变更
This commit is contained in:
+36
-6
@@ -36,6 +36,21 @@ if (!function_exists('make')) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('service')) {
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return mixed|null
|
||||
* @throws Exception
|
||||
*/
|
||||
function service(string $name): mixed
|
||||
{
|
||||
return Kiri::service()->get($name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('replica')) {
|
||||
|
||||
|
||||
@@ -911,12 +926,28 @@ if (!function_exists('env')) {
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('config')) {
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param null $default
|
||||
* @return array|string|null
|
||||
*/
|
||||
#[Pure] function config($key, $default = NULL): null|array|string
|
||||
{
|
||||
return Config::get($key, $default);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('di')) {
|
||||
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
function di(string $className): mixed
|
||||
{
|
||||
@@ -934,7 +965,7 @@ if (!function_exists('interval')) {
|
||||
* @param int $interval
|
||||
* @param bool $is
|
||||
*/
|
||||
function interval(callable $callback, int $interval = 1000, bool $is = FALSE)
|
||||
function interval(callable $callback, int $interval = 1000, bool $is = FALSE): void
|
||||
{
|
||||
usleep($interval * 1000);
|
||||
|
||||
@@ -1142,13 +1173,12 @@ if (!function_exists('error')) {
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @return bool
|
||||
* @param array $method
|
||||
* @return void
|
||||
*/
|
||||
function error(mixed $message, string $method = 'error'): bool
|
||||
function error(mixed $message, array $method = []): void
|
||||
{
|
||||
Kiri::getLogger()->error($method, [$message]);
|
||||
return false;
|
||||
Kiri::getLogger()->error($message, $method);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ class Loader extends Component
|
||||
if (!class_exists($class)) {
|
||||
return null;
|
||||
}
|
||||
return Kiri::getDi()->getReflect($class);
|
||||
return Kiri::getDi()->getReflectionClass($class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kiri\Core;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use ReturnTypeWillChange;
|
||||
use Traversable;
|
||||
@@ -24,6 +25,15 @@ class HashMap implements \ArrayAccess, \IteratorAggregate
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasItem(): bool
|
||||
{
|
||||
return count($this->lists) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param $value
|
||||
@@ -34,6 +44,23 @@ class HashMap implements \ArrayAccess, \IteratorAggregate
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param $value
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function append(string $key, $value): void
|
||||
{
|
||||
if (!$this->has($key)) {
|
||||
$this->lists[$key] = [];
|
||||
} else if (!is_array($this->lists[$key])) {
|
||||
throw new Exception('Source must a array.');
|
||||
}
|
||||
$this->lists[$key][] = $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
@@ -108,4 +135,17 @@ class HashMap implements \ArrayAccess, \IteratorAggregate
|
||||
{
|
||||
unset($this->lists[$offset]);
|
||||
}
|
||||
|
||||
|
||||
public static function Tree(HashMap $root, string $leaf)
|
||||
{
|
||||
if ($root->has($leaf)) {
|
||||
$hashMap = $root->get($leaf);
|
||||
} else {
|
||||
$hashMap = new HashMap();
|
||||
$root->put($leaf, $hashMap);
|
||||
}
|
||||
return $hashMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user