/** * @param Method $method * @param string $endpoint * * @return RpcApiDoc */ protected function processMethod(Method $method, $endpoint) { /** @var string[] $views */ $views = $method->getContext(); if ($method->includeDefaultContext()) { $views[] = 'Default'; } $views[] = 'default'; $request = new Request($method, [], new ParameterBag(['_controller' => $method->getController()])); /** @var array $controller */ $controller = $this->resolver->getController($request); $refl = new \ReflectionMethod($controller[0], $controller[1]); /** @var RpcApiDoc $methodDoc */ $methodDoc = $this->reader->getMethodAnnotation($refl, RpcApiDoc::class); if (null === $methodDoc) { $methodDoc = new RpcApiDoc(['resource' => $endpoint]); } $methodDoc = clone $methodDoc; $methodDoc->setEndpoint($endpoint); $methodDoc->setRpcMethod($method); if (null === $methodDoc->getSection()) { $methodDoc->setSection($endpoint); } foreach ($views as $view) { $methodDoc->addView($view); } $route = new Route($endpoint); $route->setMethods([$endpoint]); $route->setDefault('_controller', get_class($controller[0]) . '::' . $controller[1]); $methodDoc->setRoute($route); return $methodDoc; }
public static function loadClass(ReflectionClass $refl, Reader $reader) { $router = Application::instance()->getRouter(); $annotation = $reader->getClassAnnotation($refl, 'Destiny\\Common\\Annotation\\Controller'); if (empty($annotation)) { return; } $methods = $refl->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { // Get all the route annotations $routes = array(); $annotations = $reader->getMethodAnnotations($method); for ($i = 0; $i < count($annotations); ++$i) { if ($annotations[$i] instanceof \Destiny\Common\Annotation\Route) { $routes[] = $annotations[$i]; } } // No routes, continue if (count($routes) <= 0) { continue; } // We have 1 or many routes, add to the router $httpMethod = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\HttpMethod'); $secure = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Secure'); $feature = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Feature'); for ($i = 0; $i < count($routes); ++$i) { $router->addRoute(new Route(array('path' => $routes[$i]->path, 'classMethod' => $method->name, 'class' => $refl->name, 'httpMethod' => $httpMethod ? $httpMethod->allow : null, 'secure' => $secure ? $secure->roles : null, 'feature' => $feature ? $feature->features : null))); } } }
private function extractAnnotation(\ReflectionMethod $m, $typeName) { if (($a = $this->reader->getMethodAnnotation($m, $typeName)) === null) { throw new NotFound("Annotation: {$typeName} is not found."); } return $a; }
/** * @param GetResponseEvent $event * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * @return bool */ public function onKernelRequest(GetResponseEvent $event) { if (strpos($event->getRequest()->attributes->get('_controller'), 'Api\\Resource') !== false) { header('Access-Control-Allow-Origin: *'); $controller = explode('::', $event->getRequest()->attributes->get('_controller')); $reflection = new \ReflectionMethod($controller[0], $controller[1]); $scopeAnnotation = $this->reader->getMethodAnnotation($reflection, 'Etu\\Core\\ApiBundle\\Framework\\Annotation\\Scope'); if ($scopeAnnotation) { $requiredScope = $scopeAnnotation->value; } else { $requiredScope = null; } if (!$requiredScope) { $requiredScope = 'public'; } $request = $event->getRequest(); $token = $request->query->get('access_token'); $access = $this->server->checkAccess($token, $requiredScope); if (!$access->isGranted()) { $event->setResponse($this->formatter->format($event->getRequest(), ['error' => $access->getError(), 'error_message' => $access->getErrorMessage()], 403)); } else { $event->getRequest()->attributes->set('_oauth_token', $access->getToken()); } } }
/** * @param \ReflectionClass $class * @param \ReflectionMethod $method * @return null|MethodMetadata */ private function loadMetadataForMethod(\ReflectionClass $class, \ReflectionMethod $method) { $methodAnnotation = $this->reader->getMethodAnnotation($method, Method::class); if ($methodAnnotation === null) { return null; } /** @var Method $methodAnnotation */ $methodMetadata = new MethodMetadata($class->name, $method->name); $methodMetadata->isMethod = true; $methodMetadata->isFormHandler = $methodAnnotation->formHandler; $methodMetadata->hasNamedParams = $methodAnnotation->namedParams; $methodMetadata->isStrict = $methodAnnotation->strict; $methodMetadata->hasSession = $methodAnnotation->session; $methodMetadata->addParameters($method->getParameters()); foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof Parameter) { if (!empty($annotation->constraints)) { $methodMetadata->addParameterMetadata($annotation->name, $annotation->constraints, $annotation->validationGroups, $annotation->strict, $annotation->serializationGroups, $annotation->serializationAttributes, $annotation->serializationVersion); } } } /** @var Result $resultAnnotation */ $resultAnnotation = $this->reader->getMethodAnnotation($method, Result::class); if ($resultAnnotation) { $methodMetadata->setResult($resultAnnotation->groups, $resultAnnotation->attributes, $resultAnnotation->version); } /** @var Security $securityAnnotation */ $securityAnnotation = $this->reader->getMethodAnnotation($method, Security::class); if ($securityAnnotation) { $methodMetadata->authorizationExpression = $securityAnnotation->expression; } return $methodMetadata; }
/** * Modifies the Request object to apply configuration information found in * controllers annotations like the template to render or HTTP caching * configuration. * * @param FilterControllerEvent $event A FilterControllerEvent instance * * @return void */ public function onKernelController(FilterControllerEvent $event) { if (!is_array($controller = $event->getController())) { return; } $className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]); $object = new \ReflectionClass($className); $transactional = $this->reader->getClassAnnotation($object, Transactional::NAME); if (!$transactional instanceof Transactional) { return; } $avoidTransaction = $this->reader->getMethodAnnotation($object->getMethod($controller[1]), AvoidTransaction::NAME); if (!is_null($avoidTransaction)) { return; } $request = $event->getRequest(); $modelName = $transactional->model; $model = new $modelName(); $this->transactionBuilder->setRequestMethod($request->getRealMethod()); $this->transactionBuilder->setRequestSource(Transaction::SOURCE_REST); $this->transactionBuilder->setRelatedRoute($transactional->relatedRoute); $ids = []; foreach ($model->getIds() as $field => $value) { $ids[$field] = $request->attributes->get($field); } $this->transactionBuilder->setRelatedIds($ids); $this->transactionBuilder->setModel($transactional->model); $transaction = $this->transactionBuilder->build(); $request->attributes->set('transaction', $transaction); }
/** * The interceptor is activated for public methods in Transactional annotated components. * * {@inheritDoc} */ public function matchesMethod(ReflectionMethod $method) { $transactionalEnabled = false; if ($method->isPublic()) { // Gets method-level annotation. /** @var Transactional $annotation */ $annotation = $this->reader->getMethodAnnotation($method, Transactional::class); $transactionalEnabled = $annotation !== null; if (!$transactionalEnabled) { // If there is no method-level annotation, gets class-level annotation. $annotation = $this->reader->getClassAnnotation($method->getDeclaringClass(), Transactional::class); $transactionalEnabled = $annotation !== null; } if ($transactionalEnabled) { switch ($annotation->getPolicy()) { case Transactional::NOT_REQUIRED: $policyName = 'not required'; break; case Transactional::REQUIRED: $policyName = 'required'; break; case Transactional::NESTED: $policyName = 'nested'; break; default: $policyName = 'default'; } $methodString = $method->getDeclaringClass()->name . '::' . $method->name; $this->logger->debug('TX policy for \'' . $methodString . '\': ' . $policyName); $noRollbackExceptionsStr = implode(', ', $annotation->getNoRollbackExceptions() === null ? ['default'] : $annotation->getNoRollbackExceptions()); $this->logger->debug('TX no-rollback exceptions for \'' . $methodString . '\': ' . $noRollbackExceptionsStr); } } return $transactionalEnabled; }
public static function loadClass(ReflectionClass $refl, Reader $reader, Router $router) { $annotation = $reader->getClassAnnotation($refl, 'Destiny\\Common\\Annotation\\Controller'); if (empty($annotation)) { return; } $methods = $refl->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { /** @var Route[] $routes */ $routes = array(); $annotations = $reader->getMethodAnnotations($method); for ($i = 0; $i < count($annotations); ++$i) { /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ if ($annotations[$i] instanceof \Destiny\Common\Annotation\Route) { $routes[] = $annotations[$i]; } } if (count($routes) <= 0) { continue; } /** @var \Destiny\Common\Annotation\HttpMethod $feature */ $httpMethod = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\HttpMethod'); /** @var \Destiny\Common\Annotation\Secure $feature */ $secure = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Secure'); for ($i = 0; $i < count($routes); ++$i) { $router->addRoute(new Route(array('path' => $routes[$i]->path, 'classMethod' => $method->name, 'class' => $refl->name, 'httpMethod' => $httpMethod ? $httpMethod->allow : null, 'secure' => $secure ? $secure->roles : null))); } } }
/** * Loads ACL annotations from PHP files * * @param AclAnnotationStorage $storage */ public function load(AclAnnotationStorage $storage) { $configLoader = OroSecurityExtension::getAclAnnotationLoader(); $resources = $configLoader->load(); foreach ($resources as $resource) { foreach ($resource->data as $file) { $className = $this->getClassName($file); if ($className !== null) { $reflection = $this->getReflectionClass($className); // read annotations from class $annotation = $this->reader->getClassAnnotation($reflection, self::ANNOTATION_CLASS); if ($annotation) { $storage->add($annotation, $reflection->getName()); } else { $ancestor = $this->reader->getClassAnnotation($reflection, self::ANCESTOR_CLASS); if ($ancestor) { $storage->addAncestor($ancestor, $reflection->getName()); } } // read annotations from methods foreach ($reflection->getMethods() as $reflectionMethod) { $annotation = $this->reader->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS); if ($annotation) { $storage->add($annotation, $reflection->getName(), $reflectionMethod->getName()); } else { $ancestor = $this->reader->getMethodAnnotation($reflectionMethod, self::ANCESTOR_CLASS); if ($ancestor) { $storage->addAncestor($ancestor, $reflection->getName(), $reflectionMethod->getName()); } } } } } } }
/** * @param $serviceId * @param $class * @param $method */ public function map($serviceId, $class, $method) { $class = new \ReflectionClass($class); $method = $class->getMethod($method); $annotations = []; $annotations[] = $this->reader->getMethodAnnotation($method, self::REGISTER_ANNOTATION_CLASS); $annotations[] = $this->reader->getMethodAnnotation($method, self::SUBSCRIBE_ANNOTATION_CLASS); $securityAnnotation = $this->reader->getMethodAnnotation($method, self::SECURITY_ANNOTATION_CLASS); /* @var $annotation Register */ foreach ($annotations as $annotation) { if ($annotation) { /* @var $workerAnnotation Register */ $workerAnnotation = isset($this->workerAnnotationsClasses[$class->getName()]) ? $this->workerAnnotationsClasses[$class->getName()] : null; if ($workerAnnotation) { $worker = $workerAnnotation->getName(); } else { $worker = $annotation->getWorker() ?: "default"; } $mapping = new URIClassMapping($serviceId, $method, $annotation); if (isset($this->mappings[$worker][$annotation->getName()])) { $uri = $annotation->getName(); $className = $this->mappings[$worker][$annotation->getName()]->getMethod()->class; throw new Exception("The URI '{$uri}' has already been registered in '{$className}' for the worker '{$worker}'"); } //Set security Annotation $mapping->setSecurityAnnotation($securityAnnotation); $this->mappings[$worker][$annotation->getName()] = $mapping; } } }
public function invoke(MethodInvocation $invocation) { $resource = $invocation->getThis(); $result = $invocation->proceed(); $annotation = $this->reader->getMethodAnnotation($invocation->getMethod(), Annotation\ResourceDelegate::class); if (isset($annotation)) { $class = $this->getDelegateClassName($annotation, $resource); if (!class_exists($class)) { throw new InvalidAnnotationException('Resource Delegate class is not found.'); } $method = isset($resource->uri->query['_override']) ? $resource->uri->query['_override'] : $resource->uri->method; if (stripos($method, $resource->uri->method) !== 0) { throw new InvalidMatcherException('Overriden method must match to original method'); } $call = $this->resolveDelegateMethod($method); if (!method_exists($class, $call)) { throw new InvalidMatcherException('Resource Delegate method is not found'); } $delegate = new $class($resource); $params = $this->paramHandler->getParameters([$delegate, $call], $resource->uri->query); return call_user_func_array([$delegate, $call], $params); } else { $result; } }
/** * Load JSON API configuration from controller annotations * * @param FilterControllerEvent $event */ public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); if (!is_array($controller)) { return; } $config = null; $refClass = new \ReflectionClass($controller[0]); if (null !== ($annotation = $this->reader->getClassAnnotation($refClass, ApiRequest::class))) { /* @var $annotation ApiRequest */ $config = $annotation->toArray(); } $refMethod = $refClass->getMethod($controller[1]); if (null !== ($annotation = $this->reader->getMethodAnnotation($refMethod, ApiRequest::class))) { if (null !== $config) { $config = array_replace($config, $annotation->toArray()); } else { $config = $annotation->toArray(); } } if (null !== $config) { if (!array_key_exists('matcher', $config)) { $config['matcher'] = $this->defMatcher; } $event->getRequest()->attributes->set('_jsonapi', $this->factory->createEnvironment($config)); } }
/** * @param \ReflectionMethod $action * @return bool|Annotation */ public function supports(\ReflectionMethod $action) { $annotation = $this->reader->getMethodAnnotation($action, $this->annotationClass); if ($annotation !== null) { return $annotation; } return false; }
/** * {@inheritdoc} */ public function getMethodAnnotation(\ReflectionMethod $method, $annotationName) { $annotation = $this->innerReader->getMethodAnnotation($method, $annotationName); if (null === $annotation) { return null; } return $this->processMethodAnnotation($annotation); }
/** * @return boolean */ private function isProtectedByCsrfDoubleSubmit(\ReflectionClass $class, \ReflectionMethod $method) { $annotation = $this->annotationReader->getClassAnnotation($class, 'Bazinga\\Bundle\\RestExtraBundle\\Annotation\\CsrfDoubleSubmit'); if (null !== $annotation) { return true; } $annotation = $this->annotationReader->getMethodAnnotation($method, 'Bazinga\\Bundle\\RestExtraBundle\\Annotation\\CsrfDoubleSubmit'); return null !== $annotation; }
/** * Listens when the annotation exists loading the resource of id given and if it is allowed. * * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event The filter controller event */ public function onResourceIfAllowedAnnotationMethod(FilterControllerEvent $event) { list($object, $method) = $event->getController(); $reflectionClass = new \ReflectionClass(get_class($object)); $reflectionMethod = $reflectionClass->getMethod($method); if ($annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, $this->annotationClass)) { $resourceId = $event->getRequest()->attributes->get(sprintf('%sId', $this->resource)); if (null !== $resourceId) { $event->getRequest()->attributes->set($this->resource, $this->getResourceIfAllowed($resourceId, $annotation->getGrant())); } } }
/** * @param object $service * * @return callable[] */ private function extractCallables($service) { $methods = []; $reflectionClass = new \ReflectionClass($service); foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { /** @var Method $methodAnnotation */ $methodAnnotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, Method::class); if ($methodAnnotation instanceof Method) { $methods[$methodAnnotation->name] = [$service, $reflectionMethod->name]; } } return $methods; }
public function collect(Request $request, Response $response, \Exception $exception = null) { parent::collect($request, $response, $exception); $controller = explode('::', $request->get('_controller')); if (count($controller) !== 2) { return; } $class = new \ReflectionClass($controller[0]); $reflectionMethod = $class->getMethod($controller[1]); $annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, '\\Rezzza\\SecurityBundle\\Controller\\Annotations\\ObfuscateRequest'); if ($annotation) { $this->data = $this->obfuscator->obfuscate($this->data, $annotation->getObfuscatedPatterns()); } }
/** * Runs the inspection on the target class and saves its handlers. */ private function inspect() { foreach (ReflectionUtils::getMethods($this->targetClass) as $method) { $annotation = $this->annotationReader->getMethodAnnotation($method, $this->annotation); if (!$annotation) { continue; } $payloadType = $this->extractPayloadType($method); $methodAnnotations = $this->annotationReader->getMethodAnnotations($method); if ($payloadType) { $this->handlers[] = new AnnotatedHandlerDefinition($this->targetClass, $method, $methodAnnotations, $payloadType); } } }
/** * @param $obj * @return ConsumerContainer[] */ public function getConsumerMethods($obj) { $class = new ReflectionClass($obj); $consumerMethods = []; foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { /** @var Consumer $annotation */ $annotation = $this->reader->getMethodAnnotation($method, Consumer::class); if (null === $annotation) { continue; } $this->validateMethod($method); $consumerMethods[] = new ConsumerContainer($this->prefix, $obj, $method, $annotation); } return $consumerMethods; }
/** * Listens when the annotation exists checking the user has role to execute this method. * * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event The filter controller event */ public function onRoleAnnotationMethod(FilterControllerEvent $event) { list($object, $method) = $event->getController(); $reflectionClass = new \ReflectionClass(get_class($object)); $reflectionMethod = $reflectionClass->getMethod($method); if ($annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, $this->annotationClass)) { foreach ($annotation->getRoles() as $role) { $method = sprintf('is%s', ucwords($role)); if (method_exists($this, $method) && true === $this->{$method}()) { return; } } throw new AccessDeniedException(); } }
public function getTypeFromMethod($method) { if (is_string($method)) { throw new \InvalidArgumentException('Parameter $property cannot be a string unless the string is a valid primitive type'); } $typeAnnotation = $this->annotationReader->getMethodAnnotation($method, 'Rezonant\\MapperBundle\\Annotations\\Type'); if ($typeAnnotation) { return $typeAnnotation->value; } $typeAnnotation = $this->annotationReader->getMethodAnnotation($method, 'JMS\\Serializer\\Annotation\\Type'); if ($typeAnnotation) { return $typeAnnotation->name; } return null; }
/** * Gets the GeographicalQuery annotation for the specified object. * * @param object $obj The object * @return GeographicalQuery The geographical query annotation */ public function getGeographicalQueryAnnotation($obj) { if (!is_object($obj)) { throw new \InvalidArgumentException(); } $refClass = new \ReflectionClass($obj); foreach ($refClass->getMethods() as $method) { $annot = $this->reader->getMethodAnnotation($method, 'Vich\\GeographicalBundle\\Annotation\\GeographicalQuery'); if ($annot) { $annot->setMethod($method->getName()); return $annot; } } return null; }
/** * {@inheritdoc} */ public function invoke(callable $callable, $requestObject) { /** @var Attribute $attributeAnnotation */ $attributeAnnotation = $this->annotationReader->getMethodAnnotation(ReflectionFunctionFactory::createReflectionMethodFromCallable($callable), Attribute::class); $attributeName = $attributeAnnotation->name; $attributeValue = $this->propertyAccessor->getValue($requestObject, $attributeAnnotation->valueAt); $userId = $this->userProvider->getUserId(); if (!is_array($attributeValue) && !$this->guard->isGranted($userId, $attributeName, $attributeValue)) { throw new AccessDeniedException(); } if (is_array($attributeValue)) { $attributeValue = $this->guard->filterGranted($userId, $attributeName, $attributeValue); $this->propertyAccessor->setValue($requestObject, $attributeAnnotation->valueAt, $attributeValue); } return $this->methodInvoker->invoke($callable, $requestObject); }
/** * Change a theme based on the annotationValue. * @api Core-2.0 * @param string $controllerClassName * @param string $method * @return bool|string */ public function changeThemeByAnnotation($controllerClassName, $method) { $reflectionClass = new \ReflectionClass($controllerClassName); $reflectionMethod = $reflectionClass->getMethod($method); $themeAnnotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, 'Zikula\\Core\\Theme\\Annotation\\Theme'); if (isset($themeAnnotation)) { // method annotations contain `@Theme` so set theme based on value $this->annotationValue = $themeAnnotation->value; switch ($themeAnnotation->value) { case 'admin': $newThemeName = \ModUtil::getVar('ZikulaAdminModule', 'admintheme', ''); break; case 'print': $newThemeName = 'ZikulaPrinterTheme'; break; case 'atom': $newThemeName = 'ZikulaAtomTheme'; break; case 'rss': $newThemeName = 'ZikulaRssTheme'; break; default: $newThemeName = $themeAnnotation->value; } if (!empty($newThemeName)) { $this->setActiveTheme($newThemeName); return $newThemeName; } } return false; }
/** * Reads method annotations. * * @param \ReflectionMethod $reflectionMethod * @param string $annotationName * * @return RouteAnnotation|null */ private function readMethodAnnotation(\ReflectionMethod $reflectionMethod, $annotationName) { $annotationClass = "FOS\\RestBundle\\Controller\\Annotations\\{$annotationName}"; if ($annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, $annotationClass)) { return $annotation; } }
/** * @param $annotationName * @param CommandMessageInterface $command * @param \ReflectionClass $reflectionClass * @return mixed|null */ private function getAnnotatedTargetValue($annotationName, CommandMessageInterface $command, \ReflectionClass $reflectionClass) { foreach (ReflectionUtils::getProperties($reflectionClass) as $property) { if (null !== ($annotation = $this->reader->getPropertyAnnotation($property, $annotationName))) { $property->setAccessible(true); return $property->getValue($command->getPayload()); } } foreach (ReflectionUtils::getMethods($reflectionClass) as $method) { if (null !== ($annotation = $this->reader->getMethodAnnotation($method, $annotationName))) { $method->setAccessible(true); return $method->invoke($command->getPayload()); } } return null; }
/** * @param \ReflectionMethod $method_reflection * @param array $routes * @param ApiRoute $route * @return void */ private function findPresenterMethodRoute(\ReflectionMethod $method_reflection, &$routes, ApiRoute $route) { $action_route = $this->reader->getMethodAnnotation($method_reflection, ApiRoute::class); /** * Get action without that ^action string */ $action = lcfirst(preg_replace('/^action/', '', $method_reflection->name)); /** * Route can be defined also for particular action */ if (!$action_route) { $route->setAction($action); return; } if ($method_reflection instanceof Nette\Reflection\Method) { $action_route->setDescription($method_reflection->getAnnotation('description')); } /** * Action route will inherit presenter name, priority, etc from parent route */ $action_route->setPresenter($action_route->getPresenter() ?: $route->getPresenter()); $action_route->setPriority($action_route->getPriority() ?: $route->getPriority()); $action_route->setFormat($action_route->getFormat() ?: $route->getFormat()); $action_route->setSection($action_route->getSection() ?: $route->getSection()); $action_route->setAction($action, $action_route->getMethod() ?: NULL); $routes[$route->getPriority()][] = $action_route; }
public function it_should_read_annotations_from_specified_instances(Reader $annotationReader) { $this->add(new AnnotatedService()); $methodAnnotation = new Method(); $methodAnnotation->name = 'some.method'; $annotationReader->getMethodAnnotation(new \ReflectionMethod(new AnnotatedService(), 'coolMethod'), Method::class)->willReturn($methodAnnotation); $this->load()->shouldBeLike(new MethodCollection(['some.method' => [new AnnotatedService(), 'coolMethod']])); }
/** * Loads ACL annotations from PHP files * * @param AclAnnotationStorage $storage */ public function load(AclAnnotationStorage $storage) { if (!empty($this->subDirs)) { $directories = []; foreach ($this->bundleDirectories as $bundleDir) { foreach ($this->subDirs as $subDir) { $dir = $bundleDir . DIRECTORY_SEPARATOR . $subDir; if (is_dir($dir)) { $directories[] = $dir; } } } } else { $directories = $this->bundleDirectories; } $files = $this->findFiles('*.php', $directories); foreach ($files as $file) { $className = $this->getClassName($file); if ($className !== null) { $reflection = $this->getReflectionClass($className); // read annotations from class $annotation = $this->reader->getClassAnnotation($reflection, self::ANNOTATION_CLASS); if ($annotation) { $storage->add($annotation, $reflection->getName()); } else { $ancestor = $this->reader->getClassAnnotation($reflection, self::ANCESTOR_CLASS); if ($ancestor) { $storage->addAncestor($ancestor, $reflection->getName()); } } // read annotations from methods foreach ($reflection->getMethods() as $reflectionMethod) { $annotation = $this->reader->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS); if ($annotation) { $storage->add($annotation, $reflection->getName(), $reflectionMethod->getName()); } else { $ancestor = $this->reader->getMethodAnnotation($reflectionMethod, self::ANCESTOR_CLASS); if ($ancestor) { $storage->addAncestor($ancestor, $reflection->getName(), $reflectionMethod->getName()); } } } } } }