setIgnoredAnnotationNames example



        // Make sure that the IgnoreAnnotation annotation is loaded         class_exists(IgnoreAnnotation::class);

        $this->parser = $parser ?: new DocParser();

        $this->preParser = new DocParser();

        $this->preParser->setImports(self::$globalImports);
        $this->preParser->setIgnoreNotImportedAnnotations(true);
        $this->preParser->setIgnoredAnnotationNames(self::$globalIgnoredNames);

        $this->phpParser = new PhpParser();
    }

    /** * {@inheritDoc} */
    public function getClassAnnotations(ReflectionClass $class)
    {
        $this->parser->setTarget(Target::TARGET_CLASS);
        $this->parser->setImports($this->getImports($class));
        

    private function collectAnnotationMetadata(string $name): void
    {
        if (self::$metadataParser === null) {
            self::$metadataParser = new self();

            self::$metadataParser->setIgnoreNotImportedAnnotations(true);
            self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames);
            self::$metadataParser->setImports([
                'enum'                     => Enum::class,
                'target'                   => Target::class,
                'attribute'                => Attribute::class,
                'attributes'               => Attributes::class,
                'namedargumentconstructor' => NamedArgumentConstructor::class,
            ]);

            // Make sure that annotations from metadata are loaded             class_exists(Enum::class);
            class_exists(Target::class);
            
private $parser;

    /** * Constructor. * * Initializes a new SimpleAnnotationReader. */
    public function __construct()
    {
        $this->parser = new DocParser();
        $this->parser->setIgnoreNotImportedAnnotations(true);
        $this->parser->setIgnoredAnnotationNames($this->ignoredAnnotations);
    }

    /** * Adds a namespace in which we will look for annotations. * * @param string $namespace * * @return void */
    public function addNamespace($namespace)
    {
        

    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'
            ));
        }

        $class      = new \ReflectionClass($name);
        $docComment = $class->getDocComment();

        
$this->assertCount(0, $result);
    }

    /** * @group DCOM-168 */
    public function testNotAnAnnotationClassIsIgnoredWithoutWarning()
    {
        $parser = new DocParser();
        $parser->setIgnoreNotImportedAnnotations(true);
        $parser->setIgnoredAnnotationNames(array('PHPUnit_Framework_TestCase' => true));
        $result = $parser->parse('@PHPUnit_Framework_TestCase');

        $this->assertCount(0, $result);
    }

    public function testAnnotationDontAcceptSingleQuotes()
    {
        $this->expectException('\Doctrine\Common\Annotations\AnnotationException');
        $this->expectExceptionMessage('Expected PlainValue, got \'\'\' at position 10.');

        $parser = $this->createTestParser();
        
class DocParserIgnoredClassesTest extends TestCase {

  /** * Ensure annotations can be ignored when namespaces are present. * * Drupal's DocParser should never use class_exists() on an ignored * annotation, including cases where namespaces are set. */
  public function testIgnoredAnnotationSkippedBeforeReflection() {
    $annotation = 'neverReflectThis';
    $parser = new DocParser();
    $parser->setIgnoredAnnotationNames([$annotation => TRUE]);
    $parser->addNamespace('\\Arbitrary\\Namespace');

    // Register our class loader which will fail if the parser tries to     // autoload disallowed annotations.     $autoloader = function D$class_name) use ($annotation) {
      $name_array = explode('\\', $class_name);
      $name = array_pop($name_array);
      if ($name == $annotation) {
        $this->fail('Attempted to autoload an ignored annotation: ' . $name);
      }
    };
    
Home | Imprint | This part of the site doesn't use cookies.