Exemple #1
0
 public static function generate()
 {
     $reflector = new Wave\Reflector(Wave\Config::get('wave')->path->controllers);
     $reflected_options = $reflector->execute();
     $all_actions = self::buildRoutes($reflected_options);
     foreach ($all_actions as $profile => $actions) {
         $route_node = new Node();
         foreach ($actions as $action) {
             foreach ($action->getRoutes() as $route) {
                 $route_node->addChild($route, $action);
             }
         }
         Wave\Cache::store(Router::getCacheName($profile, 'table'), $actions);
         Wave\Cache::store(Router::getCacheName($profile, 'tree'), $route_node);
     }
 }
 public function getOperations()
 {
     $reflector = new Reflector($this->controller_dir);
     $reflected_options = $reflector->execute();
     $routes = Generator::buildRoutes($reflected_options);
     /**
      * @var string $callable
      * @var Action $action
      */
     $operations = [];
     foreach ($routes['default'] as $callable => $action) {
         // Retrieve class and method
         list($class, $function) = explode('.', $action->getAction());
         $class = preg_replace('/^Controllers\\\\?/i', '', $class);
         $class = preg_replace('/Controller$/i', '', $class);
         foreach ($action->getRoutes() as $route) {
             $matches = preg_split('/(?<!<)\\/(?!>)/', $route);
             $method = strtolower(array_shift($matches));
             if (!in_array($method, self::$allowed_methods)) {
                 continue;
             }
             $in_hint = $this->getParameterInHint($method);
             $operation = new Operation(['method' => $method, 'class' => $class, 'function' => $function]);
             foreach ($action->getAnnotations() as $key => $annotations) {
                 foreach ($annotations as $annotation) {
                     $this->applyAnnotation($key, $annotation, $operation, $in_hint);
                 }
             }
             foreach ($matches as $i => $part) {
                 if (preg_match('/<(?<type>.+?)>(?<name>\\w+)/i', $part, $match)) {
                     $matches[$i] = sprintf('{%s}', $match['name']);
                     $parameter = array('name' => $match['name'], 'in' => Parameter::IN_PATH, 'required' => true);
                     $this->convertType($match['type'], $parameter);
                     $operation->addParameter(new Parameter($parameter));
                 }
             }
             $route = '/' . implode('/', $matches);
             $operation->path = $route;
             $operation->resolveParameterPlacement();
             if (!array_key_exists($route, $operations)) {
                 $operations[$route] = array();
             }
             $operations[$route][$method] = $operation;
         }
     }
     return $operations;
 }