public function load($directory)
 {
     /* @var $dir \SplFileInfo[] */
     $dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
     foreach ($dir as $file) {
         if (!$file->isFile()) {
             continue;
         }
         $fileName = $file->getPathname();
         if (pathinfo($fileName, PATHINFO_EXTENSION) !== 'php') {
             continue;
         }
         $className = $this->getClassnameWithNamespace($fileName);
         if (!$className) {
             continue;
         }
         $className = substr($className, 0, 0 - strlen($this->suffixName));
         $this->router->addResource($className);
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function add(RouterInterface $router, Route $route)
 {
     //resolves actions with http methods
     $actions = $route->getParam('actions');
     if (empty($actions)) {
         $actions = array('/' => array('index' => Method::GET));
     }
     //add routes with http method
     //for each action new route is adding with specified HTTP Method.
     foreach ($actions as $actionRoute => $actionMethods) {
         if ($actionRoute == '/') {
             $actionRoute = '';
         }
         foreach ($actionMethods as $action => $method) {
             $paths = $route->getPaths();
             $paths['action'] = $action;
             $newRoute = $router->add($route->getRoute() . $actionRoute, $paths)->via($method);
             $newRoute->setName($route->getName() . $actionRoute . '/' . $action);
             $newRoute->setHostName($route->getParam('hostname'));
         }
     }
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function add(RouterInterface $router, Route $route)
 {
     $router->notFound($route->getPaths());
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function add(RouterInterface $router, Route $route)
 {
     $router->add($route->getRoute(), $route->getPaths())->setName($route->getName())->setHostName($route->getParam('hostname'));
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function add(RouterInterface $router, Route $route)
 {
     $router->setDefaults(array_merge($route->getPaths(), ['params' => $route->getParams()]));
 }