10 Commits

Author SHA1 Message Date
as2252258 9e954135f6 eee 2025-07-11 15:55:15 +08:00
as2252258 7de790d65f eee 2025-07-11 15:32:33 +08:00
as2252258 855da03137 eee 2025-07-11 15:28:10 +08:00
as2252258 0081a30f22 eee 2025-07-11 15:25:06 +08:00
as2252258 3f2d3b0f04 eee 2025-07-11 15:22:52 +08:00
as2252258 5fa5646024 eee 2025-07-11 15:11:27 +08:00
as2252258 045c9293d5 eee 2025-07-11 11:51:05 +08:00
as2252258 6ae7f5a721 eee 2024-11-21 10:43:16 +08:00
as2252258 9775d16db5 eee 2024-11-06 21:47:21 +08:00
as2252258 03bffb5e5b eee 2024-11-06 21:41:43 +08:00
3 changed files with 13 additions and 5 deletions
+9 -4
View File
@@ -14,6 +14,7 @@ use Closure;
use Exception;
use Kiri\Di\Interface\InjectTargetInterface;
use Kiri\Router\Interface\ValidatorInterface;
use Kiri\Server\Task\OnTaskFinish;
use Psr\Container\ContainerInterface;
use ReflectionAttribute;
use ReflectionClass;
@@ -91,7 +92,8 @@ class Container implements ContainerInterface
*/
public function get(string $id): object
{
if (isset($this->_singletons[$id])) return $this->_singletons[$id];
if (isset($this->_singletons[$id]))
return $this->_singletons[$id];
if (isset($this->_interfaces[$id])) {
return $this->_singletons[$id] = $this->make($this->_interfaces[$id]);
} else {
@@ -165,15 +167,17 @@ class Container implements ContainerInterface
throw new ReflectionException('Class ' . $className . ' cannot be instantiated');
}
if (($handler = $reflect->getConstructor()) !== null) {
if (empty($construct) && ($handler = $reflect->getConstructor()) !== null) {
$construct = $this->getMethodParams($handler);
}
$newInstance = $reflect->newInstanceArgs($construct);
return $this->runInit($reflect, static::configure($newInstance, $config));
}
/**
* @param ReflectionClass $reflect
* @param array $construct
@@ -191,7 +195,7 @@ class Container implements ContainerInterface
throw new ReflectionException('Class ' . $reflect->getName() . ' cannot be instantiated');
}
if (($handler = $reflect->getConstructor()) !== null) {
if (empty($construct) && ($handler = $reflect->getConstructor()) !== null) {
$construct = $this->getMethodParams($handler);
}
$newInstance = $reflect->newInstanceArgs($construct);
@@ -304,7 +308,8 @@ class Container implements ContainerInterface
{
$className = $parameters->getDeclaringClass()->getName();
$methodName = $parameters->getName();
if (!isset($this->_parameters[$className])) $this->_parameters[$className] = [];
if (!isset($this->_parameters[$className]))
$this->_parameters[$className] = [];
if (!isset($this->_parameters[$className][$methodName])) {
return $this->_parameters[$className][$methodName] = $this->resolveMethodParams($parameters);
} else {
+1 -1
View File
@@ -14,7 +14,7 @@ class CoroutineContext implements ContextInterface
*/
public static function inCoroutine(): bool
{
return true;
return Coroutine::getCid() > -1;
}
+3
View File
@@ -83,6 +83,9 @@ class Scanner extends Component
{
try {
require_once "$path";
if (!isset($_SERVER['PWD'])) {
$_SERVER['PWD'] = APP_PATH;
}
$path = str_replace($_SERVER['PWD'], '', $path);
$path = str_replace('.php', '', $path);
$this->parseFile($path);