public function scan() { $mappings = []; $matcher = Match::annotatedWith("Spot\\App\\REST\\Resource"); foreach ($this->namespaces as $ns) { foreach ($this->reflection->find($ns, $matcher) as $type) { $resource = $type->getAnnotation("Spot\\App\\REST\\Resource"); foreach ($type->getMethods(Method::IS_PUBLIC) as $method) { if (!$method->isAnnotatedWith("Spot\\App\\REST\\Impl\\RequestMethod")) { continue; } $path = $method->getAnnotation("Spot\\App\\REST\\Path") ?: new Path(); $route = new Route(); $route->value = $resource->value . $path->value; $route->method = (string) $method->getAnnotation("Spot\\App\\REST\\Impl\\RequestMethod"); $mappings[] = new ActionMapping($route, $method->getType()->name . "::" . $method->name); } } } return $mappings; }
public function scan() { $mappings = []; $matcher = Match::annotatedWith("Spot\\App\\Web\\Controller"); foreach ($this->namespaces as $ns) { foreach ($this->reflection->find($ns, $matcher) as $type) { $typeRoute = $type->getAnnotation("Spot\\App\\Web\\Route") ?: new Route(); foreach ($type->getMethods(Method::IS_PUBLIC) as $method) { if (!$method->isAnnotatedWith("Spot\\App\\Web\\Route")) { continue; } $route = $method->getAnnotation("Spot\\App\\Web\\Route"); $route->value = $typeRoute->value . $route->value; $route->ajax = $route->ajax === null ? $typeRoute->ajax : $route->ajax; $route->method = $route->method ?: $typeRoute->method ?: [Request::GET, Request::POST]; if (!isset($route->value[0]) || $route->value[0] != "/") { throw new \LogicException("Controller uri must start with \"/\""); } $mappings[] = new ActionMapping($route, $method->getType()->name . "::" . $method->name); } } } return $mappings; }