This commit is contained in:
2021-02-22 18:11:23 +08:00
parent cfc2d98076
commit b06c8e3da1
3 changed files with 12 additions and 27 deletions
+6 -23
View File
@@ -168,6 +168,9 @@ class Container extends BaseObject
$reflection = $this->_reflection[$class];
} else {
$reflection = new ReflectionClass($class);
if (!$reflection->isInstantiable()) {
return [];
}
$this->_reflection[$class] = $reflection;
}
$constructs = $reflection->getConstructor();
@@ -191,37 +194,17 @@ class Container extends BaseObject
/**
* @param $class
* @return mixed
* @return ReflectionClass|null
* @throws ReflectionException
*/
public function getReflect($class): ReflectionClass
public function getReflect($class): ?ReflectionClass
{
if (!isset($this->_reflection[$class])) {
$this->resolveDependencies($class);
}
return $this->_reflection[$class];
return $this->_reflection[$class] ?? null;
}
/**
* @param string $class
* @return array
* @throws ReflectionException
*/
public function getAttributes(string $class): array
{
$reflection = $this->getReflect($class);
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
$classAttribute = $reflection->getAttributes();
foreach ($methods as $method) {
$this->_attributes[$reflection->getName()][$method->getName()] = $method->getAttributes();
}
return $this->_attributes[$reflection->getName()];
}
/**
* @param $class
*/