PHPSA\Context::clear PHP Méthode

clear() public méthode

Resets context to beginning stage.
public clear ( )
    public function clear()
    {
        $this->symbols = [];
        $this->scope = null;
        $this->scopePointer = null;
        $this->currentBranch = null;
        $this->aliasManager = null;
        $this->initGlobals();
    }

Usage Example

Exemple #1
0
 /**
  * @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>");
     }
 }
All Usage Examples Of PHPSA\Context::clear