/** * Register a router with the service container. * * @param Container $container */ public function register(Container $container) { $container->register(array('Darya\\Routing\\Router' => function ($container) { $config = $container->config; $routes = $config['routes'] ?: array('/:controller/:action/:params' => null, '/:controller/:params' => null, '/:action/:params' => null, '/' => null); $projectNamespace = $config['project.namespace'] ?: 'Application'; $defaultNamespace = "{$projectNamespace}\\Controllers"; $router = new Router($routes, array('namespace' => $defaultNamespace)); $router->base($config['base_url']); $router->setServiceContainer($container); $router->setEventDispatcher($container->resolve('Darya\\Events\\Dispatchable')); return $router; })); }
/** * Retrieve the URL that the route was matched by. * * Optionally accepts parameters to merge into matched parameters. * * @param array $parameters [optional] * @return string */ public function url(array $parameters = array()) { if ($this->router) { $parameters = array_merge($this->matches, $parameters); return $this->router->url($this->path, $parameters); } }
/** * Associate the error handler method with the router. * * @param Router $router */ public function boot(Router $router) { $router->setErrorHandler(array($this, 'handle')); }