This commit is contained in:
as2252258@163.com
2021-05-04 03:45:23 +08:00
parent 9eb660bff8
commit 791f9722f5
+6 -20
View File
@@ -169,7 +169,7 @@ class Loader extends BaseObject
} }
$this->appendFileToDirectory($path->getRealPath(), $replace->getName()); $this->appendFileToDirectory($path->getRealPath(), $replace->getName());
$_array['handler'] = $replace->getName(); $_array['handler'] = $replace->newInstance();
$_array['target'] = []; $_array['target'] = [];
$_array['methods'] = []; $_array['methods'] = [];
$_array['property'] = []; $_array['property'] = [];
@@ -349,38 +349,24 @@ class Loader extends BaseObject
continue; continue;
} }
$class = $this->newInstance($annotations['handler']);
/** @var \Annotation\Attribute $value */ /** @var \Annotation\Attribute $value */
foreach ($annotations['target'] ?? [] as $value) { foreach ($annotations['target'] ?? [] as $value) {
$value->execute($class); $value->execute($annotations['handler']);
} }
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($class::class, $value->name, $name); $annotation->addRelate($className, $value->name, $name);
} else if ($value instanceof Get) { } else if ($value instanceof Get) {
$annotation->addGets($class::class, $value->name, $name); $annotation->addGets($className, $value->name, $name);
} else if ($value instanceof Set) { } else if ($value instanceof Set) {
$annotation->addSets($class::class, $value->name, $name); $annotation->addSets($className, $value->name, $name);
} else { } else {
$value->execute($class, $name); $value->execute($annotations['handler'], $name);
} }
} }
} }
} }
} }
/**
* @param $class
* @return object
* @throws \ReflectionException
* @throws \Snowflake\Exception\NotFindClassException
*/
private function newInstance($class)
{
$reflection = Snowflake::getDi()->getReflect($class);
return $reflection?->newInstance();
}
} }