This commit is contained in:
2021-02-22 19:38:44 +08:00
parent 7f20d3aaf1
commit c2a0211517
+28 -28
View File
@@ -4,6 +4,7 @@
namespace Annotation; namespace Annotation;
use Exception;
use ReflectionAttribute; use ReflectionAttribute;
use ReflectionClass; use ReflectionClass;
use ReflectionException; use ReflectionException;
@@ -114,26 +115,29 @@ class Annotation extends Component
* @param string $class * @param string $class
* @param string $alias * @param string $alias
* @return array * @return array
* @throws ReflectionException * @throws Exception
* @throws NotFindPropertyException
* @throws NotFindClassException
*/ */
private function getReflect(string $class, string $alias): array private function getReflect(string $class, string $alias): array
{ {
$reflect = $this->reflectClass($class); try {
var_dump($class, $reflect); $reflect = $this->reflectClass($class);
if (empty($reflect)) { var_dump($class, $reflect);
if (empty($reflect)) {
return [];
}
$constructor = $reflect->getConstructor();
if (!empty($constructor) && count($constructor->getParameters()) > 0) {
return [];
}
$object = $reflect->newInstance();
$this->resolveMethod($reflect, $class, $alias, $object);
return $this->targets($reflect);
} catch (\Throwable $throwable) {
$this->addError($throwable);
return []; return [];
} }
$constructor = $reflect->getConstructor();
if (!empty($constructor) && count($constructor->getParameters()) > 0) {
return [];
}
$object = $reflect->newInstance();
$this->resolveMethod($reflect, $class, $alias, $object);
return $this->targets($reflect);
} }
@@ -146,20 +150,16 @@ class Annotation extends Component
*/ */
private function resolveMethod(ReflectionClass $reflect, $class, $alias, $object) private function resolveMethod(ReflectionClass $reflect, $class, $alias, $object)
{ {
try { foreach ($reflect->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
foreach ($reflect->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($method->class != $class) {
if ($method->class != $class) { continue;
continue;
}
$tmp = $this->resolveAnnotations($method, $alias, $object);
if (empty($tmp)) {
continue;
}
$this->_classes[$reflect->getName()][$method->getName()] = $tmp;
} }
} catch (\Throwable $throwable) {
$this->addError($throwable); $tmp = $this->resolveAnnotations($method, $alias, $object);
if (empty($tmp)) {
continue;
}
$this->_classes[$reflect->getName()][$method->getName()] = $tmp;
} }
$this->resolveProperty($reflect, $object); $this->resolveProperty($reflect, $object);
} }