本文整理汇总了PHP中PhpParser\PrettyPrinter\Standard::pStmt_Use方法的典型用法代码示例。如果您正苦于以下问题:PHP Standard::pStmt_Use方法的具体用法?PHP Standard::pStmt_Use怎么用?PHP Standard::pStmt_Use使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\PrettyPrinter\Standard
的用法示例。
在下文中一共展示了Standard::pStmt_Use方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: traverseStatements
/**
* Traverses the main PHP file, checks for namespaces, classes, if statements and use statements.
* A chain of responsibility could be used here to get rid of the awful if/else statements.
*
* @param $statements
* @param string $namespaceString
* @returns array $code
*/
protected function traverseStatements($statements, $namespaceString = '')
{
$uses = '';
$code = [];
foreach ($statements as $statement) {
if ($statement instanceof Namespace_) {
$namespaceString = implode('\\', $statement->name->parts);
$nestedCode = $this->traverseStatements($statement->stmts, $namespaceString);
$code = array_merge($code, $nestedCode);
} elseif ($statement instanceof Class_) {
if (empty($namespaceString)) {
$namespaceString = 'tmp';
}
$fileLocation = DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $namespaceString);
$code[$statement->name] = $this->getClass($statement, $namespaceString, $fileLocation, $uses);
} elseif ($statement instanceof If_) {
$nestedCode = $this->traverseStatements($statement->stmts, $namespaceString);
$code = array_merge($code, $nestedCode);
} elseif ($statement instanceof Use_) {
$uses .= $this->prettyPrinter->pStmt_Use($statement) . PHP_EOL;
}
}
return $code;
}