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
+36 -1
View File
@@ -21,6 +21,7 @@ use Snowflake\Core\Json;
use Snowflake\Error\Logger;
use Snowflake\Event;
use Snowflake\Exception\ConfigException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
use Swoole\WebSocket\Server;
@@ -681,13 +682,47 @@ if (!function_exists('env')) {
}
if (!function_exists('di')) {
/**
* @param string $className
* @return mixed
* @throws ReflectionException
* @throws NotFindClassException
*/
function di(string $className): mixed
{
return Snowflake::getDi()->get($className);
}
}
if (!function_exists('duplicate')) {
/**
* @param string $className
* @return mixed
* @throws ReflectionException
* @throws NotFindClassException
*/
function duplicate(string $className): mixed
{
$class = di($className);
return clone $class;
}
}
if (!function_exists('sweep')) {
/**
* @param string $configPath
* @return array|false|string|null
*/
function sweep($configPath = APP_PATH . 'config'): bool|array|string|null
function sweep(string $configPath = APP_PATH . 'config'): bool|array|string|null
{
$array = [];
foreach (glob($configPath . '/*') as $config) {