本文整理汇总了PHP中Doctrine\Common\Annotations\Reader::getMethodAnnotations方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::getMethodAnnotations方法的具体用法?PHP Reader::getMethodAnnotations怎么用?PHP Reader::getMethodAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\Reader
的用法示例。
在下文中一共展示了Reader::getMethodAnnotations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collectMethodCacheAnnotations
/**
* @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);
}
示例2: onKernelController
/**
* @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);
}
}
}
示例3: onFilterController
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;
}
}
示例4: load
/** {@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;
}
示例5: loadActions
/**
* {@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;
}
示例6: onKernelController
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;
}
}
}
}
}
示例7: processClass
/**
* @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;
}
示例8: loadMetadataForClass
/**
* 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;
}
示例9: loadForMethod
/**
* {@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;
}
示例10: onKernelController
/**
* 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);
});
}
}
}
}
}
示例11: onConfigureRoute
/**
* 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));
}
}
示例12: create
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());
}
}
示例13: loadMetadataForClass
/**
* @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;
}
示例14: loadClassMetadata
/**
* {@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;
}
示例15: getMethodAnnotations
/**
* 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;
}