本文整理汇总了PHP中Doctrine\Common\Annotations\Reader::getClassAnnotations方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::getClassAnnotations方法的具体用法?PHP Reader::getClassAnnotations怎么用?PHP Reader::getClassAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\Reader
的用法示例。
在下文中一共展示了Reader::getClassAnnotations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
}
}
}
}
示例3: loadForClass
/**
* {@inheritDoc}
*/
public function loadForClass($class, $group)
{
$reflectionClass = Reflection::loadClassReflection($class);
$classAnnotations = $this->reader->getClassAnnotations($reflectionClass);
$securityClassAnnotation = null;
$rules = array();
foreach ($classAnnotations as $classAnnotation) {
if ($classAnnotation instanceof ClassSecurityAnnotation && $group == $classAnnotation->group) {
if ($securityClassAnnotation) {
throw new \RuntimeException(sprintf('The @ClassSecurity annotation already defined in class "%s".', $reflectionClass->getName()));
}
$securityClassAnnotation = $classAnnotation;
}
if ($rule = $this->transformAnnotationToRule($classAnnotation, $group, $class)) {
$rules[] = $rule;
}
}
if (!$securityClassAnnotation && !count($rules)) {
return null;
}
if ($securityClassAnnotation) {
$strategy = $securityClassAnnotation->strategy;
} else {
$strategy = Security::STRATEGY_AFFIRMATIVE;
}
$securityClass = new ClassSecurity($reflectionClass->getName(), $strategy, $rules, $group);
return $securityClass;
}
示例4: onPostSerialize
public function onPostSerialize(ObjectEvent $event)
{
/**
* @var JsonSerializationVisitor $visitor
*/
$visitor = $event->getVisitor();
$object = $event->getObject();
$annotations = $this->annotationReader->getClassAnnotations(new \ReflectionObject($object));
$links = array();
foreach ($annotations as $annotation) {
if ($annotation instanceof Link) {
if ($annotation->url) {
$uri = $this->evaluate($annotation->url, $object);
} else {
$uri = $this->router->generate($annotation->route, $this->resolveParams($annotation->params, $object));
}
// allow a blank URI to be an optional link
if ($uri) {
$links[$annotation->name] = $uri;
}
}
}
if ($links) {
$visitor->addData('_links', $links);
}
}
示例5: 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));
}
}
示例6: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass(\ReflectionClass $class)
{
$annotations = $this->reader->getClassAnnotations($class);
if (0 === count($annotations)) {
return null;
}
$classMetadata = new ClassMetadata($class->getName());
$classMetadata->fileResources[] = $class->getFileName();
foreach ($annotations as $annotation) {
if ($annotation instanceof Annotation\Resource) {
// auto transform type from class name
if (!$annotation->type) {
$annotation->type = String::dasherize($class->getShortName());
}
$classMetadata->setResource(new Resource($annotation->type, $annotation->showLinkSelf));
}
}
$classProperties = $class->getProperties();
foreach ($classProperties as $property) {
$annotations = $this->reader->getPropertyAnnotations($property);
foreach ($annotations as $annotation) {
if ($annotation instanceof Annotation\Id) {
$classMetadata->setIdField($property->getName());
} else {
if ($annotation instanceof Annotation\Relationship) {
$classMetadata->addRelationship(new Relationship($property->getName(), $annotation->includeByDefault, $annotation->showLinkSelf, $annotation->showLinkRelated));
}
}
}
}
return $classMetadata;
}
示例7: 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;
}
}
示例8: getClassAnnotations
/**
* Get Annotations for class
*
* @param \ReflectionClass $class
* @return array
*/
public function getClassAnnotations(\ReflectionClass $class)
{
$annotations = array();
foreach ($this->delegate->getClassAnnotations($class) as $annot) {
$annotations[get_class($annot)] = $annot;
}
return $annotations;
}
示例9: isClassInjected
/**
* {@inheritdoc}
*/
public function isClassInjected(\ReflectionClass $class)
{
foreach ($this->reader->getClassAnnotations($class) as $annotation) {
if ($annotation instanceof Inject) {
return true;
}
}
return false;
}
示例10: getTransformAnnotations
/**
* Annotations specifically related to Entity Transformation as defined in the TransformMapping class
*
* @param $class
* @return null | TransformMapping
*/
public function getTransformAnnotations($class)
{
$annotations = $this->reader->getClassAnnotations(new \ReflectionClass($class));
foreach ($annotations as $annotation) {
if ($annotation instanceof TransformMapping) {
return $annotation;
}
}
return null;
}
示例11: isTracked
/**
* Get the annotation from a class or null if it doesn't exists.
*
* @param EntityManagerInterface $em
* @param mixed $entity
* @return bool
*/
public function isTracked(EntityManagerInterface $em, $entity)
{
$class = get_class($entity);
$annotations = $this->reader->getClassAnnotations($em->getClassMetadata($class)->getReflectionClass());
foreach ($annotations as $annotation) {
if ($annotation instanceof Tracked) {
return true;
}
}
return false;
}
示例12: getObjectMappingAnnotation
/**
* Get object mapping annotation for class
*
* @param \ReflectionClass $refClass
* @param string $group
*
* @return Object|null
*/
private function getObjectMappingAnnotation(\ReflectionClass $refClass, $group)
{
$classAnnotations = $this->reader->getClassAnnotations($refClass);
foreach ($classAnnotations as $classAnnotation) {
if ($classAnnotation instanceof Object) {
if ($classAnnotation->group == $group) {
return $classAnnotation;
}
}
}
return null;
}
示例13: getClassAnnotations
/**
* {@inheritDoc}
*/
public function getClassAnnotations(\ReflectionClass $class)
{
$cacheKey = $class->getName();
if (isset($this->loadedAnnotations[$cacheKey])) {
return $this->loadedAnnotations[$cacheKey];
}
if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
$annots = $this->delegate->getClassAnnotations($class);
$this->saveToCache($cacheKey, $annots);
}
return $this->loadedAnnotations[$cacheKey] = $annots;
}
示例14: getProxyAnnotations
/**
* Annotations specifically related to Entity Transformation as defined in the Proxy class
*
* @param $class
* @return null | Proxy
*/
public function getProxyAnnotations($class)
{
if ($this->doctrineProxyResolver->isDoctrineProxy($class)) {
$class = $this->doctrineProxyResolver->unwrapDoctrineProxyClass($class);
}
$annotations = $this->reader->getClassAnnotations(new \ReflectionClass($class));
foreach ($annotations as $annotation) {
if ($annotation instanceof Proxy) {
return $annotation;
}
}
return null;
}
示例15: onKernelController
/**
* 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;
}
$object = new \ReflectionObject($controller[0]);
$method = $object->getMethod($controller[1]);
$request = $event->getRequest();
foreach (array_merge($this->reader->getClassAnnotations($object), $this->reader->getMethodAnnotations($method)) as $configuration) {
if ($configuration instanceof ConfigurationInterface) {
$request->attributes->set('_' . $configuration->getAliasName(), $configuration);
}
}
}