Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 59... Línea 59...
59
     *
59
     *
60
     * @return mixed
60
     * @return mixed
61
     */
61
     */
62
    public function getAttr($from, $path)
62
    public function getAttr($from, $path)
63
    {
63
    {
-
 
64
        // Handles the case where "[<int|string]" is provided as the top-level path
-
 
65
        if (preg_match('/^\[(\w+)\]$/', $path, $matches)) {
-
 
66
            $index = is_numeric($matches[1]) ? (int) $matches[1] : $matches[1];
-
 
67
 
-
 
68
            return $from[$index] ?? null;
-
 
69
        }
-
 
70
 
64
        $parts = explode('.', $path);
71
        $parts = explode('.', $path);
65
        foreach ($parts as $part) {
72
        foreach ($parts as $part) {
66
            $sliceIdx = strpos($part, '[');
73
            $sliceIdx = strpos($part, '[');
67
            if ($sliceIdx !== false) {
74
            if ($sliceIdx !== false) {
68
                if (substr($part, -1) !== ']') {
75
                if (substr($part, -1) !== ']') {
69
                    return null;
76
                    return null;
70
                }
77
                }
71
                $slice = intval(substr($part, $sliceIdx + 1, strlen($part) - 1));
78
                $slice = (int) substr($part, $sliceIdx + 1, strlen($part) - 1);
72
                $from = isset($from[substr($part,0, $sliceIdx)][$slice])
79
                $fromIndex = substr($part, 0, $sliceIdx);
73
                    ? $from[substr($part,0, $sliceIdx)][$slice]
80
                $from = $from[$fromIndex][$slice] ?? null;
74
                    : null;
-
 
75
            } else {
81
            } else {
76
                $from = $from[$part];
82
                $from = $from[$part];
77
            }
83
            }
78
        }
84
        }
79
        return $from;
85
        return $from;
Línea 153... Línea 159...
153
     *
159
     *
154
     * @return mixed
160
     * @return mixed
155
     */
161
     */
156
    public function parseUrl($url)
162
    public function parseUrl($url)
157
    {
163
    {
-
 
164
        if (is_null($url)) {
-
 
165
            return null;
-
 
166
        }
-
 
167
 
158
        $parsed = parse_url($url);
168
        $parsed = parse_url($url);
Línea 159... Línea 169...
159
 
169
 
160
        if ($parsed === false || !empty($parsed['query'])) {
170
        if ($parsed === false || !empty($parsed['query'])) {
161
            return null;
171
            return null;