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


PHP Context::clear方法代碼示例

本文整理匯總了PHP中PHPSA\Context::clear方法的典型用法代碼示例。如果您正苦於以下問題:PHP Context::clear方法的具體用法?PHP Context::clear怎麽用?PHP Context::clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PHPSA\Context的用法示例。


在下文中一共展示了Context::clear方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parserFile

 /**
  * @param string $filepath
  * @param Context $context
  * @throws RuntimeException when filepath is not readable
  */
 public function parserFile($filepath, Context $context)
 {
     $context->setFilepath($filepath);
     try {
         if (!is_readable($filepath)) {
             throw new RuntimeException('File ' . $filepath . ' is not readable');
         }
         $context->debug('<comment>Precompile: ' . $filepath . '.</comment>');
         $code = file_get_contents($filepath);
         $astTree = $this->parser->parse($code);
         $this->nodeTraverser->traverse($astTree);
         $context->aliasManager = new AliasManager();
         $namespace = null;
         /**
          * Step 1 Precompile
          */
         foreach ($astTree as $topStatement) {
             if ($topStatement instanceof Node\Stmt\Namespace_) {
                 /**
                  * Namespace block can be created without NS name
                  */
                 if ($topStatement->name) {
                     $namespace = $topStatement->name->toString();
                     $context->aliasManager->setNamespace($namespace);
                 }
                 if ($topStatement->stmts) {
                     $this->parseTopDefinitions($topStatement->stmts, $context->aliasManager, $filepath);
                 }
             } else {
                 if (is_array($topStatement)) {
                     $this->parseTopDefinitions($topStatement, $context->aliasManager, $filepath);
                 } else {
                     $this->parseTopDefinitions($astTree, $context->aliasManager, $filepath);
                 }
             }
         }
         $context->clear();
     } catch (\PhpParser\Error $e) {
         $context->syntaxError($e, $filepath);
     } catch (Exception $e) {
         $context->output->writeln("<error>{$e->getMessage()}</error>");
     }
 }
開發者ID:ovr,項目名稱:phpsa,代碼行數:48,代碼來源:FileParser.php

示例2: parserFile

 /**
  * @param string $filepath
  * @param Parser $parser
  * @param Context $context
  */
 protected function parserFile($filepath, Parser $parser, Context $context)
 {
     $context->setFilepath($filepath);
     $astTraverser = new \PhpParser\NodeTraverser();
     $astTraverser->addVisitor(new \PhpParser\NodeVisitor\NameResolver());
     try {
         if (!is_readable($filepath)) {
             throw new RuntimeException('File ' . $filepath . ' is not readable');
         }
         $context->debug('<comment>Precompile: ' . $filepath . '.</comment>');
         $code = file_get_contents($filepath);
         $astTree = $parser->parse($code);
         $astTraverser->traverse($astTree);
         $aliasManager = new AliasManager();
         $namespace = null;
         /**
          * Step 1 Precompile
          */
         foreach ($astTree as $topStatement) {
             if ($topStatement instanceof Node\Stmt\Namespace_) {
                 /**
                  * Namespace block can be created without NS name
                  */
                 if ($topStatement->name) {
                     $namespace = $topStatement->name->toString();
                     $aliasManager->setNamespace($namespace);
                 }
                 if ($topStatement->stmts) {
                     $this->parseTopDefinitions($topStatement->stmts, $aliasManager, $filepath);
                 }
             } else {
                 $this->parseTopDefinitions($topStatement, $aliasManager, $filepath);
             }
         }
         /**
          * Another Traverser to handler Analyzer Passe(s)
          */
         $analyzeTraverser = new AstTraverser([new \PHPSA\Node\Visitor\FunctionCall()], $context);
         $analyzeTraverser->traverse($astTree);
         $context->clear();
     } catch (\PhpParser\Error $e) {
         $context->sytaxError($e, $filepath);
     } catch (Exception $e) {
         $context->output->writeln("<error>{$e->getMessage()}</error>");
     }
 }
開發者ID:sekjun9878,項目名稱:phpsa,代碼行數:51,代碼來源:CheckCommand.php

示例3: parserFile

 /**
  * @param string $filepath
  * @param Parser $parser
  * @param Context $context
  */
 protected function parserFile($filepath, Parser $parser, Context $context)
 {
     try {
         if (!is_readable($filepath)) {
             throw new RuntimeException('File ' . $filepath . ' is not readable');
         }
         $code = file_get_contents($filepath);
         $stmts = $parser->parse($code);
         /**
          * Step 1 Precompile
          */
         if ($stmts[0] instanceof Node\Stmt\Namespace_) {
             $stmts = $stmts[0]->stmts;
         }
         foreach ($stmts as $st) {
             if ($st instanceof Node\Stmt\Class_) {
                 $classDefintion = new ClassDefinition($st->name);
                 $classDefintion->setFilepath($filepath);
                 foreach ($st->stmts as $st) {
                     if ($st instanceof Node\Stmt\ClassMethod) {
                         $method = new ClassMethod($st->name, $st->stmts, $st->type, $st);
                         $classDefintion->addMethod($method);
                     } elseif ($st instanceof Node\Stmt\Property) {
                         $classDefintion->addProperty($st);
                     } elseif ($st instanceof Node\Stmt\ClassConst) {
                         $classDefintion->addConst($st);
                     }
                 }
                 $this->classes[] = $classDefintion;
             }
         }
         $context->clear();
     } catch (\PhpParser\Error $e) {
         $context->sytaxError($e, $filepath);
     } catch (Exception $e) {
         $context->output->writeln("<error>{$e->getMessage()}</error>");
     }
 }
開發者ID:necromant2005,項目名稱:phpsa,代碼行數:43,代碼來源:CheckCommand.php


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