This commit is contained in:
2021-11-27 17:43:29 +08:00
parent 3ead688d5f
commit f26539c41f
4 changed files with 42 additions and 31 deletions
+39 -16
View File
@@ -21,6 +21,7 @@ use ReflectionException;
use ReflectionFunction;
use ReflectionMethod;
use ReflectionProperty;
use Psr\Container\ContainerInterface;
/**
* Class Container
@@ -61,26 +62,39 @@ class Container extends BaseObject implements ContainerInterface
];
/**
* @param $class
* @param array $constrict
* @param array $config
*
* @return mixed
* @throws
*/
public function get($class, array $constrict = [], array $config = []): mixed
/**
* @param string $id
* @return mixed
* @throws ReflectionException
*/
public function get(string $id): mixed
{
if ($this->isInterface($class)) {
$class = $this->_interfaces[$class];
}
if (!isset($this->_singletons[$class])) {
$this->_singletons[$class] = $this->resolve($class, $constrict, $config);
}
return $this->_singletons[$class];
return $this->make($id, [], []);
}
/**
* @param $class
* @param array $constrict
* @param array $config
* @return mixed
* @throws ReflectionException
* @throws Exception
*/
public function make($class, array $constrict = [], array $config = []): mixed
{
if ($this->isInterface($class)) {
$class = $this->_interfaces[$class];
}
if (!isset($this->_singletons[$class])) {
$this->_singletons[$class] = $this->resolve($class, $constrict, $config);
}
return $this->_singletons[$class];
}
/**
* @param string $interface
* @param string $class
@@ -435,4 +449,13 @@ class Container extends BaseObject implements ContainerInterface
}
return $old;
}
/**
* @param string $id
* @return bool
*/
public function has(string $id): bool
{
return isset($this->_singletons[$id]) || isset($this->_interfaces[$id]);
}
}
-12
View File
@@ -1,12 +0,0 @@
<?php
namespace Kiri\Di;
/**
* @mixin Container
*/
interface ContainerInterface
{
}
+2 -2
View File
@@ -72,9 +72,9 @@ class HotReload extends Command
$this->dirs = Config::get('inotify', [APP_PATH . 'app']);
swoole_async_set(['enable_coroutine' => false]);
if (!extension_loaded('inotify')) {
$this->driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]);
$this->driver = Kiri::getDi()->make(Scaner::class, [$this->dirs, $this]);
} else {
$this->driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
$this->driver = Kiri::getDi()->make(Inotify::class, [$this->dirs, $this]);
}
if (Kiri::getPlatform()->isLinux()) {
swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather');
+1 -1
View File
@@ -13,7 +13,7 @@ use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Config;
use Kiri\Core\Json;
use Kiri\Di\Container;
use Kiri\Di\ContainerInterface;
use Psr\Container\ContainerInterface;
use ReflectionException;
use Server\ServerManager;
use Swoole\Coroutine;