|
|
@@ -743,32 +743,24 @@ class RouteBuilder
|
|
|
return $defaults;
|
|
|
}
|
|
|
|
|
|
- $regex = '/(?:([a-zA-Z0-9\/]*)\.)?([a-zA-Z0-9\/]*?)(?:\/)?([a-zA-Z0-9]*):{2}([a-zA-Z0-9_]*)/i';
|
|
|
+ $regex = '/(?:(?<plugin>[a-zA-Z0-9\/]*)\.)?(?<prefix>[a-zA-Z0-9\/]*?)' .
|
|
|
+ '(?:\/)?(?<controller>[a-zA-Z0-9]*):{2}(?<action>[a-zA-Z0-9_]*)/i';
|
|
|
+
|
|
|
if (preg_match($regex, $defaults, $matches)) {
|
|
|
- unset($matches[0]);
|
|
|
- $matches = array_filter($matches, function ($value) {
|
|
|
- return $value !== '::';
|
|
|
- });
|
|
|
- // Intentionally incomplete switch
|
|
|
- switch (count($matches)) {
|
|
|
- case 2:
|
|
|
- return [
|
|
|
- 'controller' => (isset($matches[3]) ? $matches[3] : null),
|
|
|
- 'action' => (isset($matches[4]) ? $matches[4] : null)
|
|
|
- ];
|
|
|
- case 3:
|
|
|
- return [
|
|
|
- 'prefix' => (isset($matches[2]) ? strtolower($matches[2]) : null),
|
|
|
- 'controller' => (isset($matches[3]) ? $matches[3] : null),
|
|
|
- 'action' => (isset($matches[4]) ? $matches[4] : null)
|
|
|
- ];
|
|
|
- case 4:
|
|
|
- return [
|
|
|
- 'plugin' => (isset($matches[1]) ? $matches[1] : null),
|
|
|
- 'prefix' => (isset($matches[2]) ? strtolower($matches[2]) : null),
|
|
|
- 'controller' => (isset($matches[3]) ? $matches[3] : null),
|
|
|
- 'action' => (isset($matches[4]) ? $matches[4] : null)
|
|
|
- ];
|
|
|
+ foreach ($matches as $key => $value) {
|
|
|
+ // Remove numeric keys and empty values.
|
|
|
+ if (is_int($key) || $value === '' || $value === '::') {
|
|
|
+ unset($matches[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $length = count($matches);
|
|
|
+
|
|
|
+ if (isset($matches['prefix'])) {
|
|
|
+ $matches['prefix'] = strtolower($matches['prefix']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($length >= 2 || $length <= 4) {
|
|
|
+ return $matches;
|
|
|
}
|
|
|
}
|
|
|
throw new RuntimeException("Could not parse `{$defaults}` route destination string.");
|