diff --git a/src/AnnotationReader.php b/src/AnnotationReader.php index 9cab0df..285225e 100644 --- a/src/AnnotationReader.php +++ b/src/AnnotationReader.php @@ -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' => [], - ]; } } } diff --git a/src/Attribute.php b/src/Attribute.php new file mode 100644 index 0000000..3d0bdd0 --- /dev/null +++ b/src/Attribute.php @@ -0,0 +1,5 @@ +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 = [];