Skip to content

Commit e6efe99

Browse files
committed
RouteList: ArrayAccess, Countable and IteratorAggregate are deprecated
1 parent 3db816f commit e6efe99

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/Application/Routers/RouteList.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,64 +93,65 @@ public function getModule(): ?string
9393
}
9494

9595

96+
/** @deprecated */
9697
public function count(): int
9798
{
99+
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
98100
return count($this->getRouters());
99101
}
100102

101103

102-
/**
103-
* @param mixed $index
104-
* @param Nette\Routing\Router $router
105-
*/
104+
/** @deprecated */
106105
public function offsetSet($index, $router): void
107106
{
108107
if ($index === null) {
108+
/*if (get_class($router) === Route::class) {
109+
trigger_error(__METHOD__ . '() is deprecated, use addRoute(...)', E_USER_DEPRECATED);
110+
} else {
111+
trigger_error(__METHOD__ . '() is deprecated, use add(new ' . get_class($router) . '(...)).', E_USER_DEPRECATED);
112+
}*/
109113
$this->add($router);
110114
} else {
115+
trigger_error(__METHOD__ . '() is deprecated, use modify($index, $route).', E_USER_DEPRECATED);
111116
$this->modify($index, $router);
112117
}
113118
}
114119

115120

116-
/**
117-
* @param int $index
118-
* @return mixed
119-
* @throws Nette\OutOfRangeException
120-
*/
121+
/** @deprecated */
121122
public function offsetGet($index)
122123
{
124+
trigger_error(__METHOD__ . '() is deprecated, use getRouters().', E_USER_DEPRECATED);
123125
if (!$this->offsetExists($index)) {
124126
throw new Nette\OutOfRangeException('Offset invalid or out of range');
125127
}
126128
return $this->getRouters()[$index];
127129
}
128130

129131

130-
/**
131-
* @param int $index
132-
*/
132+
/** @deprecated */
133133
public function offsetExists($index): bool
134134
{
135+
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
135136
return is_int($index) && $index >= 0 && $index < $this->count();
136137
}
137138

138139

139-
/**
140-
* @param int $index
141-
* @throws Nette\OutOfRangeException
142-
*/
140+
/** @deprecated */
143141
public function offsetUnset($index): void
144142
{
143+
trigger_error(__METHOD__ . '() is deprecated, use modify($index, null).', E_USER_DEPRECATED);
145144
if (!$this->offsetExists($index)) {
146145
throw new Nette\OutOfRangeException('Offset invalid or out of range');
147146
}
148147
$this->modify($index, null);
149148
}
150149

151150

151+
/** @deprecated */
152152
public function getIterator(): \ArrayIterator
153153
{
154+
trigger_error(__METHOD__ . '() is deprecated, use getRouters().', E_USER_DEPRECATED);
154155
return new \ArrayIterator($this->getRouters());
155156
}
156157
}

src/Bridges/ApplicationTracy/RoutingPanel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function analyse(Nette\Routing\Router $router, string $module = ''): voi
100100
{
101101
if ($router instanceof Routers\RouteList) {
102102
if ($router->match($this->httpRequest)) {
103-
foreach ($router as $subRouter) {
103+
foreach ($router->getRouters() as $subRouter) {
104104
$this->analyse($subRouter, $module . $router->getModule());
105105
}
106106
}

tests/Bridges.DI/RoutingExtension.basic.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ test(function () {
3636
$container = new Container1;
3737
$router = $container->getService('router');
3838
Assert::type(Nette\Application\Routers\RouteList::class, $router);
39-
Assert::count(2, $router);
40-
Assert::same('index.php', $router[0]->getMask());
41-
Assert::same('item/<id>', $router[1]->getMask());
39+
@Assert::count(2, $router); // @ is deprecated
40+
Assert::same('index.php', @$router[0]->getMask()); // @ is deprecated
41+
Assert::same('item/<id>', @$router[1]->getMask()); // @ is deprecated
4242

4343
Assert::type(Nette\Application\Routers\RouteList::class, $router);
44-
Assert::type(Nette\Application\Routers\Route::class, $router[0]);
44+
Assert::type(Nette\Application\Routers\Route::class, @$router[0]); // @ is deprecated
4545
});
4646

4747

@@ -64,5 +64,5 @@ test(function () {
6464
$router = $container->getService('router');
6565

6666
Assert::type(Nette\Application\Routers\RouteList::class, $router);
67-
Assert::type(Route::class, $router[0]);
67+
Assert::type(Route::class, @$router[0]); // @ is deprecated
6868
});

0 commit comments

Comments
 (0)