• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Annotations\AnnotationReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了AnnotationReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: setUp

 public function setUp()
 {
     if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0RC4-DEV', '>=')) {
         $this->markTestSkipped('Doctrine common is 2.1.0RC4-DEV version, skipping.');
     } else {
         if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
             $reader = new AnnotationReader();
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
             $reader->setIgnoreNotImportedAnnotations(true);
             $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
             $reader->setEnableParsePhpImports(false);
             $reader->setAutoloadAnnotations(true);
             $reader = new CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache());
         } else {
             $reader = new AnnotationReader();
             $reader->setAutoloadAnnotations(true);
             $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
         }
     }
     $config = new \Doctrine\ORM\Configuration();
     $config->setProxyDir(TESTS_TEMP_DIR);
     $config->setProxyNamespace('Gedmo\\Mapping\\Proxy');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader));
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $evm = new \Doctrine\Common\EventManager();
     $this->timestampable = new \Gedmo\Timestampable\TimestampableListener();
     $evm->addEventSubscriber($this->timestampable);
     $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($this->em->getClassMetadata(self::ARTICLE)));
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:34,代码来源:CompatibilityMappingTest.php


示例16: getContentFiles

 public function getContentFiles($object)
 {
     $reflectedClass = new \ReflectionClass($object);
     $reader = new AnnotationReader();
     $annotations = $reader->getClassAnnotations($reflectedClass);
     $isContentFiledClass = false;
     foreach ($annotations as $annotation) {
         if ($annotation instanceof ContentFiled) {
             $isContentFiledClass = true;
         }
     }
     if (!$isContentFiledClass) {
         throw new \InvalidArgumentException('Only @ContentFiled annotated classes are supported!');
     }
     $contentFiles = [];
     foreach ($reflectedClass->getProperties() as $property) {
         foreach ($reader->getPropertyAnnotations($property) as $annotation) {
             if ($annotation instanceof ContentFileAnnotation) {
                 $mappingType = $object->{$annotation->mappingTypeMethod}();
                 $contentFiles = array_merge($contentFiles, $this->contentFileManager->findFilesByMappingType($mappingType));
             }
         }
     }
     return $contentFiles;
 }
开发者ID:scigroup,项目名称:tinyuplmngr,代码行数:25,代码来源:ContentFiledManager.php


示例17: readExtendedMetadata

 public function readExtendedMetadata($meta, array &$config)
 {
     // load our available annotations
     require_once __DIR__ . '/../Annotations.php';
     $reader = new AnnotationReader();
     // set annotation namespace and alias
     //$reader->setAnnotationNamespaceAlias('Gedmo\Mapping\Mock\Extension\Encoder\Mapping\\', 'ext');
     $class = $meta->getReflectionClass();
     // check only property annotations
     foreach ($class->getProperties() as $property) {
         // skip inherited properties
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // now lets check if property has our annotation
         if ($encode = $reader->getPropertyAnnotation($property, 'Gedmo\\Mapping\\Mock\\Extension\\Encoder\\Mapping\\Encode')) {
             $field = $property->getName();
             // check if field is mapped
             if (!$meta->hasField($field)) {
                 throw new \Exception("Field is not mapped as object property");
             }
             // allow encoding only strings
             if (!in_array($encode->type, array('sha1', 'md5'))) {
                 throw new \Exception("Invalid encoding type supplied");
             }
             // validate encoding type
             $mapping = $meta->getFieldMapping($field);
             if ($mapping['type'] != 'string') {
                 throw new \Exception("Only strings can be encoded");
             }
             // store the metadata
             $config['encode'][$field] = array('type' => $encode->type, 'secret' => $encode->secret);
         }
     }
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:35,代码来源:Annotation.php


示例18: getTemplateDataForModel

 protected function getTemplateDataForModel($model)
 {
     $data = ['name' => Helper::get()->shortName($model), 'slug' => Helper::get()->slugify($model), 'properties' => []];
     $reflectionClass = new \ReflectionClass($model);
     $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
     $reader = new AnnotationReader();
     foreach ($properties as $property) {
         $name = $property->getName();
         $type = null;
         $targetEntity = null;
         $mappedBySlug = null;
         $propertyDefinition = ['name' => $name];
         if (($fieldAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Field')) !== null) {
             $type = $fieldAnnotation->type;
         } elseif (($referenceOneAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceOne')) !== null) {
             $name .= '.id';
             $type = 'reference';
             $targetEntity = Helper::get()->shortName($referenceOneAnnotation->targetDocument);
         } elseif (($referenceManyAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceMany')) !== null) {
             $type = 'referenced_list';
             $targetEntity = Helper::get()->shortName($referenceManyAnnotation->targetDocument);
             $mappedBySlug = Helper::get()->slugify($referenceManyAnnotation->mappedBy, false);
         } elseif ($reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Id') === null) {
             continue;
         }
         $propertyDefinition['name'] = $name;
         $propertyDefinition['type'] = $type;
         if ($targetEntity) {
             $propertyDefinition[$type] = ['targetEntity' => $targetEntity, 'targetEntitySlug' => Helper::get()->slugify($targetEntity), 'mappedBySlug' => $mappedBySlug];
         }
         $data['properties'][] = $propertyDefinition;
     }
     return $data;
 }
开发者ID:100hz,项目名称:hive-console,代码行数:34,代码来源:ScaffoldUICommand.php


示例19: testAnnotationReader

 public function testAnnotationReader()
 {
     $reader = new AnnotationReader();
     $method = new \ReflectionMethod('FOS\\RestBundle\\Tests\\Fixtures\\Controller\\ParamsAnnotatedController', 'getArticlesAction');
     $params = $reader->getMethodAnnotations($method);
     // Param 1 (query)
     $this->assertEquals('page', $params[0]->name);
     $this->assertEquals('\\d+', $params[0]->requirements);
     $this->assertEquals('1', $params[0]->default);
     $this->assertEquals('Page of the overview.', $params[0]->description);
     $this->assertFalse($params[0]->map);
     $this->assertFalse($params[0]->strict);
     // Param 2 (request)
     $this->assertEquals('byauthor', $params[1]->name);
     $this->assertEquals('[a-z]+', $params[1]->requirements);
     $this->assertEquals('by author', $params[1]->description);
     $this->assertEquals(['search'], $params[1]->incompatibles);
     $this->assertFalse($params[1]->map);
     $this->assertTrue($params[1]->strict);
     // Param 3 (query)
     $this->assertEquals('filters', $params[2]->name);
     $this->assertTrue($params[2]->map);
     $this->assertEquals(new NotNull(), $params[2]->requirements);
     // Param 4 (file)
     $this->assertEquals('avatar', $params[3]->name);
     $this->assertEquals(['mimeTypes' => 'application/json'], $params[3]->requirements);
     $this->assertTrue($params[3]->image);
     $this->assertTrue($params[3]->strict);
     // Param 5 (file)
     $this->assertEquals('foo', $params[4]->name);
     $this->assertEquals(new NotNull(), $params[4]->requirements);
     $this->assertFalse($params[4]->image);
     $this->assertFalse($params[4]->strict);
 }
开发者ID:francescolaffi,项目名称:FOSRestBundle,代码行数:34,代码来源:ParamReaderTest.php


示例20: __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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Annotations\AnnotationRegistry类代码示例发布时间:2022-05-23
下一篇:
PHP Common\EventManager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap