本文整理汇总了PHP中Doctrine\Common\Annotations\Reader::getClassAnnotation方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::getClassAnnotation方法的具体用法?PHP Reader::getClassAnnotation怎么用?PHP Reader::getClassAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\Reader
的用法示例。
在下文中一共展示了Reader::getClassAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass(\ReflectionClass $class)
{
$actionMetadata = new ActionMetadata($class->name);
$actionMetadata->fileResources[] = $class->getFilename();
$actionAnnotation = $this->reader->getClassAnnotation($class, Action::class);
/** @var Action $actionAnnotation */
if ($actionAnnotation !== null) {
$actionMetadata->isAction = true;
$actionMetadata->serviceId = $actionAnnotation->serviceId ?: null;
$actionMetadata->alias = $actionAnnotation->alias ?: null;
} else {
return null;
}
/** @var Security $securityAnnotation */
$securityAnnotation = $this->reader->getClassAnnotation($class, Security::class);
if ($securityAnnotation) {
$actionMetadata->authorizationExpression = $securityAnnotation->expression;
}
$methodCount = 0;
foreach ($class->getMethods() as $method) {
if (!$method->isPublic()) {
continue;
}
$methodMetadata = $this->loadMetadataForMethod($class, $method);
if ($methodMetadata) {
$actionMetadata->addMethodMetadata($methodMetadata);
$methodCount++;
}
}
if ($methodCount < 1) {
return null;
}
return $actionMetadata;
}
示例2: 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
*
* @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);
}
示例3: readUploadable
/**
* Attempts to read the uploadable annotation.
*
* @param \ReflectionClass $class The reflection class.
* @return null|\Iphp\FileStoreBundle\Annotation\Uploadable The annotation.
*/
public function readUploadable(\ReflectionClass $class)
{
$baseClassName = $className = $class->getNamespaceName() . '\\' . $class->getName();
do {
if (isset($this->uploadedClass[$className])) {
if ($baseClassName != $className) {
$this->uploadedClass[$baseClassName] = $this->uploadedClass[$className];
}
return $this->uploadedClass[$baseClassName];
}
$annotation = $this->reader->getClassAnnotation($class, 'Iphp\\FileStoreBundle\\Mapping\\Annotation\\Uploadable');
if ($annotation) {
$this->uploadedClass[$baseClassName] = $annotation;
if ($baseClassName != $className) {
$this->uploadedClass[$className] = $annotation;
}
return $annotation;
}
$class = $class->getParentClass();
if ($class) {
$className = $class->getNamespaceName() . '\\' . $class->getName();
}
} while ($class);
return $annotation;
}
示例4: loadMetadataForClass
/**
* @param \ReflectionClass $class
*
* @return \Metadata\ClassMetadata
*/
public function loadMetadataForClass(\ReflectionClass $class)
{
$metadata = new ClassMetadata($class->getName());
// Resource annotation
$annotation = $this->reader->getClassAnnotation($class, 'Conjecto\\Nemrod\\ResourceManager\\Annotation\\Resource');
if (null !== $annotation) {
$types = $annotation->types;
$pattern = $annotation->uriPattern;
if (!is_array($types)) {
$types = array($types);
}
$metadata->types = $types;
$metadata->uriPattern = $pattern;
}
foreach ($class->getProperties() as $reflectionProperty) {
$propMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName());
// Property annotation
$annotation = $this->reader->getPropertyAnnotation($reflectionProperty, 'Conjecto\\Nemrod\\ResourceManager\\Annotation\\Property');
if (null !== $annotation) {
$propMetadata->value = $annotation->value;
$propMetadata->cascade = $annotation->cascade;
}
$metadata->addPropertyMetadata($propMetadata);
}
return $metadata;
}
示例5: 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;
}
示例6: checkBadWords
/**
* @param LifecycleEventArgs $args
* @return bool
* @throws \Exception
*/
public function checkBadWords(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if (!$entity instanceof BadWordDetectorInterface) {
return true;
}
$badWords = $args->getEntityManager()->getRepository('RenowazeBundle:BadWord')->findAll();
/** @var BadWordDetector $annotationParams */
$annotationParams = $this->reader->getClassAnnotation(new \ReflectionClass($entity), 'RenowazeBundle\\Annotation\\BadWordDetector');
foreach ($annotationParams->fields as $field) {
$methodName = 'get' . ucfirst($field);
if (!method_exists($entity, $methodName)) {
throw new \Exception(sprintf('Field "%s" not found in entity "%s"', $methodName, get_class($entity)));
}
/** @var BadWord $badWord */
foreach ($badWords as $badWord) {
if (strpos($entity->{$methodName}(), $badWord->getWord()) !== false) {
$entity->setHasBadWords(true);
return true;
}
}
}
$entity->setHasBadWords(false);
return true;
}
示例7: load
/**
* 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());
}
}
}
}
}
}
}
示例8: onKernelController
/**
* 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));
}
}
示例9: getGeographicalAnnotation
/**
* Gets the Geograhpical annotation for the specified object.
*
* @param object $obj The object
* @return Geographical The geographical annotation
*/
public function getGeographicalAnnotation($obj)
{
if (!is_object($obj)) {
throw new \InvalidArgumentException();
}
$refClass = new \ReflectionClass($obj);
return $this->reader->getClassAnnotation($refClass, 'Vich\\GeographicalBundle\\Annotation\\Geographical');
}
示例10: checkSegmentCode
/**
* @param \ReflectionClass $classRefl
* @param string $segmentCode
* @throws IncorrectSegmentId
*/
protected function checkSegmentCode($classRefl, $segmentCode)
{
if ($segmentAnnotation = $this->annotationReader->getClassAnnotation($classRefl, Segment::class)) {
if ($segmentCode != $segmentAnnotation->value) {
throw new IncorrectSegmentId(sprintf("Expected %s segment, %s found", $segmentAnnotation->value, $segmentCode));
}
}
}
示例11: isProtectedByCsrfDoubleSubmit
/**
* @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;
}
示例12: create
/**
* @param string $nodeEntityClass
* @param string $property
*
* @return \GraphAware\Neo4j\OGM\Metadata\NodeAnnotationMetadata
*/
public function create($nodeEntityClass)
{
$reflectionClass = new \ReflectionClass($nodeEntityClass);
/** @var Node $annotation */
$annotation = $this->reader->getClassAnnotation($reflectionClass, Node::class);
if (null !== $annotation) {
return new NodeAnnotationMetadata($annotation->label, $annotation->repository);
}
throw new MappingException(sprintf('The class "%s" is missing the "%s" annotation', $nodeEntityClass, Node::class));
}
示例13: getEntityTransformer
/**
* @param $entityClass
* @return TransformerAbstract|null
*/
protected function getEntityTransformer($entityClass)
{
$reflectionClass = new \ReflectionClass($entityClass);
/** @var FractalTransformer $annotation */
$annotation = $this->annotationReader->getClassAnnotation($reflectionClass, FractalTransformer::class);
if (is_null($annotation)) {
return null;
}
$transformerClass = $annotation->value;
return new $transformerClass();
}
示例14: loadClassMetadata
/**
* @inheritdoc
*/
public function loadClassMetadata(\ReflectionClass $class)
{
if (null !== ($resource = $this->reader->getClassAnnotation($class, ApiResource::class))) {
return $this->loadResourceMetadata($resource, $class);
} elseif (null !== ($document = $this->reader->getClassAnnotation($class, ApiDocument::class))) {
return $this->loadDocumentMetadata($document, $class);
} else {
$object = $this->reader->getClassAnnotation($class, ApiObject::class);
return $this->loadObjectMetadata($class, $object);
}
}
示例15: onKernelController
/**
* This event will fire during any controller call
*/
public function onKernelController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
}
$class = new \ReflectionClass(get_class($controller[0]));
// get controller
if (!empty($this->reader->getClassAnnotation($class, self::STATE_LESS_ANNOTATION))) {
$this->handleAuthenticated($class);
}
}