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


PHP Annotations\DocParser类代码示例

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


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

示例1: getDocParser

 protected final function getDocParser()
 {
     $docParser = new DocParser();
     $docParser->setImports(array('desc' => 'JMS\\TranslationBundle\\Annotation\\Desc', 'meaning' => 'JMS\\TranslationBundle\\Annotation\\Meaning', 'ignore' => 'JMS\\TranslationBundle\\Annotation\\Ignore'));
     $docParser->setIgnoreNotImportedAnnotations(true);
     return $docParser;
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:7,代码来源:BasePhpFileExtractorTest.php

示例2: testIssueWithNamespacesOrImports

 public function testIssueWithNamespacesOrImports()
 {
     $docblock = "@Entity";
     $parser = new DocParser();
     $annots = $parser->parse($docblock);
     $this->assertEquals(1, count($annots));
     $this->assertInstanceOf("Entity", $annots[0]);
     $this->assertEquals(1, count($annots));
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:9,代码来源:DCOM58Test.php

示例3: extract

 private function extract($directory)
 {
     $twig = new \Twig_Environment();
     $twig->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator(new MessageSelector())));
     $twig->addExtension(new TranslationExtension($translator));
     $docParser = new DocParser();
     $docParser->setImports(array('desc' => 'JMS\\TranslationBundle\\Annotation\\Desc', 'meaning' => 'JMS\\TranslationBundle\\Annotation\\Meaning', 'ignore' => 'JMS\\TranslationBundle\\Annotation\\Ignore'));
     $docParser->setIgnoreNotImportedAnnotations(true);
     $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
     $extractor = new FileExtractor($twig, new NullLogger(), array(new DefaultPhpFileExtractor($docParser), new TranslationContainerExtractor(), new TwigFileExtractor($twig), new ValidationExtractor($factory), new FormExtractor($docParser)));
     $extractor->setDirectory($directory);
     return $extractor->extract();
 }
开发者ID:nikic,项目名称:JMSTranslationBundle,代码行数:13,代码来源:FileExtractorTest.php

示例4: scanForAnnotations

 public function scanForAnnotations(string $docBlock, $context, array $imports) : Annotations
 {
     // Hack to ensure an attempt to autoload an annotation class is made
     AnnotationRegistry::registerLoader(function ($class) {
         return (bool) class_exists($class);
     });
     $imports = array_combine(array_map(function ($string) {
         return strtolower($string);
     }, array_keys($imports)), array_values($imports));
     $parser = new DocParser();
     $parser->setIgnoreNotImportedAnnotations(true);
     $parser->setImports($imports);
     return new Annotations($parser->parse($docBlock, $context));
 }
开发者ID:dkplus,项目名称:reflections,代码行数:14,代码来源:AnnotationScanner.php

示例5: getAnnotationReader

 /**
  * @return AnnotationReader
  */
 public static function getAnnotationReader()
 {
     if (self::$annotationReader !== null) {
         return self::$annotationReader;
     }
     //For old AnnotationReader (<=1.2.7)
     //For new (>1.2.7) version of AnnotationReader, we can give a DocParser since a3c2928912eeb5dc5678352f22c378173def16b6
     $parser = new DocParser();
     $parser->setIgnoreNotImportedAnnotations(true);
     self::$annotationReader = new AnnotationReader($parser);
     //For old version of AnnotationReader (<=1.2.7) , we have to specify manually all ignored annotations
     foreach (self::$ignoredAnnotationNames as $ignoredAnnotationName) {
         self::$annotationReader->addGlobalIgnoredName($ignoredAnnotationName);
     }
     return self::$annotationReader;
 }
开发者ID:nikoms,项目名称:phpunit-arrange,代码行数:19,代码来源:AnnotationReaderFactory.php

示例6: extract

 private function extract($file, FormExtractor $extractor = null)
 {
     if (!is_file($file = __DIR__ . '/Fixture/' . $file)) {
         throw new RuntimeException(sprintf('The file "%s" does not exist.', $file));
     }
     $file = new \SplFileInfo($file);
     if (null === $extractor) {
         $docParser = new DocParser();
         $docParser->setImports(array('desc' => 'JMS\\TranslationBundle\\Annotation\\Desc', 'meaning' => 'JMS\\TranslationBundle\\Annotation\\Meaning', 'ignore' => 'JMS\\TranslationBundle\\Annotation\\Ignore'));
         $docParser->setIgnoreNotImportedAnnotations(true);
         $extractor = new FormExtractor($docParser);
     }
     $lexer = new \PHPParser_Lexer(file_get_contents($file));
     $parser = new \PHPParser_Parser();
     $ast = $parser->parse($lexer);
     $catalogue = new MessageCatalogue();
     $extractor->visitPhpFile($file, $catalogue, $ast);
     return $catalogue;
 }
开发者ID:nikic,项目名称:JMSTranslationBundle,代码行数:19,代码来源:FormExtractorTest.php

示例7: testDocParsePerformance

 /**
  * @group performance
  */
 public function testDocParsePerformance()
 {
     $imports = array('ignorephpdoc' => 'Annotations\\Annotation\\IgnorePhpDoc', 'ignoreannotation' => 'Annotations\\Annotation\\IgnoreAnnotation', 'route' => 'Doctrine\\Tests\\Common\\Annotations\\Fixtures\\Annotation\\Route', 'template' => 'Doctrine\\Tests\\Common\\Annotations\\Fixtures\\Annotation\\Template', '__NAMESPACE__' => 'Doctrine\\Tests\\Common\\Annotations\\Fixtures');
     $ignored = array('access', 'author', 'copyright', 'deprecated', 'example', 'ignore', 'internal', 'link', 'see', 'since', 'tutorial', 'version', 'package', 'subpackage', 'name', 'global', 'param', 'return', 'staticvar', 'static', 'var', 'throws', 'inheritdoc');
     $parser = new DocParser();
     $method = $this->getMethod();
     $methodComment = $method->getDocComment();
     $classComment = $method->getDeclaringClass()->getDocComment();
     $time = microtime(true);
     for ($i = 0, $c = 200; $i < $c; $i++) {
         $parser = new DocParser();
         $parser->setImports($imports);
         $parser->setIgnoredAnnotationNames($ignored);
         $parser->parse($methodComment);
         $parser->parse($classComment);
     }
     $time = microtime(true) - $time;
     $this->printResults('doc-parser', $time, $c);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:22,代码来源:PerformanceTest.php

示例8: extract

 private function extract($directory)
 {
     $twig = new \Twig_Environment();
     $twig->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator(new MessageSelector())));
     $twig->addExtension(new TranslationExtension($translator));
     $loader = new \Twig_Loader_Filesystem(realpath(__DIR__ . "/Fixture/SimpleTest/Resources/views/"));
     $twig->setLoader($loader);
     $docParser = new DocParser();
     $docParser->setImports(array('desc' => 'JMS\\TranslationBundle\\Annotation\\Desc', 'meaning' => 'JMS\\TranslationBundle\\Annotation\\Meaning', 'ignore' => 'JMS\\TranslationBundle\\Annotation\\Ignore'));
     $docParser->setIgnoreNotImportedAnnotations(true);
     //use correct factory class depending on whether using Symfony 2 or 3
     if (class_exists('Symfony\\Component\\Validator\\Mapping\\Factory\\LazyLoadingMetadataFactory')) {
         $metadataFactoryClass = 'Symfony\\Component\\Validator\\Mapping\\Factory\\LazyLoadingMetadataFactory';
     } else {
         $metadataFactoryClass = 'Symfony\\Component\\Validator\\Mapping\\ClassMetadataFactory';
     }
     $factory = new $metadataFactoryClass(new AnnotationLoader(new AnnotationReader()));
     $extractor = new FileExtractor($twig, new NullLogger(), array(new DefaultPhpFileExtractor($docParser), new TranslationContainerExtractor(), new TwigFileExtractor($twig), new ValidationExtractor($factory), new FormExtractor($docParser)));
     $extractor->setDirectory($directory);
     return $extractor->extract();
 }
开发者ID:AntoineLemaire,项目名称:JMSTranslationBundle,代码行数:21,代码来源:FileExtractorTest.php

示例9: register

 public function register(Application $app)
 {
     $app['translation-extractor.logger'] = $app->share(function (Application $app) {
         return $app['monolog'];
     });
     $app['translation-extractor.doc-parser'] = $app->share(function () {
         $parser = new DocParser();
         $parser->addNamespace("JMS\\TranslationBundle\\Annotation");
         return $parser;
     });
     $app['translation-extractor.node-visitors'] = $app->share(function (Application $app) {
         return [new ConstraintExtractor($app), new ValidationExtractor($app['validator']->getMetadataFactory()), new DefaultPhpFileExtractor($app['translation-extractor.doc-parser']), new TwigFileExtractor($app['twig']), new FormExtractor($app['translation-extractor.doc-parser']), new HelpMessageExtractor($app['translation-extractor.doc-parser'])];
     });
     $app['translation-extractor.file-extractor'] = $app->share(function (Application $app) {
         return new FileExtractor($app['twig'], $app['translation-extractor.logger'], $app['translation-extractor.node-visitors']);
     });
     $app['translation-extractor.extractor-manager'] = $app->share(function (Application $app) {
         return new ExtractorManager($app['translation-extractor.file-extractor'], $app['translation-extractor.logger']);
     });
     $app['translation-extractor.writer'] = $app->share(function (Application $app) {
         return new FileWriter($app['translation-extractor.writers']);
     });
     $app['translation-extractor.writers'] = $app->share(function () {
         return ['po' => new SymfonyDumperAdapter(new PoFileDumper(), 'po'), 'xlf' => new XliffDumper()];
     });
     $app['translation-extractor.loader-manager'] = $app->share(function (Application $app) {
         return new LoaderManager($app['translation-extractor.loaders']);
     });
     $app['translation-extractor.loaders'] = $app->share(function () {
         return ['po' => new SymfonyLoaderAdapter(new PoFileLoader()), 'xlf' => new XliffLoader()];
     });
     $app['translation-extractor.updater'] = $app->share(function (Application $app) {
         AnnotationRegistry::registerAutoloadNamespace('JMS\\TranslationBundle\\Annotation', $app['root.path'] . '/vendor/jms/translation-bundle');
         return new Updater($app['translation-extractor.loader-manager'], $app['translation-extractor.extractor-manager'], $app['translation-extractor.logger'], $app['translation-extractor.writer']);
     });
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:36,代码来源:TranslationExtractorServiceProvider.php

示例10: setUp

 protected function setUp()
 {
     $docParser = new DocParser();
     $docParser->setImports(array('desc' => 'JMS\\TranslationBundle\\Annotation\\Desc', 'meaning' => 'JMS\\TranslationBundle\\Annotation\\Meaning', 'ignore' => 'JMS\\TranslationBundle\\Annotation\\Ignore'));
     $docParser->setIgnoreNotImportedAnnotations(true);
     $this->extractor = new FormExtractor($docParser);
 }
开发者ID:willstorm,项目名称:cms,代码行数:7,代码来源:FormExtractorTest.php

示例11: processDocComment

 /**
  * Dispatch annotations found in phpDoc with context given in second argument.
  *
  * @param string     $phpDoc     phpDoc
  * @param mixed      $context    context
  */
 private function processDocComment($phpDoc, $context = null)
 {
     $annotations = $this->docParser->parse($phpDoc);
     foreach ($annotations as $annotation) {
         $this->collection->dispatch(Events::TOKEN_PHP_ANNOTATION, new Context\PHP\Annotation($annotation, $context), $this->result);
     }
 }
开发者ID:korchasa,项目名称:dokapi,代码行数:13,代码来源:PHPFileProcessor.php

示例12: enterNode

 /**
  * @param Node $node
  * @return void
  */
 public function enterNode(Node $node)
 {
     if (!$node instanceof Node\Expr\MethodCall || !is_string($node->name) || !in_array(strtolower($node->name), array_map('strtolower', array_keys($this->methodsToExtractFrom)))) {
         $this->previousNode = $node;
         return;
     }
     $ignore = false;
     $desc = $meaning = null;
     if (null !== ($docComment = $this->getDocCommentForNode($node))) {
         if ($docComment instanceof Doc) {
             $docComment = $docComment->getText();
         }
         foreach ($this->docParser->parse($docComment, 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) {
             if ($annot instanceof Ignore) {
                 $ignore = true;
             } elseif ($annot instanceof Desc) {
                 $desc = $annot->text;
             } elseif ($annot instanceof Meaning) {
                 $meaning = $annot->text;
             }
         }
     }
     if (!$node->args[0]->value instanceof String_) {
         if ($ignore) {
             return;
         }
         $message = sprintf('Can only extract the translation id from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine());
         if ($this->logger) {
             $this->logger->error($message);
             return;
         }
         throw new RuntimeException($message);
     }
     $id = $node->args[0]->value->value;
     $index = $this->methodsToExtractFrom[strtolower($node->name)];
     if (isset($node->args[$index])) {
         if (!$node->args[$index]->value instanceof String_) {
             if ($ignore) {
                 return;
             }
             $message = sprintf('Can only extract the translation domain from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine());
             if ($this->logger) {
                 $this->logger->error($message);
                 return;
             }
             throw new RuntimeException($message);
         }
         $domain = $node->args[$index]->value->value;
     } else {
         $domain = 'messages';
     }
     $message = new Message($id, $domain);
     $message->setDesc($desc);
     $message->setMeaning($meaning);
     $message->addSource($this->fileSourceFactory->create($this->file, $node->getLine()));
     $this->catalogue->add($message);
 }
开发者ID:kazak,项目名称:forum,代码行数:61,代码来源:DefaultPhpFileExtractor.php

示例13: 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:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:12,代码来源:AnnotationReader.php

示例14: parseItem

 /**
  * @param $item
  * @param null $domain
  */
 private function parseItem($item, $domain = null)
 {
     // get doc comment
     $ignore = false;
     $desc = $meaning = $docComment = null;
     if ($item->key) {
         $docComment = $item->key->getDocComment();
     }
     if (!$docComment) {
         $docComment = $item->value->getDocComment();
     }
     $docComment = is_object($docComment) ? $docComment->getText() : null;
     if ($docComment) {
         if ($docComment instanceof Doc) {
             $docComment = $docComment->getText();
         }
         foreach ($this->docParser->parse($docComment, 'file ' . $this->file . ' near line ' . $item->value->getLine()) as $annot) {
             if ($annot instanceof Ignore) {
                 $ignore = true;
             } elseif ($annot instanceof Desc) {
                 $desc = $annot->text;
             } elseif ($annot instanceof Meaning) {
                 $meaning = $annot->text;
             }
         }
     }
     // check if the value is explicitly set to false => e.g. for FormField that should be rendered without label
     $ignore = $ignore || !$item->value instanceof Node\Scalar\String_ || $item->value->value == false;
     if (!$item->value instanceof Node\Scalar\String_ && !$item->value instanceof Node\Scalar\LNumber) {
         if ($ignore) {
             return;
         }
         $message = sprintf('Unable to extract translation id for form label/title/placeholder from non-string values, but got "%s" in %s on line %d. Please refactor your code to pass a string, or add "/** @Ignore */".', get_class($item->value), $this->file, $item->value->getLine());
         if ($this->logger) {
             $this->logger->error($message);
             return;
         }
         throw new RuntimeException($message);
     }
     if ($domain === false) {
         // Don't translate when domain is `false`
         return;
     }
     $source = $this->fileSourceFactory->create($this->file, $item->value->getLine());
     $id = $item->value->value;
     if (null === $domain) {
         $this->defaultDomainMessages[] = array('id' => $id, 'source' => $source, 'desc' => $desc, 'meaning' => $meaning);
     } else {
         $this->addToCatalogue($id, $source, $domain, $desc, $meaning);
     }
 }
开发者ID:php-community,项目名称:JMSTranslationBundle,代码行数:55,代码来源:FormExtractor.php

示例15: fromComment

 /**
  * Use doctrine to parse the comment block and return the detected annotations.
  *
  * @param string $comment a T_DOC_COMMENT.
  * @param Context $context
  * @return array Annotations
  */
 public function fromComment($comment, $context = null)
 {
     if ($context === null) {
         $context = new Context(['comment' => $comment]);
     } else {
         $context->comment = $comment;
     }
     try {
         self::$context = $context;
         if ($context->is('annotations') === false) {
             $context->annotations = [];
         }
         $comment = preg_replace_callback('/^[\\t ]*\\*[\\t ]+/m', function ($match) {
             // Replace leading tabs with spaces.
             // Workaround for http://www.doctrine-project.org/jira/browse/DCOM-255
             return str_replace("\t", ' ', $match[0]);
         }, $comment);
         $annotations = $this->docParser->parse($comment, $context);
         self::$context = null;
         return $annotations;
     } catch (Exception $e) {
         self::$context = null;
         if (preg_match('/^(.+) at position ([0-9]+) in ' . preg_quote($context, '/') . '\\.$/', $e->getMessage(), $matches)) {
             $errorMessage = $matches[1];
             $errorPos = $matches[2];
             $atPos = strpos($comment, '@');
             $context->line += substr_count($comment, "\n", 0, $atPos + $errorPos);
             $lines = explode("\n", substr($comment, $atPos, $errorPos));
             $context->character = strlen(array_pop($lines)) + 1;
             // position starts at 0 character starts at 1
             Logger::warning(new Exception($errorMessage . ' in ' . $context, $e->getCode(), $e));
         } else {
             Logger::warning($e);
         }
         return [];
     }
 }
开发者ID:rexzor,项目名称:swagger-php,代码行数:44,代码来源:Analyser.php


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