- Added native Attribute support from PHP 8
This commit is contained in:
parent
2a45abae27
commit
f4fffbd480
|
@ -36,9 +36,20 @@ class AnnotationReader
|
||||||
|
|
||||||
protected function parseDocComment(Reflector $reflect)
|
protected function parseDocComment(Reflector $reflect)
|
||||||
{
|
{
|
||||||
$namespace = $this->getObjectNamespace($reflect);
|
|
||||||
$tags = [];
|
$tags = [];
|
||||||
|
|
||||||
|
if ( $reflect->getAttributes() ) {
|
||||||
|
foreach($reflect->getAttributes() as $attr) {
|
||||||
|
$tags[] = [
|
||||||
|
'tag' => substr(strrchr($attr->getName(), "\\"), 1),
|
||||||
|
'arguments' => $attr->getArguments(),
|
||||||
|
'object' => $attr->newInstance(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$namespace = $this->getObjectNamespace($reflect);
|
||||||
|
|
||||||
foreach (preg_split("/\r\n|\n|\r/", $reflect->getDocComment()) as $line) {
|
foreach (preg_split("/\r\n|\n|\r/", $reflect->getDocComment()) as $line) {
|
||||||
$line = ltrim($line, "* \t\/");
|
$line = ltrim($line, "* \t\/");
|
||||||
$line = rtrim($line, "\t ");
|
$line = rtrim($line, "\t ");
|
||||||
|
@ -57,12 +68,10 @@ class AnnotationReader
|
||||||
'tag' => substr($line, 0, $open - 1),
|
'tag' => substr($line, 0, $open - 1),
|
||||||
'arguments' => eval("namespace $namespace; return [ $arguments ];"),
|
'arguments' => eval("namespace $namespace; return [ $arguments ];"),
|
||||||
];
|
];
|
||||||
}
|
} catch (\Throwable $error) {
|
||||||
catch(\Throwable $error) {
|
|
||||||
throw new \InvalidArgumentException("An error occured while parsing annotation from '" . $this->getObjectName($reflect) . "' : @$line -- " . $error->getMessage());
|
throw new \InvalidArgumentException("An error occured while parsing annotation from '" . $this->getObjectName($reflect) . "' : @$line -- " . $error->getMessage());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$tags[] = [
|
$tags[] = [
|
||||||
'tag' => $line,
|
'tag' => $line,
|
||||||
'arguments' => [],
|
'arguments' => [],
|
||||||
|
@ -70,6 +79,7 @@ class AnnotationReader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Notes;
|
||||||
|
|
||||||
|
interface Attribute {}
|
Loading…
Reference in New Issue