Skip to content

Commit 20eda36

Browse files
committed
RouteList: array access is deprecated
1 parent dfe7775 commit 20eda36

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/Application/Routers/RouteList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public function getModule(): ?string
9494
*/
9595
public function offsetSet($index, $router): void
9696
{
97+
if ($router instanceof Route) {
98+
trigger_error('Usage `$router[] = new Route(...)` is deprecated, use `$router->addRoute(...)`.', E_USER_DEPRECATED);
99+
} else {
100+
$class = getclass($router);
101+
trigger_error("Usage `\$router[] = new $class` is deprecated, use `\$router->add(new $class)`.", E_USER_DEPRECATED);
102+
}
97103
if ($index === null) {
98104
$this->add($router);
99105
} else {
@@ -108,6 +114,7 @@ public function offsetSet($index, $router): void
108114
*/
109115
public function offsetGet($index): mixed
110116
{
117+
trigger_error('Usage `$route = $router[...]` is deprecated, use `$router->getRouters()`.', E_USER_DEPRECATED);
111118
if (!$this->offsetExists($index)) {
112119
throw new Nette\OutOfRangeException('Offset invalid or out of range');
113120
}
@@ -120,6 +127,7 @@ public function offsetGet($index): mixed
120127
*/
121128
public function offsetExists($index): bool
122129
{
130+
trigger_error('Usage `isset($router[...])` is deprecated.', E_USER_DEPRECATED);
123131
return is_int($index) && $index >= 0 && $index < count($this->getRouters());
124132
}
125133

@@ -130,6 +138,7 @@ public function offsetExists($index): bool
130138
*/
131139
public function offsetUnset($index): void
132140
{
141+
trigger_error('Usage `unset($router[$index])` is deprecated, use `$router->modify($index, null)`.', E_USER_DEPRECATED);
133142
if (!$this->offsetExists($index)) {
134143
throw new Nette\OutOfRangeException('Offset invalid or out of range');
135144
}

tests/Bridges.DI/RoutingExtension.basic.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ test('', function () {
3131
$container = new Container1;
3232
$router = $container->getService('router');
3333
Assert::type(Nette\Application\Routers\RouteList::class, $router);
34-
Assert::same('index.php', $router[0]->getMask());
35-
Assert::same('item/<id>', $router[1]->getMask());
34+
$routes = $router->getRouters();
35+
Assert::same('index.php', $routes[0]->getMask());
36+
Assert::same('item/<id>', $routes[1]->getMask());
3637

3738
Assert::type(Nette\Application\Routers\RouteList::class, $router);
38-
Assert::type(Nette\Application\Routers\Route::class, $router[0]);
39+
Assert::type(Nette\Application\Routers\Route::class, $routes[0]);
3940
});

tests/Routers/RouteList.basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require __DIR__ . '/Route.php';
1717

1818

1919
$list = new RouteList;
20-
$list[] = new Route('<presenter>/<action=default>/<id= \d{1,3}>');
20+
$list->addRoute('<presenter>/<action=default>/<id= \d{1,3}>');
2121

2222

2323
Assert::same('http://example.com/front.homepage/', testRouteOut($list, ['presenter' => 'Front:Homepage']));

tests/Routers/RouteList.modules.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ require __DIR__ . '/Route.php';
1616

1717

1818
$list = new RouteList;
19-
$list[] = new Route('auth/<presenter>[/<action>]', [
19+
$list->addRoute('auth/<presenter>[/<action>]', [
2020
'module' => 'Auth',
2121
'presenter' => 'Homepage',
2222
'action' => 'default',
2323
]);
24-
$list[] = new Route('<presenter>[/<action>]', [
24+
$list->addRoute('<presenter>[/<action>]', [
2525
'module' => 'Default',
2626
'presenter' => 'Homepage',
2727
'action' => 'default',

0 commit comments

Comments
 (0)