Skip to content

Commit 5220836

Browse files
committed
RouteList: array access is deprecated
1 parent ac00766 commit 5220836

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/Application/Routers/RouteList.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public function getModule(): ?string
9595
*/
9696
public function offsetSet($index, $router): void
9797
{
98+
if ($router instanceof Route) {
99+
trigger_error('Usage `$router[] = new Route(...)` is deprecated, use `$router->addRoute(...)`.', E_USER_DEPRECATED);
100+
} else {
101+
$class = getclass($router);
102+
trigger_error("Usage `\$router[] = new $class` is deprecated, use `\$router->add(new $class)`.", E_USER_DEPRECATED);
103+
}
104+
98105
if ($index === null) {
99106
$this->add($router);
100107
} else {
@@ -109,6 +116,7 @@ public function offsetSet($index, $router): void
109116
*/
110117
public function offsetGet($index): Nette\Routing\Router
111118
{
119+
trigger_error('Usage `$route = $router[...]` is deprecated, use `$router->getRouters()`.', E_USER_DEPRECATED);
112120
if (!$this->offsetExists($index)) {
113121
throw new Nette\OutOfRangeException('Offset invalid or out of range');
114122
}
@@ -122,6 +130,7 @@ public function offsetGet($index): Nette\Routing\Router
122130
*/
123131
public function offsetExists($index): bool
124132
{
133+
trigger_error('Usage `isset($router[...])` is deprecated.', E_USER_DEPRECATED);
125134
return is_int($index) && $index >= 0 && $index < count($this->getRouters());
126135
}
127136

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

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
declare(strict_types=1);
88

9-
use Nette\Application\Routers\Route;
109
use Nette\Application\Routers\RouteList;
1110
use Tester\Assert;
1211

@@ -17,7 +16,7 @@ require __DIR__ . '/Route.php';
1716

1817

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

2221

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

tests/Routers/RouteList.modules.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
declare(strict_types=1);
88

9-
use Nette\Application\Routers\Route;
109
use Nette\Application\Routers\RouteList;
1110

1211

@@ -16,12 +15,12 @@ require __DIR__ . '/Route.php';
1615

1716

1817
$list = new RouteList;
19-
$list[] = new Route('auth/<presenter>[/<action>]', [
18+
$list->addRoute('auth/<presenter>[/<action>]', [
2019
'module' => 'Auth',
2120
'presenter' => 'Homepage',
2221
'action' => 'default',
2322
]);
24-
$list[] = new Route('<presenter>[/<action>]', [
23+
$list->addRoute('<presenter>[/<action>]', [
2524
'module' => 'Default',
2625
'presenter' => 'Homepage',
2726
'action' => 'default',

0 commit comments

Comments
 (0)