@@ -18,86 +18,86 @@ |
||
18 | 18 | */ |
19 | 19 | class ExpandPropertyReport implements XmlDeserializable { |
20 | 20 | |
21 | - /** |
|
22 | - * An array with requested properties. |
|
23 | - * |
|
24 | - * The requested properties will be used as keys in this array. The value |
|
25 | - * is normally null. |
|
26 | - * |
|
27 | - * If the value is an array though, it means the property must be expanded. |
|
28 | - * Within the array, the sub-properties, which themselves may be null or |
|
29 | - * arrays. |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - public $properties; |
|
34 | - |
|
35 | - /** |
|
36 | - * The deserialize method is called during xml parsing. |
|
37 | - * |
|
38 | - * This method is called statictly, this is because in theory this method |
|
39 | - * may be used as a type of constructor, or factory method. |
|
40 | - * |
|
41 | - * Often you want to return an instance of the current class, but you are |
|
42 | - * free to return other data as well. |
|
43 | - * |
|
44 | - * You are responsible for advancing the reader to the next element. Not |
|
45 | - * doing anything will result in a never-ending loop. |
|
46 | - * |
|
47 | - * If you just want to skip parsing for this element altogether, you can |
|
48 | - * just call $reader->next(); |
|
49 | - * |
|
50 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
51 | - * the next element. |
|
52 | - * |
|
53 | - * @param Reader $reader |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - static function xmlDeserialize(Reader $reader) { |
|
57 | - |
|
58 | - $elems = $reader->parseInnerTree(); |
|
59 | - |
|
60 | - $obj = new self(); |
|
61 | - $obj->properties = self::traverse($elems); |
|
62 | - |
|
63 | - return $obj; |
|
64 | - |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * This method is used by deserializeXml, to recursively parse the |
|
69 | - * {DAV:}property elements. |
|
70 | - * |
|
71 | - * @param array $elems |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - private static function traverse($elems) { |
|
75 | - |
|
76 | - $result = []; |
|
77 | - |
|
78 | - foreach ($elems as $elem) { |
|
79 | - |
|
80 | - if ($elem['name'] !== '{DAV:}property') { |
|
81 | - continue; |
|
82 | - } |
|
83 | - |
|
84 | - $namespace = isset($elem['attributes']['namespace']) ? |
|
85 | - $elem['attributes']['namespace'] : |
|
86 | - 'DAV:'; |
|
87 | - |
|
88 | - $propName = '{' . $namespace . '}' . $elem['attributes']['name']; |
|
89 | - |
|
90 | - $value = null; |
|
91 | - if (is_array($elem['value'])) { |
|
92 | - $value = self::traverse($elem['value']); |
|
93 | - } |
|
94 | - |
|
95 | - $result[$propName] = $value; |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - return $result; |
|
100 | - |
|
101 | - } |
|
21 | + /** |
|
22 | + * An array with requested properties. |
|
23 | + * |
|
24 | + * The requested properties will be used as keys in this array. The value |
|
25 | + * is normally null. |
|
26 | + * |
|
27 | + * If the value is an array though, it means the property must be expanded. |
|
28 | + * Within the array, the sub-properties, which themselves may be null or |
|
29 | + * arrays. |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + public $properties; |
|
34 | + |
|
35 | + /** |
|
36 | + * The deserialize method is called during xml parsing. |
|
37 | + * |
|
38 | + * This method is called statictly, this is because in theory this method |
|
39 | + * may be used as a type of constructor, or factory method. |
|
40 | + * |
|
41 | + * Often you want to return an instance of the current class, but you are |
|
42 | + * free to return other data as well. |
|
43 | + * |
|
44 | + * You are responsible for advancing the reader to the next element. Not |
|
45 | + * doing anything will result in a never-ending loop. |
|
46 | + * |
|
47 | + * If you just want to skip parsing for this element altogether, you can |
|
48 | + * just call $reader->next(); |
|
49 | + * |
|
50 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
51 | + * the next element. |
|
52 | + * |
|
53 | + * @param Reader $reader |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + static function xmlDeserialize(Reader $reader) { |
|
57 | + |
|
58 | + $elems = $reader->parseInnerTree(); |
|
59 | + |
|
60 | + $obj = new self(); |
|
61 | + $obj->properties = self::traverse($elems); |
|
62 | + |
|
63 | + return $obj; |
|
64 | + |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * This method is used by deserializeXml, to recursively parse the |
|
69 | + * {DAV:}property elements. |
|
70 | + * |
|
71 | + * @param array $elems |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + private static function traverse($elems) { |
|
75 | + |
|
76 | + $result = []; |
|
77 | + |
|
78 | + foreach ($elems as $elem) { |
|
79 | + |
|
80 | + if ($elem['name'] !== '{DAV:}property') { |
|
81 | + continue; |
|
82 | + } |
|
83 | + |
|
84 | + $namespace = isset($elem['attributes']['namespace']) ? |
|
85 | + $elem['attributes']['namespace'] : |
|
86 | + 'DAV:'; |
|
87 | + |
|
88 | + $propName = '{' . $namespace . '}' . $elem['attributes']['name']; |
|
89 | + |
|
90 | + $value = null; |
|
91 | + if (is_array($elem['value'])) { |
|
92 | + $value = self::traverse($elem['value']); |
|
93 | + } |
|
94 | + |
|
95 | + $result[$propName] = $value; |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + return $result; |
|
100 | + |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
@@ -20,108 +20,108 @@ |
||
20 | 20 | */ |
21 | 21 | class PrincipalPropertySearchReport implements XmlDeserializable { |
22 | 22 | |
23 | - /** |
|
24 | - * The requested properties. |
|
25 | - * |
|
26 | - * @var array|null |
|
27 | - */ |
|
28 | - public $properties; |
|
29 | - |
|
30 | - /** |
|
31 | - * searchProperties |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - public $searchProperties = []; |
|
36 | - |
|
37 | - /** |
|
38 | - * By default the property search will be conducted on the url of the http |
|
39 | - * request. If this is set to true, it will be applied to the principal |
|
40 | - * collection set instead. |
|
41 | - * |
|
42 | - * @var bool |
|
43 | - */ |
|
44 | - public $applyToPrincipalCollectionSet = false; |
|
45 | - |
|
46 | - /** |
|
47 | - * Search for principals matching ANY of the properties (OR) or a ALL of |
|
48 | - * the properties (AND). |
|
49 | - * |
|
50 | - * This property is either "anyof" or "allof". |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - public $test; |
|
55 | - |
|
56 | - /** |
|
57 | - * The deserialize method is called during xml parsing. |
|
58 | - * |
|
59 | - * This method is called statictly, this is because in theory this method |
|
60 | - * may be used as a type of constructor, or factory method. |
|
61 | - * |
|
62 | - * Often you want to return an instance of the current class, but you are |
|
63 | - * free to return other data as well. |
|
64 | - * |
|
65 | - * You are responsible for advancing the reader to the next element. Not |
|
66 | - * doing anything will result in a never-ending loop. |
|
67 | - * |
|
68 | - * If you just want to skip parsing for this element altogether, you can |
|
69 | - * just call $reader->next(); |
|
70 | - * |
|
71 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
72 | - * the next element. |
|
73 | - * |
|
74 | - * @param Reader $reader |
|
75 | - * @return mixed |
|
76 | - */ |
|
77 | - static function xmlDeserialize(Reader $reader) { |
|
78 | - |
|
79 | - $self = new self(); |
|
80 | - |
|
81 | - $foundSearchProp = false; |
|
82 | - $self->test = 'allof'; |
|
83 | - if ($reader->getAttribute('test') === 'anyof') { |
|
84 | - $self->test = 'anyof'; |
|
85 | - } |
|
86 | - |
|
87 | - $elemMap = [ |
|
88 | - '{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue', |
|
89 | - '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
90 | - ]; |
|
23 | + /** |
|
24 | + * The requested properties. |
|
25 | + * |
|
26 | + * @var array|null |
|
27 | + */ |
|
28 | + public $properties; |
|
29 | + |
|
30 | + /** |
|
31 | + * searchProperties |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + public $searchProperties = []; |
|
36 | + |
|
37 | + /** |
|
38 | + * By default the property search will be conducted on the url of the http |
|
39 | + * request. If this is set to true, it will be applied to the principal |
|
40 | + * collection set instead. |
|
41 | + * |
|
42 | + * @var bool |
|
43 | + */ |
|
44 | + public $applyToPrincipalCollectionSet = false; |
|
45 | + |
|
46 | + /** |
|
47 | + * Search for principals matching ANY of the properties (OR) or a ALL of |
|
48 | + * the properties (AND). |
|
49 | + * |
|
50 | + * This property is either "anyof" or "allof". |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + public $test; |
|
55 | + |
|
56 | + /** |
|
57 | + * The deserialize method is called during xml parsing. |
|
58 | + * |
|
59 | + * This method is called statictly, this is because in theory this method |
|
60 | + * may be used as a type of constructor, or factory method. |
|
61 | + * |
|
62 | + * Often you want to return an instance of the current class, but you are |
|
63 | + * free to return other data as well. |
|
64 | + * |
|
65 | + * You are responsible for advancing the reader to the next element. Not |
|
66 | + * doing anything will result in a never-ending loop. |
|
67 | + * |
|
68 | + * If you just want to skip parsing for this element altogether, you can |
|
69 | + * just call $reader->next(); |
|
70 | + * |
|
71 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
72 | + * the next element. |
|
73 | + * |
|
74 | + * @param Reader $reader |
|
75 | + * @return mixed |
|
76 | + */ |
|
77 | + static function xmlDeserialize(Reader $reader) { |
|
78 | + |
|
79 | + $self = new self(); |
|
80 | + |
|
81 | + $foundSearchProp = false; |
|
82 | + $self->test = 'allof'; |
|
83 | + if ($reader->getAttribute('test') === 'anyof') { |
|
84 | + $self->test = 'anyof'; |
|
85 | + } |
|
86 | + |
|
87 | + $elemMap = [ |
|
88 | + '{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue', |
|
89 | + '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
90 | + ]; |
|
91 | 91 | |
92 | - foreach ($reader->parseInnerTree($elemMap) as $elem) { |
|
93 | - |
|
94 | - switch ($elem['name']) { |
|
95 | - |
|
96 | - case '{DAV:}prop' : |
|
97 | - $self->properties = array_keys($elem['value']); |
|
98 | - break; |
|
99 | - case '{DAV:}property-search' : |
|
100 | - $foundSearchProp = true; |
|
101 | - // This property has two sub-elements: |
|
102 | - // {DAV:}prop - The property to be searched on. This may |
|
103 | - // also be more than one |
|
104 | - // {DAV:}match - The value to match with |
|
105 | - if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) { |
|
106 | - throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element'); |
|
107 | - } |
|
108 | - foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) { |
|
109 | - $self->searchProperties[$propName] = $elem['value']['{DAV:}match']; |
|
110 | - } |
|
111 | - break; |
|
112 | - case '{DAV:}apply-to-principal-collection-set' : |
|
113 | - $self->applyToPrincipalCollectionSet = true; |
|
114 | - break; |
|
115 | - |
|
116 | - } |
|
117 | - |
|
118 | - } |
|
119 | - if (!$foundSearchProp) { |
|
120 | - throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element'); |
|
121 | - } |
|
122 | - |
|
123 | - return $self; |
|
124 | - |
|
125 | - } |
|
92 | + foreach ($reader->parseInnerTree($elemMap) as $elem) { |
|
93 | + |
|
94 | + switch ($elem['name']) { |
|
95 | + |
|
96 | + case '{DAV:}prop' : |
|
97 | + $self->properties = array_keys($elem['value']); |
|
98 | + break; |
|
99 | + case '{DAV:}property-search' : |
|
100 | + $foundSearchProp = true; |
|
101 | + // This property has two sub-elements: |
|
102 | + // {DAV:}prop - The property to be searched on. This may |
|
103 | + // also be more than one |
|
104 | + // {DAV:}match - The value to match with |
|
105 | + if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) { |
|
106 | + throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element'); |
|
107 | + } |
|
108 | + foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) { |
|
109 | + $self->searchProperties[$propName] = $elem['value']['{DAV:}match']; |
|
110 | + } |
|
111 | + break; |
|
112 | + case '{DAV:}apply-to-principal-collection-set' : |
|
113 | + $self->applyToPrincipalCollectionSet = true; |
|
114 | + break; |
|
115 | + |
|
116 | + } |
|
117 | + |
|
118 | + } |
|
119 | + if (!$foundSearchProp) { |
|
120 | + throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element'); |
|
121 | + } |
|
122 | + |
|
123 | + return $self; |
|
124 | + |
|
125 | + } |
|
126 | 126 | |
127 | 127 | } |
@@ -20,39 +20,39 @@ |
||
20 | 20 | */ |
21 | 21 | class PrincipalSearchPropertySetReport implements XmlDeserializable { |
22 | 22 | |
23 | - /** |
|
24 | - * The deserialize method is called during xml parsing. |
|
25 | - * |
|
26 | - * This method is called statictly, this is because in theory this method |
|
27 | - * may be used as a type of constructor, or factory method. |
|
28 | - * |
|
29 | - * Often you want to return an instance of the current class, but you are |
|
30 | - * free to return other data as well. |
|
31 | - * |
|
32 | - * You are responsible for advancing the reader to the next element. Not |
|
33 | - * doing anything will result in a never-ending loop. |
|
34 | - * |
|
35 | - * If you just want to skip parsing for this element altogether, you can |
|
36 | - * just call $reader->next(); |
|
37 | - * |
|
38 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
39 | - * the next element. |
|
40 | - * |
|
41 | - * @param Reader $reader |
|
42 | - * @return mixed |
|
43 | - */ |
|
44 | - static function xmlDeserialize(Reader $reader) { |
|
45 | - |
|
46 | - if (!$reader->isEmptyElement) { |
|
47 | - throw new BadRequest('The {DAV:}principal-search-property-set element must be empty'); |
|
48 | - } |
|
49 | - |
|
50 | - // The element is actually empty, so there's not much to do. |
|
51 | - $reader->next(); |
|
52 | - |
|
53 | - $self = new self(); |
|
54 | - return $self; |
|
55 | - |
|
56 | - } |
|
23 | + /** |
|
24 | + * The deserialize method is called during xml parsing. |
|
25 | + * |
|
26 | + * This method is called statictly, this is because in theory this method |
|
27 | + * may be used as a type of constructor, or factory method. |
|
28 | + * |
|
29 | + * Often you want to return an instance of the current class, but you are |
|
30 | + * free to return other data as well. |
|
31 | + * |
|
32 | + * You are responsible for advancing the reader to the next element. Not |
|
33 | + * doing anything will result in a never-ending loop. |
|
34 | + * |
|
35 | + * If you just want to skip parsing for this element altogether, you can |
|
36 | + * just call $reader->next(); |
|
37 | + * |
|
38 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
39 | + * the next element. |
|
40 | + * |
|
41 | + * @param Reader $reader |
|
42 | + * @return mixed |
|
43 | + */ |
|
44 | + static function xmlDeserialize(Reader $reader) { |
|
45 | + |
|
46 | + if (!$reader->isEmptyElement) { |
|
47 | + throw new BadRequest('The {DAV:}principal-search-property-set element must be empty'); |
|
48 | + } |
|
49 | + |
|
50 | + // The element is actually empty, so there's not much to do. |
|
51 | + $reader->next(); |
|
52 | + |
|
53 | + $self = new self(); |
|
54 | + return $self; |
|
55 | + |
|
56 | + } |
|
57 | 57 | |
58 | 58 | } |
@@ -22,80 +22,80 @@ discard block |
||
22 | 22 | */ |
23 | 23 | function resolve($basePath, $newPath) { |
24 | 24 | |
25 | - $base = parse($basePath); |
|
26 | - $delta = parse($newPath); |
|
27 | - |
|
28 | - $pick = function($part) use ($base, $delta) { |
|
29 | - |
|
30 | - if ($delta[$part]) { |
|
31 | - return $delta[$part]; |
|
32 | - } elseif ($base[$part]) { |
|
33 | - return $base[$part]; |
|
34 | - } |
|
35 | - return null; |
|
36 | - |
|
37 | - }; |
|
38 | - |
|
39 | - // If the new path defines a scheme, it's absolute and we can just return |
|
40 | - // that. |
|
41 | - if ($delta['scheme']) { |
|
42 | - return build($delta); |
|
43 | - } |
|
44 | - |
|
45 | - $newParts = []; |
|
46 | - |
|
47 | - $newParts['scheme'] = $pick('scheme'); |
|
48 | - $newParts['host'] = $pick('host'); |
|
49 | - $newParts['port'] = $pick('port'); |
|
50 | - |
|
51 | - $path = ''; |
|
52 | - if ($delta['path']) { |
|
53 | - // If the path starts with a slash |
|
54 | - if ($delta['path'][0] === '/') { |
|
55 | - $path = $delta['path']; |
|
56 | - } else { |
|
57 | - // Removing last component from base path. |
|
58 | - $path = $base['path']; |
|
59 | - if (strpos($path, '/') !== false) { |
|
60 | - $path = substr($path, 0, strrpos($path, '/')); |
|
61 | - } |
|
62 | - $path .= '/' . $delta['path']; |
|
63 | - } |
|
64 | - } else { |
|
65 | - $path = $base['path'] ?: '/'; |
|
66 | - } |
|
67 | - // Removing .. and . |
|
68 | - $pathParts = explode('/', $path); |
|
69 | - $newPathParts = []; |
|
70 | - foreach ($pathParts as $pathPart) { |
|
71 | - |
|
72 | - switch ($pathPart) { |
|
73 | - //case '' : |
|
74 | - case '.' : |
|
75 | - break; |
|
76 | - case '..' : |
|
77 | - array_pop($newPathParts); |
|
78 | - break; |
|
79 | - default : |
|
80 | - $newPathParts[] = $pathPart; |
|
81 | - break; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - $path = implode('/', $newPathParts); |
|
86 | - |
|
87 | - // If the source url ended with a /, we want to preserve that. |
|
88 | - $newParts['path'] = $path; |
|
89 | - if ($delta['query']) { |
|
90 | - $newParts['query'] = $delta['query']; |
|
91 | - } elseif (!empty($base['query']) && empty($delta['host']) && empty($delta['path'])) { |
|
92 | - // Keep the old query if host and path didn't change |
|
93 | - $newParts['query'] = $base['query']; |
|
94 | - } |
|
95 | - if ($delta['fragment']) { |
|
96 | - $newParts['fragment'] = $delta['fragment']; |
|
97 | - } |
|
98 | - return build($newParts); |
|
25 | + $base = parse($basePath); |
|
26 | + $delta = parse($newPath); |
|
27 | + |
|
28 | + $pick = function($part) use ($base, $delta) { |
|
29 | + |
|
30 | + if ($delta[$part]) { |
|
31 | + return $delta[$part]; |
|
32 | + } elseif ($base[$part]) { |
|
33 | + return $base[$part]; |
|
34 | + } |
|
35 | + return null; |
|
36 | + |
|
37 | + }; |
|
38 | + |
|
39 | + // If the new path defines a scheme, it's absolute and we can just return |
|
40 | + // that. |
|
41 | + if ($delta['scheme']) { |
|
42 | + return build($delta); |
|
43 | + } |
|
44 | + |
|
45 | + $newParts = []; |
|
46 | + |
|
47 | + $newParts['scheme'] = $pick('scheme'); |
|
48 | + $newParts['host'] = $pick('host'); |
|
49 | + $newParts['port'] = $pick('port'); |
|
50 | + |
|
51 | + $path = ''; |
|
52 | + if ($delta['path']) { |
|
53 | + // If the path starts with a slash |
|
54 | + if ($delta['path'][0] === '/') { |
|
55 | + $path = $delta['path']; |
|
56 | + } else { |
|
57 | + // Removing last component from base path. |
|
58 | + $path = $base['path']; |
|
59 | + if (strpos($path, '/') !== false) { |
|
60 | + $path = substr($path, 0, strrpos($path, '/')); |
|
61 | + } |
|
62 | + $path .= '/' . $delta['path']; |
|
63 | + } |
|
64 | + } else { |
|
65 | + $path = $base['path'] ?: '/'; |
|
66 | + } |
|
67 | + // Removing .. and . |
|
68 | + $pathParts = explode('/', $path); |
|
69 | + $newPathParts = []; |
|
70 | + foreach ($pathParts as $pathPart) { |
|
71 | + |
|
72 | + switch ($pathPart) { |
|
73 | + //case '' : |
|
74 | + case '.' : |
|
75 | + break; |
|
76 | + case '..' : |
|
77 | + array_pop($newPathParts); |
|
78 | + break; |
|
79 | + default : |
|
80 | + $newPathParts[] = $pathPart; |
|
81 | + break; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + $path = implode('/', $newPathParts); |
|
86 | + |
|
87 | + // If the source url ended with a /, we want to preserve that. |
|
88 | + $newParts['path'] = $path; |
|
89 | + if ($delta['query']) { |
|
90 | + $newParts['query'] = $delta['query']; |
|
91 | + } elseif (!empty($base['query']) && empty($delta['host']) && empty($delta['path'])) { |
|
92 | + // Keep the old query if host and path didn't change |
|
93 | + $newParts['query'] = $base['query']; |
|
94 | + } |
|
95 | + if ($delta['fragment']) { |
|
96 | + $newParts['fragment'] = $delta['fragment']; |
|
97 | + } |
|
98 | + return build($newParts); |
|
99 | 99 | |
100 | 100 | } |
101 | 101 | |
@@ -113,55 +113,55 @@ discard block |
||
113 | 113 | */ |
114 | 114 | function normalize($uri) { |
115 | 115 | |
116 | - $parts = parse($uri); |
|
117 | - |
|
118 | - if (!empty($parts['path'])) { |
|
119 | - $pathParts = explode('/', ltrim($parts['path'], '/')); |
|
120 | - $newPathParts = []; |
|
121 | - foreach ($pathParts as $pathPart) { |
|
122 | - switch ($pathPart) { |
|
123 | - case '.': |
|
124 | - // skip |
|
125 | - break; |
|
126 | - case '..' : |
|
127 | - // One level up in the hierarchy |
|
128 | - array_pop($newPathParts); |
|
129 | - break; |
|
130 | - default : |
|
131 | - // Ensuring that everything is correctly percent-encoded. |
|
132 | - $newPathParts[] = rawurlencode(rawurldecode($pathPart)); |
|
133 | - break; |
|
134 | - } |
|
135 | - } |
|
136 | - $parts['path'] = '/' . implode('/', $newPathParts); |
|
137 | - } |
|
138 | - |
|
139 | - if ($parts['scheme']) { |
|
140 | - $parts['scheme'] = strtolower($parts['scheme']); |
|
141 | - $defaultPorts = [ |
|
142 | - 'http' => '80', |
|
143 | - 'https' => '443', |
|
144 | - ]; |
|
145 | - |
|
146 | - if (!empty($parts['port']) && isset($defaultPorts[$parts['scheme']]) && $defaultPorts[$parts['scheme']] == $parts['port']) { |
|
147 | - // Removing default ports. |
|
148 | - unset($parts['port']); |
|
149 | - } |
|
150 | - // A few HTTP specific rules. |
|
151 | - switch ($parts['scheme']) { |
|
152 | - case 'http' : |
|
153 | - case 'https' : |
|
154 | - if (empty($parts['path'])) { |
|
155 | - // An empty path is equivalent to / in http. |
|
156 | - $parts['path'] = '/'; |
|
157 | - } |
|
158 | - break; |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - if ($parts['host']) $parts['host'] = strtolower($parts['host']); |
|
163 | - |
|
164 | - return build($parts); |
|
116 | + $parts = parse($uri); |
|
117 | + |
|
118 | + if (!empty($parts['path'])) { |
|
119 | + $pathParts = explode('/', ltrim($parts['path'], '/')); |
|
120 | + $newPathParts = []; |
|
121 | + foreach ($pathParts as $pathPart) { |
|
122 | + switch ($pathPart) { |
|
123 | + case '.': |
|
124 | + // skip |
|
125 | + break; |
|
126 | + case '..' : |
|
127 | + // One level up in the hierarchy |
|
128 | + array_pop($newPathParts); |
|
129 | + break; |
|
130 | + default : |
|
131 | + // Ensuring that everything is correctly percent-encoded. |
|
132 | + $newPathParts[] = rawurlencode(rawurldecode($pathPart)); |
|
133 | + break; |
|
134 | + } |
|
135 | + } |
|
136 | + $parts['path'] = '/' . implode('/', $newPathParts); |
|
137 | + } |
|
138 | + |
|
139 | + if ($parts['scheme']) { |
|
140 | + $parts['scheme'] = strtolower($parts['scheme']); |
|
141 | + $defaultPorts = [ |
|
142 | + 'http' => '80', |
|
143 | + 'https' => '443', |
|
144 | + ]; |
|
145 | + |
|
146 | + if (!empty($parts['port']) && isset($defaultPorts[$parts['scheme']]) && $defaultPorts[$parts['scheme']] == $parts['port']) { |
|
147 | + // Removing default ports. |
|
148 | + unset($parts['port']); |
|
149 | + } |
|
150 | + // A few HTTP specific rules. |
|
151 | + switch ($parts['scheme']) { |
|
152 | + case 'http' : |
|
153 | + case 'https' : |
|
154 | + if (empty($parts['path'])) { |
|
155 | + // An empty path is equivalent to / in http. |
|
156 | + $parts['path'] = '/'; |
|
157 | + } |
|
158 | + break; |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + if ($parts['host']) $parts['host'] = strtolower($parts['host']); |
|
163 | + |
|
164 | + return build($parts); |
|
165 | 165 | |
166 | 166 | } |
167 | 167 | |
@@ -180,29 +180,29 @@ discard block |
||
180 | 180 | */ |
181 | 181 | function parse($uri) { |
182 | 182 | |
183 | - // Normally a URI must be ASCII, however. However, often it's not and |
|
184 | - // parse_url might corrupt these strings. |
|
185 | - // |
|
186 | - // For that reason we take any non-ascii characters from the uri and |
|
187 | - // uriencode them first. |
|
188 | - $uri = preg_replace_callback( |
|
189 | - '/[^[:ascii:]]/u', |
|
190 | - function($matches) { |
|
191 | - return rawurlencode($matches[0]); |
|
192 | - }, |
|
193 | - $uri |
|
194 | - ); |
|
195 | - |
|
196 | - return |
|
197 | - parse_url($uri) + [ |
|
198 | - 'scheme' => null, |
|
199 | - 'host' => null, |
|
200 | - 'path' => null, |
|
201 | - 'port' => null, |
|
202 | - 'user' => null, |
|
203 | - 'query' => null, |
|
204 | - 'fragment' => null, |
|
205 | - ]; |
|
183 | + // Normally a URI must be ASCII, however. However, often it's not and |
|
184 | + // parse_url might corrupt these strings. |
|
185 | + // |
|
186 | + // For that reason we take any non-ascii characters from the uri and |
|
187 | + // uriencode them first. |
|
188 | + $uri = preg_replace_callback( |
|
189 | + '/[^[:ascii:]]/u', |
|
190 | + function($matches) { |
|
191 | + return rawurlencode($matches[0]); |
|
192 | + }, |
|
193 | + $uri |
|
194 | + ); |
|
195 | + |
|
196 | + return |
|
197 | + parse_url($uri) + [ |
|
198 | + 'scheme' => null, |
|
199 | + 'host' => null, |
|
200 | + 'path' => null, |
|
201 | + 'port' => null, |
|
202 | + 'user' => null, |
|
203 | + 'query' => null, |
|
204 | + 'fragment' => null, |
|
205 | + ]; |
|
206 | 206 | |
207 | 207 | } |
208 | 208 | |
@@ -215,41 +215,41 @@ discard block |
||
215 | 215 | */ |
216 | 216 | function build(array $parts) { |
217 | 217 | |
218 | - $uri = ''; |
|
219 | - |
|
220 | - $authority = ''; |
|
221 | - if (!empty($parts['host'])) { |
|
222 | - $authority = $parts['host']; |
|
223 | - if (!empty($parts['user'])) { |
|
224 | - $authority = $parts['user'] . '@' . $authority; |
|
225 | - } |
|
226 | - if (!empty($parts['port'])) { |
|
227 | - $authority = $authority . ':' . $parts['port']; |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - if (!empty($parts['scheme'])) { |
|
232 | - // If there's a scheme, there's also a host. |
|
233 | - $uri = $parts['scheme'] . ':'; |
|
234 | - |
|
235 | - } |
|
236 | - if ($authority) { |
|
237 | - // No scheme, but there is a host. |
|
238 | - $uri .= '//' . $authority; |
|
239 | - |
|
240 | - } |
|
241 | - |
|
242 | - if (!empty($parts['path'])) { |
|
243 | - $uri .= $parts['path']; |
|
244 | - } |
|
245 | - if (!empty($parts['query'])) { |
|
246 | - $uri .= '?' . $parts['query']; |
|
247 | - } |
|
248 | - if (!empty($parts['fragment'])) { |
|
249 | - $uri .= '#' . $parts['fragment']; |
|
250 | - } |
|
251 | - |
|
252 | - return $uri; |
|
218 | + $uri = ''; |
|
219 | + |
|
220 | + $authority = ''; |
|
221 | + if (!empty($parts['host'])) { |
|
222 | + $authority = $parts['host']; |
|
223 | + if (!empty($parts['user'])) { |
|
224 | + $authority = $parts['user'] . '@' . $authority; |
|
225 | + } |
|
226 | + if (!empty($parts['port'])) { |
|
227 | + $authority = $authority . ':' . $parts['port']; |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + if (!empty($parts['scheme'])) { |
|
232 | + // If there's a scheme, there's also a host. |
|
233 | + $uri = $parts['scheme'] . ':'; |
|
234 | + |
|
235 | + } |
|
236 | + if ($authority) { |
|
237 | + // No scheme, but there is a host. |
|
238 | + $uri .= '//' . $authority; |
|
239 | + |
|
240 | + } |
|
241 | + |
|
242 | + if (!empty($parts['path'])) { |
|
243 | + $uri .= $parts['path']; |
|
244 | + } |
|
245 | + if (!empty($parts['query'])) { |
|
246 | + $uri .= '?' . $parts['query']; |
|
247 | + } |
|
248 | + if (!empty($parts['fragment'])) { |
|
249 | + $uri .= '#' . $parts['fragment']; |
|
250 | + } |
|
251 | + |
|
252 | + return $uri; |
|
253 | 253 | |
254 | 254 | } |
255 | 255 | |
@@ -273,10 +273,10 @@ discard block |
||
273 | 273 | */ |
274 | 274 | function split($path) { |
275 | 275 | |
276 | - $matches = []; |
|
277 | - if (preg_match('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u', $path, $matches)) { |
|
278 | - return [$matches[1], $matches[2]]; |
|
279 | - } |
|
280 | - return [null,null]; |
|
276 | + $matches = []; |
|
277 | + if (preg_match('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u', $path, $matches)) { |
|
278 | + return [$matches[1], $matches[2]]; |
|
279 | + } |
|
280 | + return [null,null]; |
|
281 | 281 | |
282 | 282 | } |
@@ -11,9 +11,9 @@ |
||
11 | 11 | */ |
12 | 12 | class Version { |
13 | 13 | |
14 | - /** |
|
15 | - * Full version number |
|
16 | - */ |
|
17 | - const VERSION = '1.1.0'; |
|
14 | + /** |
|
15 | + * Full version number |
|
16 | + */ |
|
17 | + const VERSION = '1.1.0'; |
|
18 | 18 | |
19 | 19 | } |
@@ -42,10 +42,10 @@ |
||
42 | 42 | protected $eot; |
43 | 43 | protected $eof; |
44 | 44 | protected $min; |
45 | - protected $max; |
|
46 | - protected $accept; |
|
47 | - protected $special; |
|
48 | - protected $transition; |
|
45 | + protected $max; |
|
46 | + protected $accept; |
|
47 | + protected $special; |
|
48 | + protected $transition; |
|
49 | 49 | |
50 | 50 | protected $decisionNumber; |
51 | 51 |
@@ -88,9 +88,9 @@ |
||
88 | 88 | if ( $follow->member(TokenConst::$EOR_TOKEN_TYPE) ) { |
89 | 89 | $viableTokensFollowingThisRule = $this->computeContextSensitiveRuleFOLLOW(); |
90 | 90 | $follow = $follow->union($viableTokensFollowingThisRule); |
91 | - if ( $this->state->_fsp>=0 ) { // remove EOR if we're not the start symbol |
|
92 | - $follow->remove(TokenConst::$EOR_TOKEN_TYPE); |
|
93 | - } |
|
91 | + if ( $this->state->_fsp>=0 ) { // remove EOR if we're not the start symbol |
|
92 | + $follow->remove(TokenConst::$EOR_TOKEN_TYPE); |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | // if current token is consistent with what could come after set |
96 | 96 | // then we know we're missing a token; error recovery is free to |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function __construct($input, $state = null) { |
38 | 38 | parent::__construct($state); // share the state object with another parser |
39 | 39 | $this->setTokenStream($input); |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | public function reset() { |
43 | 43 | parent::reset(); // reset all recognizer state variables |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $this->input = $input; |
78 | 78 | } |
79 | 79 | |
80 | - public function getTokenStream() { |
|
80 | + public function getTokenStream() { |
|
81 | 81 | return $this->input; |
82 | 82 | } |
83 | 83 |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | public static $MIN_TOKEN_TYPE;// = UP+1; |
12 | 12 | |
13 | - public static $EOF;// = CharStream.EOF; |
|
13 | + public static $EOF;// = CharStream.EOF; |
|
14 | 14 | public static $EOF_TOKEN;// = new CommonToken(EOF); |
15 | 15 | |
16 | 16 | public static $INVALID_TOKEN_TYPE = 0; |