comparison vendor/symfony/routing/Matcher/Dumper/StaticPrefixCollection.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
26 private $prefix; 26 private $prefix;
27 27
28 /** 28 /**
29 * @var array[]|StaticPrefixCollection[] 29 * @var array[]|StaticPrefixCollection[]
30 */ 30 */
31 private $items = array(); 31 private $items = [];
32 32
33 /** 33 /**
34 * @var int 34 * @var int
35 */ 35 */
36 private $matchStart = 0; 36 private $matchStart = 0;
66 66
67 if ($this->prefix === $prefix) { 67 if ($this->prefix === $prefix) {
68 // When a prefix is exactly the same as the base we move up the match start position. 68 // When a prefix is exactly the same as the base we move up the match start position.
69 // This is needed because otherwise routes that come afterwards have higher precedence 69 // This is needed because otherwise routes that come afterwards have higher precedence
70 // than a possible regular expression, which goes against the input order sorting. 70 // than a possible regular expression, which goes against the input order sorting.
71 $this->items[] = array($prefix, $route); 71 $this->items[] = [$prefix, $route];
72 $this->matchStart = count($this->items); 72 $this->matchStart = \count($this->items);
73 73
74 return; 74 return;
75 } 75 }
76 76
77 foreach ($this->items as $i => $item) { 77 foreach ($this->items as $i => $item) {
94 } 94 }
95 } 95 }
96 96
97 // No optimised case was found, in this case we simple add the route for possible 97 // No optimised case was found, in this case we simple add the route for possible
98 // grouping when new routes are added. 98 // grouping when new routes are added.
99 $this->items[] = array($prefix, $route); 99 $this->items[] = [$prefix, $route];
100 } 100 }
101 101
102 /** 102 /**
103 * Tries to combine a route with another route or group. 103 * Tries to combine a route with another route or group.
104 * 104 *
105 * @param StaticPrefixCollection|array $item 105 * @param StaticPrefixCollection|array $item
106 * @param string $prefix 106 * @param string $prefix
107 * @param mixed $route 107 * @param mixed $route
108 * 108 *
109 * @return null|StaticPrefixCollection 109 * @return StaticPrefixCollection|null
110 */ 110 */
111 private function groupWithItem($item, $prefix, $route) 111 private function groupWithItem($item, $prefix, $route)
112 { 112 {
113 $itemPrefix = $item instanceof self ? $item->prefix : $item[0]; 113 $itemPrefix = $item instanceof self ? $item->prefix : $item[0];
114 $commonPrefix = $this->detectCommonPrefix($prefix, $itemPrefix); 114 $commonPrefix = $this->detectCommonPrefix($prefix, $itemPrefix);
118 } 118 }
119 119
120 $child = new self($commonPrefix); 120 $child = new self($commonPrefix);
121 121
122 if ($item instanceof self) { 122 if ($item instanceof self) {
123 $child->items = array($item); 123 $child->items = [$item];
124 } else { 124 } else {
125 $child->addRoute($item[0], $item[1]); 125 $child->addRoute($item[0], $item[1]);
126 } 126 }
127 127
128 $child->addRoute($prefix, $route); 128 $child->addRoute($prefix, $route);
150 * 150 *
151 * @return false|string A common prefix, longer than the base/group prefix, or false when none available 151 * @return false|string A common prefix, longer than the base/group prefix, or false when none available
152 */ 152 */
153 private function detectCommonPrefix($prefix, $anotherPrefix) 153 private function detectCommonPrefix($prefix, $anotherPrefix)
154 { 154 {
155 $baseLength = strlen($this->prefix); 155 $baseLength = \strlen($this->prefix);
156 $commonLength = $baseLength; 156 $commonLength = $baseLength;
157 $end = min(strlen($prefix), strlen($anotherPrefix)); 157 $end = min(\strlen($prefix), \strlen($anotherPrefix));
158 158
159 for ($i = $baseLength; $i <= $end; ++$i) { 159 for ($i = $baseLength; $i <= $end; ++$i) {
160 if (substr($prefix, 0, $i) !== substr($anotherPrefix, 0, $i)) { 160 if (substr($prefix, 0, $i) !== substr($anotherPrefix, 0, $i)) {
161 break; 161 break;
162 } 162 }
164 $commonLength = $i; 164 $commonLength = $i;
165 } 165 }
166 166
167 $commonPrefix = rtrim(substr($prefix, 0, $commonLength), '/'); 167 $commonPrefix = rtrim(substr($prefix, 0, $commonLength), '/');
168 168
169 if (strlen($commonPrefix) > $baseLength) { 169 if (\strlen($commonPrefix) > $baseLength) {
170 return $commonPrefix; 170 return $commonPrefix;
171 } 171 }
172 172
173 return false; 173 return false;
174 } 174 }
199 } 199 }
200 } 200 }
201 201
202 private function shouldBeInlined() 202 private function shouldBeInlined()
203 { 203 {
204 if (count($this->items) >= 3) { 204 if (\count($this->items) >= 3) {
205 return false; 205 return false;
206 } 206 }
207 207
208 foreach ($this->items as $item) { 208 foreach ($this->items as $item) {
209 if ($item instanceof self) { 209 if ($item instanceof self) {
210 return true; 210 return true;
211 } 211 }
212 } 212 }
213 213
214 foreach ($this->items as $item) { 214 foreach ($this->items as $item) {
215 if (is_array($item) && $item[0] === $this->prefix) { 215 if (\is_array($item) && $item[0] === $this->prefix) {
216 return false; 216 return false;
217 } 217 }
218 } 218 }
219 219
220 return true; 220 return true;