Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
RouterFactory refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Jul 20, 2017
1 parent d27da46 commit 89af557
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/factories/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,43 @@

class RouterFactory implements FactoryInterface
{
/**
* @var array
*/
private $routes;
/**
* @var Router
*/
private $router;

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/**
* @var array $config
*/
$config = $container->get('config');
/**
* @var array $routes
*/
$routes = $container->get('routes');
/**
* @var ServerRequestInterface $request
*/
$this->routes = $container->get('routes');
$request = $container->get(ServerRequestInterface::class);
$router = new Router(
$this->router = new Router(
$config['app']['default_return_type'] ?? Router::HTML,
$request->getMethod(),
$request->getUri()->getPath(),
'',
$config['app']['cache_file']
);
foreach ($routes as $route) {
$router->add($route[0], $route[1], $route[2], $route[3], $route[4] ?? '');
return $this->getRouter();
}

private function getRouter()
{
$this->addRoutes();
return $this->router;
}

private function addRoutes()
{
foreach ($this->routes as $route) {
$this->router->add($route[0], $route[1], $route[2], $route[3], $route[4] ?? '');
}
return $router;
}
}

0 comments on commit 89af557

Please sign in to comment.