From 68dd8a185caf6b2790afbbff23a2c78a4cb40df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 19 Jan 2021 19:28:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Annotation/Annotation.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Annotation/Annotation.php b/Annotation/Annotation.php index 1243a870..a5de04f0 100644 --- a/Annotation/Annotation.php +++ b/Annotation/Annotation.php @@ -153,7 +153,11 @@ class Annotation extends Component $names = []; foreach ($attributes as $attribute) { - $names[$attribute->getName()] = $this->instance($attribute); + $class = $this->instance($attribute); + if ($class === null) { + continue; + } + $names[$attribute->getName()] = $class; } $tmp['handler'] = [$object, $method->getName()]; @@ -203,7 +207,11 @@ class Annotation extends Component $this->_targets[$name] = []; } foreach ($attributes as $attribute) { - $this->_targets[$name][] = $this->instance($attribute); + $class = $this->instance($attribute); + if ($class === null) { + continue; + } + $this->_targets[$name][] = $class; } } return []; @@ -212,12 +220,13 @@ class Annotation extends Component /** * @param ReflectionAttribute $attribute - * @return array|object + * @return array|object|null */ - private function instance(ReflectionAttribute $attribute): array|object + private function instance(ReflectionAttribute $attribute): array|object|null { - var_dump($attribute->getName()); - var_dump($attribute->getTarget()); + if (!class_exists($attribute->getName())) { + return null; + } return $attribute->newInstance(); }