Skip to content

Commit 0d611f1

Browse files
committed
Route::$styles is deprecated (BC break)
1 parent 98dff12 commit 0d611f1

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/Application/Routers/Route.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Route implements Application\IRouter
2222
{
2323
use Nette\SmartObject;
2424

25-
/** key used in {@link Route::$styles} or metadata {@link Route::__construct} */
25+
/** key used in metadata {@link Route::__construct} */
2626
public const
2727
VALUE = 'value',
2828
PATTERN = 'pattern',
@@ -53,14 +53,15 @@ class Route implements Application\IRouter
5353
PRESENTER_KEY = 'presenter',
5454
MODULE_KEY = 'module';
5555

56+
/** @deprecated */
57+
public static $styles = [];
58+
5659
/** @var array */
57-
public static $styles = [
60+
protected $defaultMeta = [
5861
'#' => [ // default style for path parameters
5962
self::PATTERN => '[^/]+',
6063
self::FILTER_OUT => [__CLASS__, 'param2path'],
6164
],
62-
'?#' => [// default style for query parameters
63-
],
6465
'module' => [
6566
self::PATTERN => '[a-z][a-z0-9.-]*',
6667
self::FILTER_IN => [__CLASS__, 'path2presenter'],
@@ -76,12 +77,6 @@ class Route implements Application\IRouter
7677
self::FILTER_IN => [__CLASS__, 'path2action'],
7778
self::FILTER_OUT => [__CLASS__, 'action2path'],
7879
],
79-
'?module' => [
80-
],
81-
'?presenter' => [
82-
],
83-
'?action' => [
84-
],
8580
];
8681

8782
/** @var string */
@@ -140,6 +135,11 @@ public function __construct(string $mask, $metadata = [], int $flags = 0)
140135
];
141136
}
142137

138+
if (self::$styles) {
139+
trigger_error('Route::$styles is deprecated.', E_USER_DEPRECATED);
140+
array_replace_recursive($this->defaultMeta, self::$styles);
141+
}
142+
143143
$this->flags = $flags;
144144
$this->setMask($mask, $metadata);
145145
}
@@ -480,7 +480,7 @@ private function setMask(string $mask, array $metadata): void
480480
$matches = Strings::matchAll($parts[$i - 1], '/(?:([a-zA-Z0-9_.-]+)=)?<([^> ]+) *([^>]*)>/');
481481

482482
foreach ($matches as [, $param, $name, $pattern]) { // $pattern is not used
483-
$meta = ($metadata[$name] ?? []) + (static::$styles['?' . $name] ?? static::$styles['?#']);
483+
$meta = ($metadata[$name] ?? []) + ($this->defaultMeta['?' . $name] ?? []);
484484

485485
if (array_key_exists(self::VALUE, $meta)) {
486486
$meta[self::FIXITY] = self::OPTIONAL;
@@ -540,7 +540,7 @@ private function setMask(string $mask, array $metadata): void
540540
}
541541

542542
// pattern, condition & metadata
543-
$meta = ($metadata[$name] ?? []) + (static::$styles[$name] ?? static::$styles['#']);
543+
$meta = ($metadata[$name] ?? []) + ($this->defaultMeta[$name] ?? $this->defaultMeta['#']);
544544

545545
if ($pattern == '' && isset($meta[self::PATTERN])) {
546546
$pattern = $meta[self::PATTERN];

0 commit comments

Comments
 (0)