當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Annotations\AnnotationReader類代碼示例

本文整理匯總了PHP中Doctrine\Common\Annotations\AnnotationReader的典型用法代碼示例。如果您正苦於以下問題:PHP AnnotationReader類的具體用法?PHP AnnotationReader怎麽用?PHP AnnotationReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AnnotationReader類的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: 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

示例3: setUp

 public function setUp()
 {
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setProxyNamespace('Proxies');
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
     $this->dm = DocumentManager::create(new Mongo(), $config);
     $currencies = array('USD' => 1, 'EURO' => 1.7, 'JPN' => 0.0125);
     foreach ($currencies as $name => &$multiplier) {
         $multiplier = new Currency($name, $multiplier);
         $this->dm->persist($multiplier);
     }
     $product = new ConfigurableProduct('T-Shirt');
     $product->addOption(new Option('small', new Money(12.99, $currencies['USD']), new StockItem('T-shirt Size S', new Money(9.99, $currencies['USD']), 15)));
     $product->addOption(new Option('medium', new Money(14.99, $currencies['USD']), new StockItem('T-shirt Size M', new Money(11.99, $currencies['USD']), 15)));
     $product->addOption(new Option('large', new Money(17.99, $currencies['USD']), new StockItem('T-shirt Size L', new Money(13.99, $currencies['USD']), 15)));
     $this->dm->persist($product);
     $this->dm->flush();
     foreach ($currencies as $currency) {
         $this->dm->detach($currency);
     }
     $this->dm->detach($product);
     unset($currencies, $product);
 }
開發者ID:jacques-sounvi,項目名稱:addressbook,代碼行數:26,代碼來源:EcommerceTest.php

示例4: testParseAnnotationDocblocks

 public function testParseAnnotationDocblocks()
 {
     $class = new \ReflectionClass(__NAMESPACE__ . '\\DCOM55Annotation');
     $reader = new AnnotationReader();
     $annots = $reader->getClassAnnotations($class);
     $this->assertEquals(0, count($annots));
 }
開發者ID:eltondias,項目名稱:Relogio,代碼行數:7,代碼來源:DCOM55Test.php

示例5: testPdfAnnotationIsCorrectlyCreatedByReader

 /**
  * @Pdf()
  */
 public function testPdfAnnotationIsCorrectlyCreatedByReader()
 {
     $reader = new AnnotationReader();
     $method = new \ReflectionMethod($this, 'testPdfAnnotationIsCorrectlyCreatedByReader');
     $pdf = $reader->getMethodAnnotation($method, 'Ps\\PdfBundle\\Annotation\\Pdf');
     $this->assertNotNull($pdf);
 }
開發者ID:davidfuhr,項目名稱:PdfBundle,代碼行數:10,代碼來源:PdfTest.php

示例6: 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

示例7: 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

示例8: create

 /**
  * @param string $className
  * @return Datagrid
  */
 public function create($className)
 {
     /** @var \Doctrine\ORM\EntityManager $entityManager */
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $metadata = $entityManager->getClassMetadata($className);
     $reflection = $metadata->getReflectionClass();
     $datagridSpec = new ArrayObject(array('className' => $className, 'primaryKey' => $metadata->getSingleIdentifierFieldName(), 'name' => array('singular' => '', 'plural' => ''), 'defaultSort' => null, 'headerColumns' => array(), 'searchColumns' => array(), 'suggestColumns' => array()));
     $reader = new AnnotationReader();
     foreach ($reader->getClassAnnotations($reflection) as $annotation) {
         $params = compact('datagridSpec', 'annotation');
         $this->getEventManager()->trigger('discoverTitle', $this, $params);
     }
     foreach ($reflection->getProperties() as $property) {
         foreach ($reader->getPropertyAnnotations($property) as $annotation) {
             $params = compact('datagridSpec', 'annotation', 'property');
             $this->getEventManager()->trigger('configureColumn', $this, $params);
         }
     }
     foreach ($reflection->getMethods() as $method) {
         foreach ($reader->getMethodAnnotations($method) as $annotation) {
             $params = compact('datagridSpec', 'annotation', 'method');
             $this->getEventManager()->trigger('configureColumn', $this, $params);
         }
     }
     $this->datagrids[$className] = new Datagrid($entityManager, $datagridSpec->getArrayCopy());
     return $this->datagrids[$className];
 }
開發者ID:PoetikDragon,項目名稱:USCSS,代碼行數:31,代碼來源:DatagridManager.php

示例9: __construct

 public function __construct($consumerWorker, ConnectionFactory $connectionFactory)
 {
     $this->connectionFactory = $connectionFactory;
     $className = get_class($consumerWorker);
     $reflectionClass = new \ReflectionClass($className);
     $reader = new AnnotationReader();
     $methods = $reflectionClass->getMethods();
     foreach ($methods as $method) {
         $methodAnnotations = $reader->getMethodAnnotations($method);
         foreach ($methodAnnotations as $annotation) {
             if ($annotation instanceof Annotation\Consumer) {
                 $parameters = $method->getParameters();
                 $taskClassName = false;
                 if (!empty($parameters)) {
                     $taskClass = $parameters[0]->getClass();
                     $isMessage = $taskClass->implementsInterface('IvixLabs\\RabbitmqBundle\\Message\\MessageInterface');
                     if (!$isMessage) {
                         throw new \InvalidArgumentException('Task must implmenet IvixLabs\\RabbitmqBundle\\Message\\MessageInterface');
                     }
                     $taskClassName = $taskClass->getName();
                 }
                 $key = $annotation->connectionName . '_' . $annotation->channelName . '_' . $annotation->exchangeName . '_' . $annotation->routingKey;
                 if (!isset($this->taskClasses[$key])) {
                     $this->taskClasses[$key] = [];
                 }
                 $this->taskClasses[$key][] = [$taskClassName, $method->getClosure($consumerWorker), $annotation];
             }
         }
     }
 }
開發者ID:IvixLabs,項目名稱:RabbitmqBundle,代碼行數:30,代碼來源:Consumer.php

示例10: setUp

    public function setUp()
    {
        $config = new Configuration();

        $config->setProxyDir(__DIR__ . '/../../../../Proxies');
        $config->setProxyNamespace('Proxies');

        $config->setHydratorDir(__DIR__ . '/../../../../Hydrators');
        $config->setHydratorNamespace('Hydrators');

        $config->setDefaultDB('doctrine_odm_tests');

        /*
        $config->setLoggerCallable(function(array $log) {
            print_r($log);
        });
        $config->setMetadataCacheImpl(new ApcCache());
        */

        $reader = new AnnotationReader();
        $reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\');
        $this->annotationDriver = new AnnotationDriver($reader, __DIR__ . '/../../../../Documents');
        $config->setMetadataDriverImpl($this->annotationDriver);

        $conn = new Connection(null, array(), $config);
        $this->dm = DocumentManager::create($conn, $config);
        $this->uow = $this->dm->getUnitOfWork();
    }
開發者ID:JanJakes,項目名稱:mongodb-odm,代碼行數:28,代碼來源:BaseTest.php

示例11: readExtendedMetadata

 /**
  * (non-PHPdoc)
  * @see Gedmo\Mapping.Driver::readExtendedMetadata()
  */
 public function readExtendedMetadata(ClassMetadataInfo $meta, array &$config)
 {
     require_once __DIR__ . '/../Annotations.php';
     $reader = new AnnotationReader();
     $reader->setAnnotationNamespaceAlias('Gedmo\\Timestampable\\Mapping\\', 'gedmo');
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || $meta->isInheritedAssociation($property->name)) {
             continue;
         }
         if ($timestampable = $reader->getPropertyAnnotation($property, self::ANNOTATION_TIMESTAMPABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw MappingException::fieldMustBeMapped($field, $meta->name);
             }
             if (!$this->_isValidField($meta, $field)) {
                 throw MappingException::notValidFieldType($field, $meta->name);
             }
             if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
                 throw MappingException::triggerTypeInvalid($field, $meta->name);
             }
             if ($timestampable->on == 'change') {
                 if (!isset($timestampable->field) || !isset($timestampable->value)) {
                     throw MappingException::parametersMissing($field, $meta->name);
                 }
                 $field = array('field' => $field, 'trackedField' => $timestampable->field, 'value' => $timestampable->value);
             }
             // properties are unique and mapper checks that, no risk here
             $config[$timestampable->on][] = $field;
         }
     }
 }
開發者ID:jgat2012,項目名稱:hp_oms,代碼行數:37,代碼來源:Annotation.php

示例12: testBasicClassAnnotations

 /**
  * @covers \Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonAnySetter
  */
 public function testBasicClassAnnotations()
 {
     AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Weasel/JsonMarshaller/Config/DoctrineAnnotations/JsonAnySetter.php');
     $annotationReader = new AnnotationReader();
     $got = $annotationReader->getMethodAnnotations(new \ReflectionMethod(__NAMESPACE__ . '\\JsonAnySetterTestVictim', 'basic'));
     $this->assertEquals(array(new JsonAnySetter()), $got);
 }
開發者ID:siad007,項目名稱:php-weasel,代碼行數:10,代碼來源:JsonAnySetterTest.php

示例13: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $model = $input->getArgument('model');
     $seeds = $input->getArgument('seeds');
     $io = new SymfonyStyle($input, $output);
     if (!class_exists($model)) {
         $io->error(array('The model you specified does not exist.', 'You can create a model with the "model:create" command.'));
         return 1;
     }
     $this->dm = $this->createDocumentManager($input->getOption('server'));
     $faker = Faker\Factory::create();
     AnnotationRegistry::registerAutoloadNamespace('Hive\\Annotations', dirname(__FILE__) . '/../../');
     $reflectionClass = new \ReflectionClass($model);
     $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
     $reader = new AnnotationReader();
     for ($i = 0; $i < $seeds; $i++) {
         $instance = new $model();
         foreach ($properties as $property) {
             $name = $property->getName();
             $seed = $reader->getPropertyAnnotation($property, 'Hive\\Annotations\\Seed');
             if ($seed !== null) {
                 $fake = $seed->fake;
                 if (class_exists($fake)) {
                     $instance->{$name} = $this->createFakeReference($fake);
                 } else {
                     $instance->{$name} = $faker->{$seed->fake};
                 }
             }
         }
         $this->dm->persist($instance);
     }
     $this->dm->flush();
     $io->success(array("Created {$seeds} seeds for {$model}"));
 }
開發者ID:100hz,項目名稱:hive-console,代碼行數:37,代碼來源:ModelSeedCommand.php

示例14: 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

示例15: loadMetadataForClass

 public function loadMetadataForClass($className)
 {
     $metadata = new ClassMetadata($className);
     $reflectionClass = new \ReflectionClass($className);
     $reflectionProperties = $reflectionClass->getProperties();
     foreach ($reflectionProperties as $reflectionProperty) {
         $name = $reflectionProperty->getName();
         $pMetadata = new PropertyMetadata($name);
         $annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof Annotations\Expose) {
                 $pMetadata->setExpose((bool) $annotation->value);
             } elseif ($annotation instanceof Annotations\Type) {
                 $pMetadata->setType((string) $annotation->value);
             } elseif ($annotation instanceof Annotations\Groups) {
                 $pMetadata->setGroups($annotation->value);
             } elseif ($annotation instanceof Annotations\SerializedName) {
                 $pMetadata->setSerializedName((string) $annotation->value);
             } elseif ($annotation instanceof Annotations\SinceVersion) {
                 $pMetadata->setSinceVersion((string) $annotation->value);
             } elseif ($annotation instanceof Annotations\UntilVersion) {
                 $pMetadata->setUntilVersion((string) $annotation->value);
             }
         }
         $metadata->addPropertyMetadata($pMetadata);
     }
     return $metadata;
 }
開發者ID:sugatov,項目名稱:simple-serializer,代碼行數:28,代碼來源:AnnotationDriver.php


注:本文中的Doctrine\Common\Annotations\AnnotationReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。