Пример #1
0
 protected static function getClassRoutes($className, $directoryPrefix, $urlPrefix, $parseActions = TRUE)
 {
     $regex = sprintf('@^Controller_%s_V(\\d+)_(.+)$@', str_replace(DIRECTORY_SEPARATOR, '_', rtrim($directoryPrefix, DIRECTORY_SEPARATOR)));
     if (preg_match($regex, $className, $matches)) {
         $version = $matches[1];
         $urlPrefix = str_replace('{version}', $version, $urlPrefix) . '/';
         $controllerName = $matches[2];
         /** @var RestfulAPI\Route $route */
         $route = Annotations::getClassAnnotation($className, self::annotationRoute);
         if (NULL === $route) {
             $route = Annotations::annotationClass(self::annotationRoute);
         }
         $route->name = $className;
         $route->value = $urlPrefix . $route->value;
         $routeDefaults = ['directory' => $directoryPrefix . 'V' . $version, 'controller' => $controllerName];
         if ($parseActions) {
             $classReflection = new ReflectionClass($className);
             $classActions = $classReflection->getMethods(ReflectionMethod::IS_PUBLIC);
             foreach ($classActions as $method) {
                 if (!$method->isFinal() && preg_match('@^action_(([^_]+)(?:_(.+))?)$@', $method->name, $actionMatches)) {
                     /** @var RestfulAPI\Route $actionRoute */
                     $actionRoute = Annotations::getMethodAnnotation($method->name, self::annotationRoute, $className);
                     if (NULL !== $actionRoute) {
                         $actionRoute->name = $className . '::' . Arr::get($actionMatches, 1, $method->name);
                         $actionRoute->value = $urlPrefix . $actionRoute->value;
                         $actionRoute->defaults['action'] = Arr::get($actionMatches, 3);
                         self::makeRoute($actionRoute, $routeDefaults);
                     }
                 }
             }
         }
         self::makeRoute($route, $routeDefaults);
     }
 }