本文整理汇总了PHP中PHPSA\Context::sytaxError方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::sytaxError方法的具体用法?PHP Context::sytaxError怎么用?PHP Context::sytaxError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPSA\Context
的用法示例。
在下文中一共展示了Context::sytaxError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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>");
}
}
示例2: 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>");
}
}