Skip to content

Commit e5d9863

Browse files
committed
RouteList: array access is deprecated
1 parent 7f22eac commit e5d9863

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
@@ -96,6 +96,13 @@ public function getModule(): ?string
9696
*/
9797
public function offsetSet($index, $router): void
9898
{
99+
if ($router instanceof Route) {
100+
trigger_error('Usage `$router[] = new Route(...)` is deprecated, use `$router->addRoute(...)`.', E_USER_DEPRECATED);
101+
} else {
102+
$class = getclass($router);
103+
trigger_error("Usage `\$router[] = new $class` is deprecated, use `\$router->add(new $class)`.", E_USER_DEPRECATED);
104+
}
105+
99106
if ($index === null) {
100107
$this->add($router);
101108
} else {
@@ -110,6 +117,7 @@ public function offsetSet($index, $router): void
110117
*/
111118
public function offsetGet($index): Nette\Routing\Router
112119
{
120+
trigger_error('Usage `$route = $router[...]` is deprecated, use `$router->getRouters()`.', E_USER_DEPRECATED);
113121
if (!$this->offsetExists($index)) {
114122
throw new Nette\OutOfRangeException('Offset invalid or out of range');
115123
}
@@ -123,6 +131,7 @@ public function offsetGet($index): Nette\Routing\Router
123131
*/
124132
public function offsetExists($index): bool
125133
{
134+
trigger_error('Usage `isset($router[...])` is deprecated.', E_USER_DEPRECATED);
126135
return is_int($index) && $index >= 0 && $index < count($this->getRouters());
127136
}
128137

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

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)