Skip to content

Commit

Permalink
MultiRouter is not Nette\Collections\ArrayList descendant yet
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 27, 2010
1 parent 677a11f commit 5b86f26
Showing 1 changed file with 84 additions and 4 deletions.
88 changes: 84 additions & 4 deletions Nette/Application/Routers/MultiRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
* @copyright Copyright (c) 2004, 2010 David Grudl
* @package Nette\Application
*/
class MultiRouter extends /*Nette\Collections\*/ArrayList implements IRouter
class MultiRouter extends /*Nette\*/Object implements IRouter, /*\*/ArrayAccess, /*\*/Countable, /*\*/IteratorAggregate
{
/** @var SplQueue */
private $routes;

/** @var array */
private $cachedRoutes;



public function __construct()
{
parent::__construct(NULL, /*Nette\Application\*/'IRouter');
$this->routes = new /*SplQueue*//**/ArrayList/**/;
}


Expand All @@ -41,7 +44,7 @@ public function __construct()
*/
public function match(/*Nette\Web\*/IHttpRequest $httpRequest)
{
foreach ($this as $route) {
foreach ($this->routes as $route) {
$appRequest = $route->match($httpRequest);
if ($appRequest !== NULL) {
return $appRequest;
Expand All @@ -64,7 +67,7 @@ public function constructUrl(PresenterRequest $appRequest, /*Nette\Web\*/IHttpRe
$routes = array();
$routes['*'] = array();

foreach ($this as $route) {
foreach ($this->routes as $route) {
$presenter = $route instanceof Route ? $route->getTargetPresenter() : NULL;

if ($presenter === FALSE) continue;
Expand Down Expand Up @@ -99,4 +102,81 @@ public function constructUrl(PresenterRequest $appRequest, /*Nette\Web\*/IHttpRe
return NULL;
}



/********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/



/**
* Adds the router.
* @param mixed
* @param IRouter
* @return void
*/
public function offsetSet($index, $route)
{
if (!($routes instanceof IRouter)) {
throw new /*\*/InvalidArgumentException("Argument must be IRouter descendant.");
}
$this->routes[$index] = $route;
}



/**
* Returns router specified by index. Throws exception if router doesn't exist.
* @param mixed
* @return IRouter
*/
public function offsetGet($index)
{
return $this->routes[$index];
}



/**
* Does router specified by index exists?
* @param mixed
* @return bool
*/
public function offsetExists($index)
{
return isset($this->routes[$index]);
}



/**
* Removes router.
* @param mixed
* @return void
*/
public function offsetUnset($index)
{
unset($this->routes[$index]);
}



/**
* Iterates over routers.
* @return \Traversable
*/
public function getIterator()
{
return $this->routes;
}



/**
* @return int
*/
public function count()
{
return count($this->routes);
}

}

0 comments on commit 5b86f26

Please sign in to comment.