当前位置: 首页>>代码示例>>PHP>>正文


PHP AnnotationReader::getClassAnnotation方法代码示例

本文整理汇总了PHP中Doctrine\Common\Annotations\AnnotationReader::getClassAnnotation方法的典型用法代码示例。如果您正苦于以下问题:PHP AnnotationReader::getClassAnnotation方法的具体用法?PHP AnnotationReader::getClassAnnotation怎么用?PHP AnnotationReader::getClassAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Annotations\AnnotationReader的用法示例。


在下文中一共展示了AnnotationReader::getClassAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: realpath

 /**
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  * @param \Doctrine\Common\Annotations\AnnotationReader $annotationReader
  * @param \FSi\Bundle\AdminBundle\Finder\AdminClassFinder $adminClassFinder
  */
 function it_registers_annotated_admin_classes_as_services($container, $annotationReader, $adminClassFinder)
 {
     $container->getParameter('kernel.bundles')->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\MyBundle', 'FSi\\Bundle\\AdminBundle\\FSiAdminBundle', 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'));
     $baseDir = __DIR__ . '/../../../../../..';
     $adminClassFinder->findClasses(array(realpath($baseDir . '/spec/fixtures/Admin'), realpath($baseDir . '/Admin')))->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement'));
     $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(null);
     $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(new Element(array()));
     $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/spec/fixtures/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled();
     $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled();
     $container->addDefinitions(Argument::that(function ($definitions) {
         if (count($definitions) !== 1) {
             return false;
         }
         /** @var \Symfony\Component\DependencyInjection\Definition $definition */
         $definition = $definitions[0];
         if ($definition->getClass() !== 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement') {
             return false;
         }
         if (!$definition->hasTag('admin.element')) {
             return false;
         }
         return true;
     }))->shouldBeCalled();
     $this->process($container);
 }
开发者ID:kbedn,项目名称:admin-bundle,代码行数:30,代码来源:AdminAnnotatedElementPassSpec.php

示例2: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string        $className
  * @param ClassMetadata $metadata
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $class = $metadata->getReflectionClass();
     if (!$class) {
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($metadata->name);
     }
     $entityAnnot = $this->reader->getClassAnnotation($class, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Entity');
     if (!$entityAnnot) {
         throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
     }
     $metadata->storageName = $entityAnnot->storageName;
     // Evaluate annotations on properties/fields
     foreach ($class->getProperties() as $property) {
         $idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Id');
         $transientAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Transient');
         if ($idAnnot) {
             $metadata->mapIdentifier($property->getName());
         } elseif ($transientAnnot) {
             $metadata->skipTransientField($property->getName());
         } else {
             $metadata->mapField(['fieldName' => $property->getName()]);
         }
     }
 }
开发者ID:nicktacular,项目名称:KeyValueStore,代码行数:32,代码来源:AnnotationDriver.php

示例3: getProperties

 protected function getProperties($object)
 {
     $reflClass = new \ReflectionClass($object);
     $codeAnnotation = $this->annotationReader->getClassAnnotation($reflClass, Segment::class);
     if (!$codeAnnotation) {
         throw new AnnotationMissing(sprintf("Missing @Segment annotation for class %", $reflClass->getName()));
     }
     $properties = [$codeAnnotation->value];
     foreach ($reflClass->getProperties() as $propRefl) {
         $propRefl->setAccessible(true);
         /** @var SegmentPiece $isSegmentPiece */
         $isSegmentPiece = $this->annotationReader->getPropertyAnnotation($propRefl, SegmentPiece::class);
         if ($isSegmentPiece) {
             if (!$isSegmentPiece->parts) {
                 $properties[$isSegmentPiece->position] = $propRefl->getValue($object);
             } else {
                 $parts = $isSegmentPiece->parts;
                 $value = $propRefl->getValue($object);
                 $valuePieces = [];
                 foreach ($parts as $key => $part) {
                     if (is_integer($key)) {
                         $partName = $part;
                     } else {
                         $partName = $key;
                     }
                     $valuePieces[] = isset($value[$partName]) ? $value[$partName] : null;
                 }
                 $properties[$isSegmentPiece->position] = $this->weedOutEmpty($valuePieces);
             }
         }
     }
     $properties = $this->weedOutEmpty($properties);
     return $properties;
 }
开发者ID:progrupa,项目名称:edifact,代码行数:34,代码来源:AnnotationPrinter.php

示例4: orderOf

 public function orderOf(EventListenerInterface $listener)
 {
     $order = $this->reader->getClassAnnotation(new \ReflectionClass($listener), Order::class);
     if (null === $order && $listener instanceof EventListenerProxyInterface) {
         $order = $this->reader->getClassAnnotation(new \ReflectionClass($listener->getTargetType()), Order::class);
     }
     return null === $order ? 0 : $order->value;
 }
开发者ID:fcm,项目名称:GovernorFramework,代码行数:8,代码来源:AnnotationOrderResolver.php

示例5: parseClass

 /**
  * Parse a class.
  *
  * @param array $annotations
  * @return string|null
  */
 public function parseClass($class)
 {
     $reflectionClass = new ReflectionClass($class);
     // check if class is entity
     if ($annotation = $this->reader->getClassAnnotation($reflectionClass, '\\ProAI\\Datamapper\\Annotations\\Presenter')) {
         return $this->parsePresenter($class, $annotation);
     } else {
         return null;
     }
 }
开发者ID:emtudo,项目名称:laravel-datamapper,代码行数:16,代码来源:PresenterScanner.php

示例6: parseClass

 /**
  * Parse a class.
  *
  * @param string $class
  * @return array|null
  */
 public function parseClass($class)
 {
     $reflectionClass = new ReflectionClass($class);
     // check if class is controller
     if ($annotation = $this->reader->getClassAnnotation($reflectionClass, '\\ProAI\\Annotations\\Annotations\\Controller')) {
         return $this->parseController($class);
     } else {
         return null;
     }
 }
开发者ID:proai,项目名称:lumen-annotations,代码行数:16,代码来源:RouteScanner.php

示例7: indexEntity

 /**
  * Start indexing entity for the indexer specific content
  *
  * @param EntityStructure $structure Structure reference
  * @return mixed
  * @throws InvalidAnnotationException
  */
 public function indexEntity(&$structure)
 {
     $table = $this->reader->getClassAnnotation($this->entityClass, Table::class);
     if (!$table instanceof Table) {
         throw new InvalidAnnotationException("Entity '" . $this->entityClass->getName() . "' has no Table entity!");
         // @codeCoverageIgnore
     }
     if ($table->name == null) {
         throw new InvalidAnnotationException("Entity '" . $this->entityClass->getName() . "' is required to have the name parameter in the Table annotation.");
         // @codeCoverageIgnore
     }
     $structure->table = $table;
     $structure->tableName = $table->name;
 }
开发者ID:tomvlk,项目名称:sweet-orm,代码行数:21,代码来源:TableIndexer.php

示例8: parseClass

 /**
  * Parse a class.
  *
  * @param string $class
  * @return array|null
  */
 public function parseClass($class)
 {
     $reflectionClass = new ReflectionClass($class);
     // check if class is controller
     if ($annotation = $this->reader->getClassAnnotation($reflectionClass, '\\ProAI\\Annotations\\Annotations\\Hears')) {
         $class = $annotation->value;
         if (isset($this->config['events_namespace']) && substr($class, 0, strlen($this->config['events_namespace'])) != $this->config['events_namespace']) {
             $class = $this->config['events_namespace'] . '\\' . $class;
         }
         return $class;
     } else {
         return null;
     }
 }
开发者ID:proai,项目名称:lumen-annotations,代码行数:20,代码来源:EventScanner.php

示例9: create

 /**
  * @param $datagridClass
  * @return \Abbert\Datagrid\Datagrid
  * @throws \Exception
  */
 public function create($datagridClass)
 {
     // annotation reader
     $reflection = new \ReflectionClass($datagridClass);
     $reader = new AnnotationReader();
     $annotationDatagrid = $reader->getClassAnnotation($reflection, 'Abbert\\DatagridBundle\\Annotation\\Datagrid');
     // datasource
     $annotation = $reader->getClassAnnotation($reflection, 'Abbert\\DatagridBundle\\Annotation\\DoctrineSource');
     $setDatasource = null;
     if ($annotation !== null && $annotation->entityClass != '') {
         $repo = $this->entityManager->getRepository($annotation->entityClass);
         $setDatasource = new DoctrineSource($repo);
     }
     if (isset($this->serviceIds[$datagridClass])) {
         // service
         $service = $this->container->get($this->serviceIds[$datagridClass]);
         if ($service instanceof \Abbert\Datagrid\Datagrid) {
             $datagrid = clone $service;
         } else {
             $datagrid = new \Abbert\Datagrid\Datagrid();
             $service->create($datagrid);
         }
     } else {
         // normale class, hier worden dependencies ondersteund
         $deps = [];
         if ($annotationDatagrid !== null && count($annotationDatagrid->dependencies)) {
             foreach ($annotationDatagrid->dependencies as $dep) {
                 if (strstr($dep, '@')) {
                     $deps[] = $this->container->get(str_replace('@', '', $dep));
                 } else {
                     if (strstr('%', '', $dep)) {
                         $deps[] = $this->container->getParameter(str_replace('%', '', $dep));
                     }
                 }
             }
         }
         if ($setDatasource !== null) {
             $deps[] = $setDatasource;
         }
         $datagrid = call_user_func_array(array($reflection, 'newInstance'), $deps);
     }
     // configuratie
     $datagrid->setViewPath($this->viewPath);
     if ($setDatasource !== null) {
         $datagrid->setDatasource($setDatasource);
     }
     return $datagrid;
 }
开发者ID:abbert,项目名称:datagrid-bundle,代码行数:53,代码来源:Datagrid.php

示例10: getClassMetadata

 /**
  * @param string $classname
  * @return array
  */
 public function getClassMetadata($classname)
 {
     $classMetadata = [];
     $reflexionClass = $this->getReflectionClass($classname);
     $classAnnotations = $this->reader->getClassAnnotations($reflexionClass);
     foreach ($classAnnotations as $classAnnotation) {
         if (!isset($classMetadata[get_class($classAnnotation)])) {
             $classMetadata[get_class($classAnnotation)] = [];
         }
         $classMetadata[get_class($classAnnotation)][] = $classAnnotation;
     }
     if ($this->reader->getClassAnnotation($reflexionClass, ParentClass::class)) {
         $classMetadata = array_merge_recursive($this->getClassMetadata(get_parent_class($classname)), $classMetadata);
     }
     return $classMetadata;
 }
开发者ID:eoko,项目名称:odm-metadata-annotation,代码行数:20,代码来源:AnnotationDriver.php

示例11: guessType

 /**
  * {@inheritdoc}
  */
 public function guessType($class, $property)
 {
     $metadata = $this->getClassMetadata($class);
     if (!$metadata->hasAssociation($property)) {
         return null;
     }
     $multiple = $metadata->isCollectionValuedAssociation($property);
     $annotationReader = new AnnotationReader();
     $associationMapping = $metadata->getAssociationMapping($property);
     $associationMetadata = $this->getClassMetadata($associationMapping['targetEntity']);
     if (null === $annotationReader->getClassAnnotation($associationMetadata->getReflectionClass(), static::TREE_ANNOTATION)) {
         return null;
     }
     $levelProperty = null;
     $parentProperty = null;
     foreach ($associationMetadata->getReflectionProperties() as $property) {
         if ($annotationReader->getPropertyAnnotation($property, static::TREE_LEVEL_ANNOTATION)) {
             $levelProperty = $property->getName();
         }
         if ($annotationReader->getPropertyAnnotation($property, static::TREE_PARENT_ANNOTATION)) {
             $parentProperty = $property->getName();
         }
     }
     if (null === $levelProperty || null === $parentProperty) {
         return null;
     }
     return new TypeGuess('tree_choice', ['class' => $associationMapping['targetEntity'], 'multiple' => $multiple, 'level_property' => $levelProperty, 'parent_property' => $parentProperty], Guess::VERY_HIGH_CONFIDENCE);
 }
开发者ID:snovichkov,项目名称:TreeChoiceBundle,代码行数:31,代码来源:TreeChoiceTypeGuesser.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // get repository
     $entityClass = $input->getArgument('entityClass');
     $repository = $this->getHelper('em')->getEntityManager()->getRepository($entityClass);
     $reflClass = new ReflectionClass($entityClass);
     $reader = new AnnotationReader();
     $annotation = $reader->getClassAnnotation($reflClass, '\\Keratine\\Lucene\\Mapping\\Annotation\\Indexable');
     if (!$annotation) {
         $output->writeln(sprintf('<error>%s must define the "%s" annotation.</error>', $entityClass, '\\Keratine\\Lucene\\Mapping\\Annotation\\Indexable'));
         return;
     }
     $indexManager = new IndexManager($this->getHelper('zendsearch')->getIndices()[$annotation->index]);
     // delete all indexed documents
     $numDocs = $indexManager->numDocs();
     for ($id = 0; $id < $numDocs; $id++) {
         $indexManager->delete($id);
     }
     // index each entity
     foreach ($repository->findAll() as $entity) {
         $indexManager->index($entity);
     }
     // optimize index
     $indexManager->optimize();
     // get number of indexed documents
     $numDocs = $indexManager->numDocs();
     $output->writeln(sprintf('<info>%d document(s) indexed</info>', $numDocs));
 }
开发者ID:diskojulien,项目名称:keratine,代码行数:28,代码来源:LuceneIndexCommand.php

示例13: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $reader = new AnnotationReader();
     /** @var ManagerRegistry $doctrine */
     $doctrine = $this->getContainer()->get('doctrine');
     $em = $doctrine->getManager();
     $cmf = $em->getMetadataFactory();
     $existing = [];
     $created = [];
     /** @var ClassMetadata $metadata */
     foreach ($cmf->getAllMetadata() as $metadata) {
         $refl = $metadata->getReflectionClass();
         if ($refl === null) {
             $refl = new \ReflectionClass($metadata->getName());
         }
         if ($reader->getClassAnnotation($refl, 'Padam87\\AttributeBundle\\Annotation\\Entity') != null) {
             $schema = $em->getRepository('Padam87AttributeBundle:Schema')->findOneBy(['className' => $metadata->getName()]);
             if ($schema === null) {
                 $schema = new Schema();
                 $schema->setClassName($metadata->getName());
                 $em->persist($schema);
                 $em->flush($schema);
                 $created[] = $metadata->getName();
             } else {
                 $existing[] = $metadata->getName();
             }
         }
     }
     $table = new Table($output);
     $table->addRow(['Created:', implode(PHP_EOL, $created)]);
     $table->addRow(new TableSeparator());
     $table->addRow(['Existing:', implode(PHP_EOL, $existing)]);
     $table->render();
 }
开发者ID:jvahldick,项目名称:AttributeBundle,代码行数:37,代码来源:SyncSchemaCommand.php

示例14: persist

 public function persist($entity)
 {
     $reflection = new \ReflectionClass($entity);
     $originURI = $entity->getOrigin();
     if (!$originURI) {
         throw new \Exception("Cannot persist entity, because origin URI is not defined");
     }
     $sparql = '';
     $annotationReader = new AnnotationReader();
     $iri = $annotationReader->getClassAnnotation($reflection, 'Soil\\DiscoverBundle\\Annotation\\Iri');
     if ($iri) {
         $iri = $iri->value;
         $sparql .= "<{$originURI}> rdf:type {$iri} . " . PHP_EOL;
     }
     $props = $reflection->getProperties();
     foreach ($props as $prop) {
         $matchAnnotation = $annotationReader->getPropertyAnnotation($prop, 'Soil\\DiscoverBundle\\Annotation\\Iri');
         if ($matchAnnotation && $matchAnnotation->persist) {
             $match = $matchAnnotation->value;
             $prop->setAccessible(true);
             $value = $prop->getValue($entity);
             $sparql .= "<{$originURI}> {$match} <{$value}> . " . PHP_EOL;
         }
     }
     if ($sparql) {
         $this->logger->addInfo('Persisting: ');
         $this->logger->addInfo($sparql);
         $num = $this->endpoint->insert($sparql);
         $this->logger->addInfo('Return: ' . print_r($num, true));
         return $num;
     } else {
         return null;
     }
 }
开发者ID:soilby,项目名称:rdf-persistence-bundle,代码行数:34,代码来源:PersistenceService.php

示例15: __construct

 /**
  * Entity Indexer
  * @param string|EntityClass $entityClassName
  *
  * @throws InvalidAnnotationException Invalid annotations used
  */
 public function __construct($entityClassName)
 {
     $this->entityClass = new \ReflectionClass($entityClassName);
     if (!$this->entityClass->isSubclassOf("\\SweetORM\\Entity")) {
         throw new \UnexpectedValueException("The className for getTable should be a class that is extending the SweetORM Entity class");
         // @codeCoverageIgnore
     }
     $this->entity = new EntityStructure();
     $this->entity->name = $this->entityClass->getName();
     // Reader
     $reader = new AnnotationReader();
     $this->classAnnotations = $reader->getClassAnnotations($this->entityClass);
     $this->entityAnnotation = $reader->getClassAnnotation($this->entityClass, EntityClass::class);
     // Validate Entity annotation
     if ($this->entityAnnotation === null || !$this->entityAnnotation instanceof EntityClass) {
         throw new InvalidAnnotationException("Entity '" . $this->entityClass->getName() . "' should use Annotations to use it! Please look at the documentation for help.");
         // @codeCoverageIgnore
     }
     // Run all the indexers
     foreach (self::$indexers as $indexerClass) {
         $indexerFullClass = "\\SweetORM\\Structure\\Indexer\\" . $indexerClass;
         /** @var Indexer $instance */
         $instance = new $indexerFullClass($this->entityClass, $reader);
         $instance->indexEntity($this->entity);
     }
 }
开发者ID:tomvlk,项目名称:sweet-orm,代码行数:32,代码来源:EntityIndexer.php


注:本文中的Doctrine\Common\Annotations\AnnotationReader::getClassAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。