本文整理匯總了PHP中PhpParser\Node\Stmt::getAttributes方法的典型用法代碼示例。如果您正苦於以下問題:PHP Stmt::getAttributes方法的具體用法?PHP Stmt::getAttributes怎麽用?PHP Stmt::getAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PhpParser\Node\Stmt
的用法示例。
在下文中一共展示了Stmt::getAttributes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parse
/**
* @param Stmt $classStmt
* @param $namespace
* @param $source
* @return Element\ClassModel
*/
public function parse(Stmt $classStmt, $namespace, $source)
{
$attrs = $classStmt->getAttributes();
$class = $this->classFactory->create($classStmt->name);
$class->setNamespace($namespace);
$class->setSource($source, $attrs['startLine'], 0);
// annotation
$this->commentsParser->parse($attrs, $class);
// property
$properties = array_filter($classStmt->stmts, function ($stmt) {
return $this->propertyParser->match($stmt);
});
array_map(function (Stmt $propertiesStmt) use($class) {
$prop = $this->propertyParser->parse($propertiesStmt, $class);
$this->propertyAnnotationParser->parse($propertiesStmt, $prop, $class);
$varAnnotations = $prop->annotations->withName('var');
if (!$varAnnotations->isEmpty()) {
/** @var Element\Annotation $var */
$var = $varAnnotations->first();
$prop->setAccessModifier($var->parameters);
}
}, $properties);
// method
$methods = array_filter($classStmt->stmts, function ($stmt) {
return $this->methodParser->match($stmt);
});
array_map(function ($methodStmt) use($class) {
$this->methodParser->parse($methodStmt, $class);
}, $methods);
return $class;
}
示例2: parse
/**
* @param Stmt $propertyStmt
* @param Element\Property $property
* @param Element\ClassModel $class
* @return Element\Annotation\AnnotationCollection
*/
public function parse(Stmt $propertyStmt, Element\Property $property, Element\ClassModel $class)
{
// annotation
$attrs = $propertyStmt->getAttributes();
$this->commentsParser->parse($attrs, $property);
$vars = $property->annotations->withName('var');
if ($vars->count()) {
/** @var Element\Annotation $var */
$var = $vars->first();
if (!is_array($var->parameters)) {
// classのuseにあるものだけにする(FQCN形式等は要検討)
// 型が単純なクラス名ではなくて Element\Annotation のような形式になっている場合は、Element 部分が use にあればOK
if ($searchAlias = strstr($var->parameters, '\\', true) === false) {
$searchAlias = $var->parameters;
}
$classReferences = $class->references->withAlias($searchAlias);
if ($classReferences->count()) {
$ref = $this->referenceFactory->create($var->parameters, null);
$property->reference = $ref;
}
}
}
return $property->annotations;
}