This commit is contained in:
as2252258@163.com
2021-05-02 04:38:26 +08:00
parent a906ac187c
commit c44fb76b59
+5 -24
View File
@@ -179,7 +179,7 @@ class Loader extends BaseObject
} }
$this->appendFileToDirectory($path->getRealPath(), $replace->getName()); $this->appendFileToDirectory($path->getRealPath(), $replace->getName());
$_array = ['handler' => $replace->getName(), 'target' => [], 'methods' => [], 'property' => []]; $_array = ['handler' => $replace->newInstance(), 'target' => [], 'methods' => [], 'property' => []];
foreach ($replace->getAttributes() as $attribute) { foreach ($replace->getAttributes() as $attribute) {
if ($attribute->getName() == Attribute::class) { if ($attribute->getName() == Attribute::class) {
continue; continue;
@@ -309,21 +309,18 @@ class Loader extends BaseObject
if ($annotations === null) { if ($annotations === null) {
continue; continue;
} }
if (($reflect = $this->getRelect($annotations)) === null) { $class = clone $annotations['handler'];
continue;
}
$class = $reflect->newInstance();
foreach ($annotations['target'] ?? [] as $value) { foreach ($annotations['target'] ?? [] as $value) {
$value->execute([$class]); $value->execute([$class]);
} }
foreach ($annotations['methods'] as $name => $attribute) { foreach ($annotations['methods'] as $name => $attribute) {
foreach ($attribute as $value) { foreach ($attribute as $value) {
if ($value instanceof Relation) { if ($value instanceof Relation) {
$annotation->addRelate($reflect->getName(), $value->name, $name); $annotation->addRelate($class::class, $value->name, $name);
} else if ($value instanceof Get) { } else if ($value instanceof Get) {
$annotation->addGets($reflect->getName(), $value->name, $name); $annotation->addGets($class::class, $value->name, $name);
} else if ($value instanceof Set) { } else if ($value instanceof Set) {
$annotation->addSets($reflect->getName(), $value->name, $name); $annotation->addSets($class::class, $value->name, $name);
} else { } else {
$value->execute([$class, $name]); $value->execute([$class, $name]);
} }
@@ -333,20 +330,4 @@ class Loader extends BaseObject
} }
/**
* @param $annotations
* @return \ReflectionClass|null
* @throws \ReflectionException
* @throws \Snowflake\Exception\NotFindClassException
*/
private function getRelect($annotations)
{
$reflect = Snowflake::getDi()->getReflect($annotations['handler']);
if ($reflect === null) {
return null;
}
return $reflect;
}
} }