This commit is contained in:
2023-11-30 17:46:50 +08:00
parent aa9d25d4ee
commit b25987c865
4 changed files with 75 additions and 2 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ class Kiri
/**
* @return \Kiri\Pool\Pool
* @throws ReflectionException
* @throws ReflectionException|Exception
*/
public static function getPool(): \Kiri\Pool\Pool
{
+1 -1
View File
@@ -28,7 +28,7 @@ use Kiri\Error\StdoutLogger;
* @package Kiri\Base
* @property DatabasesProviders $connections
*/
abstract class BaseApplication extends Component
abstract class BaseApplication extends LocalService
{
+65
View File
@@ -0,0 +1,65 @@
<?php
namespace Kiri\Abstracts;
use Exception;
class LocalService extends Component implements LocalServiceInterface
{
/**
* @var array
*/
protected array $_definition = [];
/**
* @var array
*/
protected array $_components = [];
/**
* @param string $name
* @return bool
*/
public function has(string $name): bool
{
return isset($this->_definition[$name]) || isset($this->_components[$name]);
}
/**
* @param string $name
* @return mixed
* @throws Exception
*/
public function get(string $name): mixed
{
if (isset($this->_components[$name])) return $this->_components[$name];
if (!isset($this->_definition[$name])) {
throw new Exception('Undefined component ' . $name);
}
$definition = $this->_definition[$name];
if (!($definition instanceof \Closure)) {
$this->_components[$name] = \Kiri::createObject($definition);
} else {
$this->_components[$name] = call_user_func($definition);
}
return $this->_components[$name];
}
/**
* @param string $name
* @param array $value
* @return void
*/
public function set(string $name, array $value): void
{
$this->_definition[$name] = $value;
unset($this->_components[$name]);
}
}
@@ -0,0 +1,8 @@
<?php
namespace Kiri\Abstracts;
interface LocalServiceInterface
{
}