- Added native Attribute support from PHP 8
This commit is contained in:
parent
2a45abae27
commit
f4fffbd480
|
@ -36,37 +36,47 @@ class AnnotationReader
|
|||
|
||||
protected function parseDocComment(Reflector $reflect)
|
||||
{
|
||||
$namespace = $this->getObjectNamespace($reflect);
|
||||
$tags = [];
|
||||
|
||||
foreach(preg_split("/\r\n|\n|\r/", $reflect->getDocComment()) as $line) {
|
||||
$line = ltrim($line, "* \t\/");
|
||||
$line = rtrim($line, "\t ");
|
||||
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);
|
||||
|
||||
if ( substr($line, 0, 1) === '@' ) {
|
||||
$line = ltrim($line, '@');
|
||||
foreach (preg_split("/\r\n|\n|\r/", $reflect->getDocComment()) as $line) {
|
||||
$line = ltrim($line, "* \t\/");
|
||||
$line = rtrim($line, "\t ");
|
||||
|
||||
$open = strpos($line, "(");
|
||||
$close = strrpos($line, ")");
|
||||
if (substr($line, 0, 1) === '@') {
|
||||
$line = ltrim($line, '@');
|
||||
|
||||
if ( ! in_array(false, [ $open, $close ], true) && ( ++$open !== $close ) ) {
|
||||
$arguments = substr($line, $open, $close - $open);
|
||||
$open = strpos($line, "(");
|
||||
$close = strrpos($line, ")");
|
||||
|
||||
try {
|
||||
if (!in_array(false, [$open, $close], true) && (++$open !== $close)) {
|
||||
$arguments = substr($line, $open, $close - $open);
|
||||
|
||||
try {
|
||||
$tags[] = [
|
||||
'tag' => substr($line, 0, $open - 1),
|
||||
'arguments' => eval("namespace $namespace; return [ $arguments ];"),
|
||||
];
|
||||
} catch (\Throwable $error) {
|
||||
throw new \InvalidArgumentException("An error occured while parsing annotation from '" . $this->getObjectName($reflect) . "' : @$line -- " . $error->getMessage());
|
||||
}
|
||||
} else {
|
||||
$tags[] = [
|
||||
'tag' => substr($line, 0, $open - 1),
|
||||
'arguments' => eval("namespace $namespace; return [ $arguments ];"),
|
||||
'tag' => $line,
|
||||
'arguments' => [],
|
||||
];
|
||||
}
|
||||
catch(\Throwable $error) {
|
||||
throw new \InvalidArgumentException("An error occured while parsing annotation from '" . $this->getObjectName($reflect) . "' : @$line -- " . $error->getMessage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tags[] = [
|
||||
'tag' => $line,
|
||||
'arguments' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Notes;
|
||||
|
||||
interface Attribute {}
|
|
@ -79,9 +79,9 @@ class ObjectReflection {
|
|||
}
|
||||
|
||||
public function gatherProperties(bool $full = true, int $filter =
|
||||
ReflectionProperty::IS_PUBLIC |
|
||||
ReflectionProperty::IS_PROTECTED |
|
||||
ReflectionProperty::IS_PRIVATE
|
||||
ReflectionProperty::IS_PUBLIC |
|
||||
ReflectionProperty::IS_PROTECTED |
|
||||
ReflectionProperty::IS_PRIVATE
|
||||
) : array
|
||||
{
|
||||
$defaultValues = $this->classReflection->getDefaultProperties();
|
||||
|
@ -123,10 +123,10 @@ class ObjectReflection {
|
|||
}
|
||||
|
||||
public function gatherMethods(bool $full = true, int $filter =
|
||||
ReflectionMethod::IS_PUBLIC |
|
||||
ReflectionMethod::IS_PROTECTED |
|
||||
ReflectionMethod::IS_PRIVATE |
|
||||
ReflectionMethod::IS_STATIC
|
||||
ReflectionMethod::IS_PUBLIC |
|
||||
ReflectionMethod::IS_PROTECTED |
|
||||
ReflectionMethod::IS_PRIVATE |
|
||||
ReflectionMethod::IS_STATIC
|
||||
) : array
|
||||
{
|
||||
$list = [];
|
||||
|
|
Loading…
Reference in New Issue