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


PHP DocParser::setTarget方法代码示例

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


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

示例1: getMethodAnnotations

 /**
  * {@inheritDoc}
  */
 public function getMethodAnnotations(ReflectionMethod $method)
 {
     $class = $method->getDeclaringClass();
     $context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
     $this->parser->setTarget(Target::TARGET_METHOD);
     $this->parser->setImports($this->getMethodImports($method));
     $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
     return $this->parser->parse($method->getDocComment(), $context);
 }
开发者ID:NivalM,项目名称:VacantesJannaMotors,代码行数:12,代码来源:AnnotationReader.php

示例2: collectAnnotationMetadata

 /**
  * Collects parsing metadata for a given annotation class
  *
  * @param string $name The annotation name
  */
 private function collectAnnotationMetadata($name)
 {
     if (self::$metadataParser == null) {
         self::$metadataParser = new self();
         self::$metadataParser->setTarget(Target::TARGET_CLASS);
         self::$metadataParser->setIgnoreNotImportedAnnotations(true);
         self::$metadataParser->setImports(array('target' => 'Doctrine\\Common\\Annotations\\Annotation\\Target', 'attribute' => 'Doctrine\\Common\\Annotations\\Annotation\\Attribute', 'attributes' => 'Doctrine\\Common\\Annotations\\Annotation\\Attributes'));
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Target.php');
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attribute.php');
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attributes.php');
     }
     $class = new \ReflectionClass($name);
     $docComment = $class->getDocComment();
     // Sets default values for annotation metadata
     $metadata = array('default_property' => null, 'has_constructor' => null !== ($constructor = $class->getConstructor()) && $constructor->getNumberOfParameters() > 0, 'properties' => array(), 'property_types' => array(), 'attribute_types' => array(), 'targets_literal' => null, 'targets' => Target::TARGET_ALL, 'is_annotation' => false !== strpos($docComment, '@Annotation'));
     // verify that the class is really meant to be an annotation
     if ($metadata['is_annotation']) {
         foreach (self::$metadataParser->parse($docComment, 'class @' . $name) as $annotation) {
             if ($annotation instanceof Target) {
                 $metadata['targets'] = $annotation->targets;
                 $metadata['targets_literal'] = $annotation->literal;
             } elseif ($annotation instanceof Attributes) {
                 foreach ($annotation->value as $attrib) {
                     // handle internal type declaration
                     $type = isset(self::$typeMap[$attrib->type]) ? self::$typeMap[$attrib->type] : $attrib->type;
                     // handle the case if the property type is mixed
                     if ('mixed' !== $type) {
                         // Checks if the property has array<type>
                         if (false !== ($pos = strpos($type, '<'))) {
                             $arrayType = substr($type, $pos + 1, -1);
                             $type = 'array';
                             if (isset(self::$typeMap[$arrayType])) {
                                 $arrayType = self::$typeMap[$arrayType];
                             }
                             $metadata['attribute_types'][$attrib->name]['array_type'] = $arrayType;
                         }
                         $metadata['attribute_types'][$attrib->name]['type'] = $type;
                         $metadata['attribute_types'][$attrib->name]['value'] = $attrib->type;
                         $metadata['attribute_types'][$attrib->name]['required'] = $attrib->required;
                     }
                 }
             }
         }
         // if not has a constructor will inject values into public properties
         if (false === $metadata['has_constructor']) {
             // collect all public properties
             foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
                 $metadata['properties'][$property->name] = $property->name;
                 // checks if the property has @var annotation
                 if (false !== ($propertyComment = $property->getDocComment()) && false !== strpos($propertyComment, '@var') && preg_match('/@var\\s+([^\\s]+)/', $propertyComment, $matches)) {
                     // literal type declaration
                     $value = $matches[1];
                     // handle internal type declaration
                     $type = isset(self::$typeMap[$value]) ? self::$typeMap[$value] : $value;
                     // handle the case if the property type is mixed
                     if ('mixed' !== $type) {
                         // Checks if the property has @var array<type> annotation
                         if (false !== ($pos = strpos($type, '<'))) {
                             $arrayType = substr($type, $pos + 1, -1);
                             $type = 'array';
                             if (isset(self::$typeMap[$arrayType])) {
                                 $arrayType = self::$typeMap[$arrayType];
                             }
                             $metadata['attribute_types'][$property->name]['array_type'] = $arrayType;
                         }
                         $metadata['attribute_types'][$property->name]['type'] = $type;
                         $metadata['attribute_types'][$property->name]['value'] = $value;
                         $metadata['attribute_types'][$property->name]['required'] = false !== strpos($propertyComment, '@Required');
                     }
                 }
             }
             // choose the first property as default property
             $metadata['default_property'] = reset($metadata['properties']);
         }
     }
     self::$annotationMetadata[$name] = $metadata;
 }
开发者ID:laiello,项目名称:masfletes,代码行数:82,代码来源:DocParser.php

示例3: collectAnnotationMetadata

 /**
  * Collects parsing metadata for a given annotation class
  *
  * @param string $name The annotation name
  *
  * @return void
  */
 private function collectAnnotationMetadata($name)
 {
     if (self::$metadataParser === null) {
         self::$metadataParser = new self();
         self::$metadataParser->setIgnoreNotImportedAnnotations(true);
         self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames);
         self::$metadataParser->setImports(array('enum' => 'Doctrine\\Common\\Annotations\\Annotation\\Enum', 'target' => 'Doctrine\\Common\\Annotations\\Annotation\\Target', 'attribute' => 'Doctrine\\Common\\Annotations\\Annotation\\Attribute', 'attributes' => 'Doctrine\\Common\\Annotations\\Annotation\\Attributes'));
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Enum.php');
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Target.php');
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attribute.php');
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attributes.php');
     }
     $class = new \ReflectionClass($name);
     $docComment = $class->getDocComment();
     // Sets default values for annotation metadata
     $metadata = array('default_property' => null, 'has_constructor' => null !== ($constructor = $class->getConstructor()) && $constructor->getNumberOfParameters() > 0, 'properties' => array(), 'property_types' => array(), 'attribute_types' => array(), 'targets_literal' => null, 'targets' => Target::TARGET_ALL, 'is_annotation' => false !== strpos($docComment, '@Annotation'));
     // verify that the class is really meant to be an annotation
     if ($metadata['is_annotation']) {
         self::$metadataParser->setTarget(Target::TARGET_CLASS);
         foreach (self::$metadataParser->parse($docComment, 'class @' . $name) as $annotation) {
             if ($annotation instanceof Target) {
                 $metadata['targets'] = $annotation->targets;
                 $metadata['targets_literal'] = $annotation->literal;
                 continue;
             }
             if ($annotation instanceof Attributes) {
                 foreach ($annotation->value as $attribute) {
                     $this->collectAttributeTypeMetadata($metadata, $attribute);
                 }
             }
         }
         // if not has a constructor will inject values into public properties
         if (false === $metadata['has_constructor']) {
             // collect all public properties
             foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
                 $metadata['properties'][$property->name] = $property->name;
                 if (false === ($propertyComment = $property->getDocComment())) {
                     continue;
                 }
                 $attribute = new Attribute();
                 $attribute->required = false !== strpos($propertyComment, '@Required');
                 $attribute->name = $property->name;
                 $attribute->type = false !== strpos($propertyComment, '@var') && preg_match('/@var\\s+([^\\s]+)/', $propertyComment, $matches) ? $matches[1] : 'mixed';
                 $this->collectAttributeTypeMetadata($metadata, $attribute);
                 // checks if the property has @Enum
                 if (false !== strpos($propertyComment, '@Enum')) {
                     $context = 'property ' . $class->name . "::\$" . $property->name;
                     self::$metadataParser->setTarget(Target::TARGET_PROPERTY);
                     foreach (self::$metadataParser->parse($propertyComment, $context) as $annotation) {
                         if (!$annotation instanceof Enum) {
                             continue;
                         }
                         $metadata['enum'][$property->name]['value'] = $annotation->value;
                         $metadata['enum'][$property->name]['literal'] = !empty($annotation->literal) ? $annotation->literal : $annotation->value;
                     }
                 }
             }
             // choose the first property as default property
             $metadata['default_property'] = reset($metadata['properties']);
         }
     }
     self::$annotationMetadata[$name] = $metadata;
 }
开发者ID:hilmysyarif,项目名称:l4-bootstrap-admin,代码行数:70,代码来源:DocParser.php

示例4: testAnnotationTarget

 public function testAnnotationTarget()
 {
     $parser = new DocParser();
     $parser->setImports(array('__NAMESPACE__' => 'Doctrine\\Tests\\Common\\Annotations\\Fixtures'));
     $class = new \ReflectionClass('Doctrine\\Tests\\Common\\Annotations\\Fixtures\\ClassWithValidAnnotationTarget');
     $context = 'class ' . $class->getName();
     $docComment = $class->getDocComment();
     $parser->setTarget(Target::TARGET_CLASS);
     $this->assertNotNull($parser->parse($docComment, $context));
     $property = $class->getProperty('foo');
     $docComment = $property->getDocComment();
     $context = 'property ' . $class->getName() . "::\$" . $property->getName();
     $parser->setTarget(Target::TARGET_PROPERTY);
     $this->assertNotNull($parser->parse($docComment, $context));
     $method = $class->getMethod('someFunction');
     $docComment = $property->getDocComment();
     $context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
     $parser->setTarget(Target::TARGET_METHOD);
     $this->assertNotNull($parser->parse($docComment, $context));
     try {
         $class = new \ReflectionClass('Doctrine\\Tests\\Common\\Annotations\\Fixtures\\ClassWithInvalidAnnotationTargetAtClass');
         $context = 'class ' . $class->getName();
         $docComment = $class->getDocComment();
         $parser->setTarget(Target::TARGET_CLASS);
         $parser->parse($class->getDocComment(), $context);
         $this->fail();
     } catch (\Doctrine\Common\Annotations\AnnotationException $exc) {
         $this->assertNotNull($exc->getMessage());
     }
     try {
         $class = new \ReflectionClass('Doctrine\\Tests\\Common\\Annotations\\Fixtures\\ClassWithInvalidAnnotationTargetAtMethod');
         $method = $class->getMethod('functionName');
         $docComment = $method->getDocComment();
         $context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
         $parser->setTarget(Target::TARGET_METHOD);
         $parser->parse($docComment, $context);
         $this->fail();
     } catch (\Doctrine\Common\Annotations\AnnotationException $exc) {
         $this->assertNotNull($exc->getMessage());
     }
     try {
         $class = new \ReflectionClass('Doctrine\\Tests\\Common\\Annotations\\Fixtures\\ClassWithInvalidAnnotationTargetAtProperty');
         $property = $class->getProperty('foo');
         $docComment = $property->getDocComment();
         $context = 'property ' . $class->getName() . "::\$" . $property->getName();
         $parser->setTarget(Target::TARGET_PROPERTY);
         $parser->parse($docComment, $context);
         $this->fail();
     } catch (\Doctrine\Common\Annotations\AnnotationException $exc) {
         $this->assertNotNull($exc->getMessage());
     }
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:52,代码来源:DocParserTest.php

示例5: getPropertyAnnotations

 /**
  * Gets the annotations applied to a property.
  *
  * @param ReflectionProperty $property The ReflectionProperty of the property
  *                                     from which the annotations should be read.
  * @return array An array of Annotations.
  */
 public function getPropertyAnnotations(\ReflectionProperty $property)
 {
     $this->parser->setTarget(Target::TARGET_PROPERTY);
     return $this->parser->parse($property->getDocComment(), 'property ' . $property->getDeclaringClass()->name . '::$' . $property->getName());
 }
开发者ID:alejofix,项目名称:Gape,代码行数:12,代码来源:SimpleAnnotationReader.php


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