This commit is contained in:
2021-07-21 13:49:55 +08:00
parent 088745109f
commit d7302ceba5
7 changed files with 309 additions and 244 deletions
+22 -7
View File
@@ -7,6 +7,7 @@ namespace Annotation;
use Exception;
use ReflectionException;
use ReflectionProperty;
use Snowflake\Core\Str;
use Snowflake\Snowflake;
/**
@@ -37,16 +38,12 @@ use Snowflake\Snowflake;
public function execute(mixed $class, mixed $method = null): bool
{
$injectValue = $this->parseInjectValue();
if (!($method instanceof ReflectionProperty)) {
$method = Snowflake::getDi()->getClassProperty($class, $method);
if (!$method) {
return false;
}
if (!($method = $this->getProperty($class, $method))) {
return false;
}
/** @var ReflectionProperty $class */
if ($method->isPrivate() || $method->isProtected()) {
$method = 'set' . ucfirst($class->getName());
$method = 'set' . ucfirst(Str::convertUnderline($method->getName()));
if (!method_exists($class, $method)) {
return false;
}
@@ -58,6 +55,24 @@ use Snowflake\Snowflake;
}
/**
* @param $class
* @param $method
* @return ReflectionProperty|bool
*/
private function getProperty($class, $method): ReflectionProperty|bool
{
if ($method instanceof ReflectionProperty) {
return $method;
}
$method = Snowflake::getDi()->getClassProperty($class, $method);
if (!$method) {
return false;
}
return $method;
}
/**
* @return mixed
* @throws Exception