This commit is contained in:
2021-08-13 17:06:52 +08:00
parent fe67cad896
commit 36f0e45e7e
2 changed files with 27 additions and 4 deletions
+17 -4
View File
@@ -75,11 +75,24 @@ abstract class BaseApplication extends Component
$this->parseEvents($config);
$this->initErrorHandler();
$this->enableEnvConfig();
$this->mapping($config['mapping']);
parent::__construct();
}
/**
* @param array $mapping
*/
public function mapping(array $mapping)
{
$di = Kiri::getDi();
foreach ($mapping as $interface => $class) {
$di->mapping($interface, $class);
}
}
/**
* @return array
*/
@@ -223,18 +236,18 @@ abstract class BaseApplication extends Component
{
$eventProvider = di(EventProvider::class);
if ($value instanceof \Closure || is_object($value)) {
$eventProvider->on($key, $value,0);
$eventProvider->on($key, $value, 0);
return;
}
if (is_array($value)) {
if (is_object($value[0]) && !($value[0] instanceof \Closure)) {
$eventProvider->on($key, $value,0);
$eventProvider->on($key, $value, 0);
return;
}
if (is_string($value[0])) {
$value[0] = Kiri::createObject($value[0]);
$eventProvider->on($key, $value,0);
$eventProvider->on($key, $value, 0);
return;
}
@@ -242,7 +255,7 @@ abstract class BaseApplication extends Component
if (!is_callable($item, true)) {
throw new InitException("Class does not hav callback.");
}
$eventProvider->on($key, $item,0);
$eventProvider->on($key, $item, 0);
}
}