Example #1
0
 /**
  * Load the configuration to a router
  * @param  Packfire\Router\RouterInterface $router (optional) Provide a specific router to load the configuration into
  * @return Packfire\Router\RouterInterface Returns a router loaded with the configuration
  */
 public function load(RouterInterface $router = null)
 {
     if (!$router) {
         if (isset($this->container['Packfire\\Router\\RouterInterface'])) {
             $router = $this->container['Packfire\\Router\\RouterInterface'];
         } else {
             $router = $this->container->instantiate('Packfire\\Router\\Router');
         }
     }
     $factory = new ConfigFactory();
     $config = $factory->load($this->file);
     $routes = $config->get('routes');
     if ($routes) {
         foreach ($routes as $name => $route) {
             $router->add($name, $route);
         }
     }
     return $router;
 }
Example #2
0
 /**
  * Create a new Router object
  * @return void
  */
 public function __construct()
 {
     $this->container = new Container();
     $this->factory = $this->container->instantiate('Packfire\\Router\\RouteFactory');
 }