/** * 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 */ 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); $method = $object->getMethod($controller[1]); $classConfigurations = $this->getConfigurations($this->reader->getClassAnnotations($object)); $methodConfigurations = $this->getConfigurations($this->reader->getMethodAnnotations($method)); $configurations = array(); foreach (array_merge(array_keys($classConfigurations), array_keys($methodConfigurations)) as $key) { if (!array_key_exists($key, $classConfigurations)) { $configurations[$key] = $methodConfigurations[$key]; } elseif (!array_key_exists($key, $methodConfigurations)) { $configurations[$key] = $classConfigurations[$key]; } else { if (is_array($classConfigurations[$key])) { if (!is_array($methodConfigurations[$key])) { throw new \UnexpectedValueException('Configurations should both be an array or both not be an array'); } $configurations[$key] = array_merge($classConfigurations[$key], $methodConfigurations[$key]); } else { // method configuration overrides class configuration $configurations[$key] = $methodConfigurations[$key]; } } } $request = $event->getRequest(); foreach ($configurations as $key => $attributes) { $request->attributes->set($key, $attributes); } }
/** * @param FilterControllerEvent $event * * @throws \Exception */ public function onKernelController(FilterControllerEvent $event) { if (!is_array($controller = $event->getController())) { return; } $object = new \ReflectionObject($controller[0]); $method = $object->getMethod($controller[1]); foreach ($this->reader->getMethodAnnotations($method) as $configuration) { if ($configuration instanceof ViewModel) { if ($configuration->hasClass()) { $class = $configuration->getClass(); $viewModel = new $class($this->templating); } elseif ($configuration->hasService()) { $viewModel = $this->getService($configuration->getService()); } else { throw new \Exception("Invalid View Model configuration."); } if (!$viewModel instanceof ViewModelInterface) { throw new \Exception("View model passed does not implement " . "Aequasi\\Bundle\\ViewModelBundle\\View\\Model\\ViewModelInterface"); } $this->viewModelService->setViewModel($viewModel); } if ($configuration instanceof ViewModelFactory) { $factory = $this->getFactory($configuration->getFactory()); if (!$factory instanceof ViewModelFactoryInterface) { throw new \Exception("View model passed does not implement " . "Aequasi\\Bundle\\ViewModelBundle\\View\\Model\\ViewModelInterface"); } $viewModel = $factory->create($configuration->getArguments()); if (!$viewModel instanceof ViewModelInterface) { throw new \Exception("View model passed does not implement " . "Aequasi\\Bundle\\ViewModelBundle\\View\\Model\\ViewModelInterface"); } $this->viewModelService->setViewModel($viewModel); } } }
/** * @param ReflectionMethod $method * * @return CacheAnnotation[]|AnnotationCollection */ private function collectMethodCacheAnnotations(ReflectionMethod $method) { $annotations = array_filter($this->annotationsReader->getMethodAnnotations($method), function ($annotation) { return $annotation instanceof CacheAnnotation; }); return new AnnotationCollection($annotations); }
public function onFilterController(FilterControllerEvent $event) { list($object, $method) = $event->getController(); // the controller could be a proxy $className = ClassUtils::getClass($object); $reflectionClass = new \ReflectionClass($className); $reflectionMethod = $reflectionClass->getMethod($method); $allControllerAnnotations = $this->annotationReader->getClassAnnotations($reflectionClass); $allMethodAnnotations = $this->annotationReader->getMethodAnnotations($reflectionMethod); $guardAnnotationsFilter = function ($annotation) { return $annotation instanceof Guard; }; $controllerGuardAnnotations = array_filter($allControllerAnnotations, $guardAnnotationsFilter); $methodGuardAnnotations = array_filter($allMethodAnnotations, $guardAnnotationsFilter); $guardAnnotations = array_merge($controllerGuardAnnotations, $methodGuardAnnotations); $permissions = []; foreach ($guardAnnotations as $guardAnnotation) { $value = $guardAnnotation->value; if (!is_array($value)) { $value = [$value]; } $permissions = array_merge($value, $permissions); } $permissions = array_unique($permissions); if (!empty($permissions) && !$this->security->isGranted($permissions)) { $e = new PermissionRequiredException(); $e->setRequiredPermissions($permissions)->setCurrentPermissions($this->security->getToken()->getUser()->getPermissions()); throw $e; } }
/** {@inheritdoc} */ public function load($class, $type = null) { if (!class_exists($class)) { throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class)); } $class = new \ReflectionClass($class); if ($class->isAbstract()) { throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class->getName())); } $parents = $this->getParentAnnotations($class); $collection = new MethodCollection(); $collection->addResource(new FileResource($class->getFileName())); foreach ($class->getMethods() as $method) { if (!$method->isPublic()) { continue; } foreach ($this->reader->getMethodAnnotations($method) as $annot) { if ($annot instanceof Method) { $this->addRoute($collection, $annot, $parents, $class, $method); } } } $collection->addPrefix($parents['method']); return $collection; }
/** * {@inheritDoc} */ public function loadActions() { $actions = new ActionCollection(); foreach ($this->classes as $id => $class) { $reflection = Reflection::loadClassReflection($class); // Get all methods from class $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { $methodAnnotations = $this->reader->getMethodAnnotations($method); foreach ($methodAnnotations as $annotation) { if ($annotation instanceof ActionAnnotation) { if ($method->isStatic()) { throw new \RuntimeException('The static method not supported (@todo).'); } if ($annotation->response) { $response = new ObjectResponse($annotation->response->class); } else { $response = null; } $action = new ServiceAction($annotation->name, $id, $method->getName(), $annotation->validationGroups, $annotation->securityGroups, $annotation->requestMappingGroup, $annotation->useStrictValidation, $annotation->checkEnabled, $response); $actions->addAction($action); } } } } return $actions; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $metadata) { $reflClass = $metadata->getReflectionClass(); $className = $reflClass->name; $loaded = false; foreach ($reflClass->getProperties() as $property) { if ($property->getDeclaringClass()->name == $className) { foreach ($this->reader->getPropertyAnnotations($property) as $groups) { if ($groups instanceof Groups) { foreach ($groups->getGroups() as $group) { $metadata->addAttributeGroup($property->name, $group); } } $loaded = true; } } } foreach ($reflClass->getMethods() as $method) { if ($method->getDeclaringClass()->name == $className) { foreach ($this->reader->getMethodAnnotations($method) as $groups) { if ($groups instanceof Groups) { if (preg_match('/^(get|is)(.+)$/i', $method->name, $matches)) { foreach ($groups->getGroups() as $group) { $metadata->addAttributeGroup(lcfirst($matches[2]), $group); } } else { throw new \BadMethodCallException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get" or "is".', $className, $method->name)); } } $loaded = true; } } } return $loaded; }
/** * @param \ReflectionClass $class * * @return \Metadata\ClassMetadata */ public function loadMetadataForClass(\ReflectionClass $class) { $classMetadata = new ClassMetadata($name = $class->name); $classMetadata->fileResources[] = $class->getFilename(); foreach ($class->getMethods() as $method) { /** * @var \ReflectionMethod $method */ if ($method->class !== $name) { continue; } $methodAnnotations = $this->reader->getMethodAnnotations($method); foreach ($methodAnnotations as $annotation) { if ($annotation instanceof ParamType) { if (!$classMetadata->hasMethod($method->name)) { $this->addMethod($classMetadata, $method); } $classMetadata->setParameterType($method->getName(), $annotation->name, $annotation->type); $classMetadata->setParameterOptions($method->getName(), $annotation->name, $annotation->options); } if ($annotation instanceof ReturnType) { $classMetadata->setReturnType($method->getName(), $annotation->type); } } } return $classMetadata; }
/** * {@inheritDoc} */ public function loadForMethod($class, $method, $group) { $methodReflection = Reflection::loadMethodReflection($class, $method); $methodAnnotations = $this->reader->getMethodAnnotations($methodReflection); $securityMethodAnnotation = null; $rules = array(); foreach ($methodAnnotations as $methodAnnotation) { if ($methodAnnotation instanceof MethodSecurityAnnotation && $group == $methodAnnotation->group) { if ($securityMethodAnnotation) { throw new \RuntimeException(sprintf('The @MethodSecurity annotation already defined in method "%s::%s".', $class, $method)); } $securityMethodAnnotation = $methodAnnotation; } if ($rule = $this->transformAnnotationToRule($methodAnnotation, $group, $class)) { $rules[] = $rule; } } if (!$securityMethodAnnotation && !count($rules)) { return null; } if ($securityMethodAnnotation) { $strategy = $securityMethodAnnotation->strategy; } else { $strategy = Security::STRATEGY_AFFIRMATIVE; } $securityMethod = new MethodSecurity($class, $method, $strategy, $rules, $group); return $securityMethod; }
/** * Reads the "@Access" annotations from the controller stores them in the "access" route option. */ public function onConfigureRoute($event, $route) { if (!$this->reader) { $this->reader = new SimpleAnnotationReader(); $this->reader->addNamespace('Pagekit\\User\\Annotation'); } if (!$route->getControllerClass()) { return; } $access = []; foreach (array_merge($this->reader->getClassAnnotations($route->getControllerClass()), $this->reader->getMethodAnnotations($route->getControllerMethod())) as $annot) { if (!$annot instanceof Access) { continue; } if ($expression = $annot->getExpression()) { $access[] = $expression; } if ($admin = $annot->getAdmin() !== null) { $route->setPath('admin' . rtrim($route->getPath(), '/')); $permission = 'system: access admin area'; if ($admin) { $access[] = $permission; } else { if ($key = array_search($permission, $access)) { unset($access[$key]); } } } } if ($access) { $route->setDefault('_access', array_unique($access)); } }
public function onKernelController(FilterControllerEvent $event) { if (!is_array($controller = $event->getController())) { return; } $object = new \ReflectionObject($controller[0]); $method = $object->getMethod($controller[1]); $classConfigurations = $this->reader->getClassAnnotations($object); $methodConfigurations = $this->reader->getMethodAnnotations($method); foreach (array_merge($classConfigurations, $methodConfigurations) as $configuration) { if ($configuration instanceof OAuth2) { $token = $this->token_storage->getToken(); // If no access token is found by the firewall, then returns an authentication error if (!$token instanceof OAuth2Token) { $this->createAuthenticationException($event, 'OAuth2 authentication required'); return; } foreach ($this->getCheckers() as $checker) { $result = $checker->check($token, $configuration); if (null !== $result) { $this->createAccessDeniedException($event, $result); return; } } } } }
/** * This event will fire during any controller call. * * @param FilterControllerEvent $event * * @return type * * @throws AccessDeniedHttpException */ public function onKernelController(FilterControllerEvent $event) { if (!is_array($controller = $event->getController())) { //return if no controller return; } $object = new \ReflectionObject($controller[0]); // get controller $method = $object->getMethod($controller[1]); // get method $configurations = $this->reader->getMethodAnnotations($method); foreach ($configurations as $configuration) { //Start of annotations reading if (isset($configuration->grantType) && $controller[0] instanceof BaseProjectController) { //Found our annotation $controller[0]->setProjectGrantType($configuration->grantType); $request = $controller[0]->get('request_stack')->getCurrentRequest(); $id = $request->get('id', false); if ($id !== false) { $redirectUrl = $controller[0]->initAction($id, $configuration->grantType); if ($redirectUrl) { $event->setController(function () use($redirectUrl) { return new RedirectResponse($redirectUrl); }); } } } } }
/** * @param string $className * * @return array */ public function processClass($className, $path) { $reflection = new \ReflectionClass($className); if (null === $this->reader->getClassAnnotation($reflection, $this->annotationClass)) { return array(); } $mappings = array(); $this->output->writeln("Found class: {$className}"); foreach ($reflection->getMethods() as $method) { /** @var Method[] $annotations */ $annotations = $this->reader->getMethodAnnotations($method); if (0 == count($annotations)) { continue; } $this->output->writeln(sprintf("Found annotations for method %s::%s.", $method->class, $method->getName())); foreach ($annotations as $annotation) { if (!$annotation instanceof Method) { continue; } $this->output->writeln(sprintf("Found mapping: %s::%s --> %s::%s", $method->class, $method->getName(), $annotation->getClass(), $annotation->getMethod())); $mapping = new Mapping(); $moduleFile = $reflection->getFileName(); $moduleFile = substr($moduleFile, strpos($moduleFile, $path)); $mapping->setOxidClass($annotation->getClass())->setOxidMethod($annotation->getMethod())->setModuleClass($className)->setModuleMethod($method->getName())->setReturn($annotation->hasReturnValue())->setParentExecution($annotation->getParentExecution())->setModuleFile($moduleFile); $mappings[] = $mapping; } } return $mappings; }
public function create(UseCase $useCase, $tagParameters) { try { /** @var UseCase $useCase */ $methodAnnotations = $this->reader->getMethodAnnotations(new \ReflectionMethod($useCase, 'execute')); /** @var UseCaseProxyBuilder $builder */ $this->builder->create($useCase)->withReader($this->reader); foreach ($methodAnnotations as $annotation) { if ($annotation instanceof SecurityAnnotation) { $this->builder->withSecurity($this->buildSecurity($tagParameters)); } if ($annotation instanceof CacheAnnotation) { $this->builder->withCache($this->buildCache($tagParameters)); } if ($annotation instanceof TransactionAnnotation) { $this->builder->withTransaction($this->buildTransaction($tagParameters)); } if ($annotation instanceof EventAnnotation) { $this->builder->withEventSender($this->buildEvent($tagParameters))->withEventFactory($this->buildEventFactory($tagParameters)); } } return $this->builder->build(); } catch (SecurityIsNotDefinedException $sinde) { throw new SecurityIsNotDefinedException('Security should be defined for use case: ' . get_class($useCase) . '. ' . $sinde->getMessage()); } catch (CacheIsNotDefinedException $cinde) { throw new CacheIsNotDefinedException('Cache should be defined for use case: ' . get_class($useCase) . '. ' . $cinde->getMessage()); } catch (TransactionIsNotDefinedException $tinde) { throw new TransactionIsNotDefinedException('Transaction should be defined for use case: ' . get_class($useCase) . '. ' . $tinde->getMessage()); } catch (EventIsNotDefinedException $einde) { throw new EventIsNotDefinedException('EventSender should be defined for use case: ' . get_class($useCase) . '. ' . $einde->getMessage()); } catch (EventFactoryIsNotDefinedException $efinde) { throw new EventFactoryIsNotDefinedException('EventFactory should be defined for use case: ' . get_class($useCase) . '. ' . $efinde->getMessage()); } }
/** * Load metadata class * * @param \ReflectionClass $class * @return ClassMetadata */ public function loadMetadataForClass(\ReflectionClass $class) { $classMetadata = new ClassMetadata($class->name); $classMetadata->fileResources[] = $class->getFileName(); foreach ($this->reader->getClassAnnotations($class) as $annotation) { if ($annotation instanceof NamespaceNode) { $classMetadata->addGraphNamespace($annotation); } if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new MetadataValue($annotation->value)); } } foreach ($class->getProperties() as $property) { foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new PropertyMetadata($class->name, $property->name)); } } } foreach ($class->getMethods() as $method) { foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new MethodMetadata($class->name, $method->name)); } } } return $classMetadata; }
/** * Get Annotations for method * * @param \ReflectionMethod $method * @return array */ public function getMethodAnnotations(\ReflectionMethod $method) { $annotations = array(); foreach ($this->delegate->getMethodAnnotations($method) as $annot) { $annotations[get_class($annot)] = $annot; } return $annotations; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadataInterface $classMetadata) { $reflectionClass = $classMetadata->getReflectionClass(); $className = $reflectionClass->name; $loaded = false; $attributesMetadata = $classMetadata->getAttributesMetadata(); foreach ($reflectionClass->getProperties() as $property) { if (!isset($attributesMetadata[$property->name])) { $attributesMetadata[$property->name] = new AttributeMetadata($property->name); $classMetadata->addAttributeMetadata($attributesMetadata[$property->name]); } if ($property->getDeclaringClass()->name === $className) { foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { if ($annotation instanceof Groups) { foreach ($annotation->getGroups() as $group) { $attributesMetadata[$property->name]->addGroup($group); } } elseif ($annotation instanceof MaxDepth) { $attributesMetadata[$property->name]->setMaxDepth($annotation->getMaxDepth()); } $loaded = true; } } } foreach ($reflectionClass->getMethods() as $method) { if ($method->getDeclaringClass()->name !== $className) { continue; } $accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches); if ($accessorOrMutator) { $attributeName = lcfirst($matches[2]); if (isset($attributesMetadata[$attributeName])) { $attributeMetadata = $attributesMetadata[$attributeName]; } else { $attributesMetadata[$attributeName] = $attributeMetadata = new AttributeMetadata($attributeName); $classMetadata->addAttributeMetadata($attributeMetadata); } } foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof Groups) { if (!$accessorOrMutator) { throw new MappingException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name)); } foreach ($annotation->getGroups() as $group) { $attributeMetadata->addGroup($group); } } elseif ($annotation instanceof MaxDepth) { if (!$accessorOrMutator) { throw new MappingException(sprintf('MaxDepth on "%s::%s" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name)); } $attributeMetadata->setMaxDepth($annotation->getMaxDepth()); } $loaded = true; } } return $loaded; }
/** * {@inheritdoc} */ public function getMethodAnnotations(\ReflectionMethod $method) { $annotations = []; $srcAnnotations = $this->innerReader->getMethodAnnotations($method); foreach ($srcAnnotations as $annotation) { $annotations[] = $this->processMethodAnnotation($annotation); } return $annotations; }
/** * @param \ReflectionMethod $reflectionMethod * * @return AbstractParameter[] */ public function read(\ReflectionMethod $reflectionMethod) { $parameters = []; foreach ($this->annotationReader->getMethodAnnotations($reflectionMethod) as $annotation) { if ($annotation instanceof AbstractParameter) { $parameters[] = $annotation; } } return $parameters; }
/** * @param \ReflectionMethod $method * @return Scope[] */ public function getScopeAnnotationsFromMethod(\ReflectionMethod $method) { $scopeAnnotations = []; $methodAnnotations = $this->annotationReader->getMethodAnnotations($method); foreach ($methodAnnotations as $annotation) { if ($annotation instanceof Scope) { $scopeAnnotations[$annotation->getName()] = $annotation; } } return $scopeAnnotations; }
/** * @param FilterControllerEvent $event * * @throws \Throwable * @throws \TypeError */ public function onKernelController(FilterControllerEvent $event) { $request = $event->getRequest(); $apiValidation = false; if ($request->attributes->has('_api_bag')) { $apiBagClass = $request->attributes->get('_api_bag'); $request->attributes->remove('_api_bag'); } if ($request->attributes->has('_api_validation')) { $apiValidation = (bool) $request->attributes->get('_api_validation'); $request->attributes->remove('_api_validation'); } if ($request->attributes->has('_api_as')) { $apiBagName = $request->attributes->get('_api_as'); $request->attributes->remove('_api_as'); } if (is_array($controller = $event->getController())) { $object = new \ReflectionObject($controller[0]); $method = $object->getMethod($controller[1]); foreach ($this->reader->getMethodAnnotations($method) as $configuration) { if ($configuration instanceof ApiParameters) { if (isset($configuration->bag)) { $apiBagClass = $configuration->bag; } if (isset($configuration->as)) { $apiBagName = $configuration->as; } if (isset($configuration->validation)) { $apiValidation = (bool) $configuration->validation; } } } } if (!empty($apiBagClass)) { $apiParameterBag = class_exists($apiBagClass) ? new $apiBagClass() : new ApiParameterBag(); $apiParameterBag->populateFromRequest($request); $request->attributes->set(isset($apiBagName) ? $apiBagName : 'api_parameters', $apiParameterBag); if ($apiValidation) { $errors = $this->validator->validate($apiParameterBag); if (count($errors) > 0) { $errorsList = array(); $accessor = PropertyAccess::createPropertyAccessor(); foreach ($errors as $error) { $key = preg_replace('/parameters(\\[(.+)\\])+/', '$1', $error->getPropertyPath()); $accessor->setValue($errorsList, $key, $error->getMessage()); } $request->attributes->set('_api_errors', $errorsList); $controller = new ApiErrorController(); $event->setController(array($controller, 'validationErrorsAction')); } } } }
/** * * @param FilterControllerEvent $event */ public function onKernelController(FilterControllerEvent $event) { if (is_array($controller = $event->getController())) { $request = $event->getRequest(); $class = new \ReflectionClass(get_class($controller[0])); $method = $class->getMethod($controller[1]); foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof GroupSecurityInterface) { $this->evaluate($annotation, $request); } } } }
public function onKernelController(FilterControllerEvent $event) { if (!is_array($controller = $event->getController())) { return; } $object = new \ReflectionObject($controller[0]); $method = $object->getMethod($controller[1]); foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof Loggable) { $this->logger->logActivity($event->getRequest(), $annotation, $controller); } } }
/** * @param array|\ReflectionMethod[] $methods * @return array */ protected function getInitMethods(array $methods) { $initMethods = []; foreach ($methods as $method) { $annotations = $this->annotationReader->getMethodAnnotations($method); foreach ($annotations as $annotation) { if ($annotation instanceof Init) { $initMethods[] = ['method' => $method, 'args' => $annotation->args, 'priority' => $annotation->priority]; } } } return $initMethods; }
/** * @param \ReflectionClass $reflectionClass * @return Annotation[] * @throws AnnotationReaderException */ private function readMethodAnnotations(\ReflectionClass $reflectionClass) : array { return array_reduce($reflectionClass->getMethods(), function (array $accumulator, \ReflectionMethod $reflectionMethod) { /* @var $annotations \Doctrine\Common\Annotations\Annotation[] */ $annotations = array_filter($this->reader->getMethodAnnotations($reflectionMethod), function ($annotation) : bool { return $annotation instanceof Annotation; }); if (empty($annotations)) { return $accumulator; } return array_merge($accumulator, $this->processMethodAnnotations($annotations, $reflectionMethod)); }, []); }
/** * 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 */ public function onCoreController(FilterControllerEvent $event) { if (!is_array($controller = $event->getController())) { return; } $object = new \ReflectionObject($controller[0]); $method = $object->getMethod($controller[1]); $request = $event->getRequest(); foreach ($this->reader->getMethodAnnotations($method) as $configuration) { if ($configuration instanceof ConfigurationInterface) { $request->attributes->set('_' . $configuration->getAliasName(), $configuration); } } }
/** * 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); } } }
/** * Verifies the request body if a schema has been defined with @Schema * * @param FilterControllerEvent $event */ public function onKernelController(FilterControllerEvent $event) { $method = $this->getCalledMethod($event); $annotations = $this->annotationReader->getMethodAnnotations($method); $validateAnnotations = array_filter($annotations, function ($annotation) { return $annotation instanceof Schema; }); $data = $event->getRequest()->request->all(); /** @var Schema $validateAnnotation */ foreach ($validateAnnotations as $validateAnnotation) { if (!empty($validateAnnotation->getPathToSchema())) { $this->validate($validateAnnotation, $data); } } }
/** * {@inheritdoc} */ public function getParameterKey(\ReflectionParameter $parameter) { $function = $parameter->getDeclaringFunction(); if ($function instanceof \ReflectionMethod) { foreach ($this->reader->getMethodAnnotations($function) as $annotation) { if ($annotation instanceof Inject) { $value = $annotation->getValue($parameter->getName()); if ($value !== null) { return $value; } } } } return null; }
/** * Parses annotations for a given method, and adds new information to the given ApiDoc * annotation. Useful to extract information from the FOSRestBundle annotations. * * @param ApiDoc $annotation * @param Route $route * @param ReflectionMethod $method */ protected function parseAnnotations(ApiDoc $annotation, Route $route, \ReflectionMethod $method) { $annots = $this->reader->getMethodAnnotations($method); foreach ($this->handlers as $handler) { $handler->handle($annotation, $annots, $route, $method); } }