Skip to content

Commit

Permalink
RouteList: ArrayAccess, Countable and IteratorAggregate are deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 23, 2020
1 parent 3db816f commit e6efe99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
33 changes: 17 additions & 16 deletions src/Application/Routers/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,64 +93,65 @@ public function getModule(): ?string
}


/** @deprecated */
public function count(): int
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
return count($this->getRouters());
}


/**
* @param mixed $index
* @param Nette\Routing\Router $router
*/
/** @deprecated */
public function offsetSet($index, $router): void
{
if ($index === null) {
/*if (get_class($router) === Route::class) {
trigger_error(__METHOD__ . '() is deprecated, use addRoute(...)', E_USER_DEPRECATED);
} else {
trigger_error(__METHOD__ . '() is deprecated, use add(new ' . get_class($router) . '(...)).', E_USER_DEPRECATED);
}*/
$this->add($router);
} else {
trigger_error(__METHOD__ . '() is deprecated, use modify($index, $route).', E_USER_DEPRECATED);
$this->modify($index, $router);
}
}


/**
* @param int $index
* @return mixed
* @throws Nette\OutOfRangeException
*/
/** @deprecated */
public function offsetGet($index)
{
trigger_error(__METHOD__ . '() is deprecated, use getRouters().', E_USER_DEPRECATED);
if (!$this->offsetExists($index)) {
throw new Nette\OutOfRangeException('Offset invalid or out of range');
}
return $this->getRouters()[$index];
}


/**
* @param int $index
*/
/** @deprecated */
public function offsetExists($index): bool
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
return is_int($index) && $index >= 0 && $index < $this->count();
}


/**
* @param int $index
* @throws Nette\OutOfRangeException
*/
/** @deprecated */
public function offsetUnset($index): void
{
trigger_error(__METHOD__ . '() is deprecated, use modify($index, null).', E_USER_DEPRECATED);
if (!$this->offsetExists($index)) {
throw new Nette\OutOfRangeException('Offset invalid or out of range');
}
$this->modify($index, null);
}


/** @deprecated */
public function getIterator(): \ArrayIterator
{
trigger_error(__METHOD__ . '() is deprecated, use getRouters().', E_USER_DEPRECATED);
return new \ArrayIterator($this->getRouters());
}
}
2 changes: 1 addition & 1 deletion src/Bridges/ApplicationTracy/RoutingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private function analyse(Nette\Routing\Router $router, string $module = ''): voi
{
if ($router instanceof Routers\RouteList) {
if ($router->match($this->httpRequest)) {
foreach ($router as $subRouter) {
foreach ($router->getRouters() as $subRouter) {
$this->analyse($subRouter, $module . $router->getModule());
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Bridges.DI/RoutingExtension.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ test(function () {
$container = new Container1;
$router = $container->getService('router');
Assert::type(Nette\Application\Routers\RouteList::class, $router);
Assert::count(2, $router);
Assert::same('index.php', $router[0]->getMask());
Assert::same('item/<id>', $router[1]->getMask());
@Assert::count(2, $router); // @ is deprecated
Assert::same('index.php', @$router[0]->getMask()); // @ is deprecated
Assert::same('item/<id>', @$router[1]->getMask()); // @ is deprecated

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


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

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

0 comments on commit e6efe99

Please sign in to comment.