This commit is contained in:
2020-09-07 17:08:58 +08:00
parent c75f38df8e
commit 08298ba09e
+26
View File
@@ -69,6 +69,7 @@ abstract class BaseApplication extends Service
$this->moreComponents();
$this->parseInt($config);
$this->parseEvents($config);
$this->initErrorHandler();
$this->enableEnvConfig();
@@ -164,6 +165,31 @@ abstract class BaseApplication extends Service
}
/**
* @param $config
*
* @throws
*/
public function parseEvents($config)
{
if (!isset($config['events']) || !is_array($config['events'])) {
return;
}
$event = Snowflake::app()->event;
foreach ($config['events'] as $key => $value) {
if (is_string($value)) {
if (!class_exists($value)) {
throw new InitException("Class {$value} does not exists.");
}
$value = Snowflake::createObject($value);
} else if (is_array($value) && !is_callable($value, true)) {
throw new InitException("Class does not hav callback.");
}
$event->on($key, $value);
}
}
/**
* @param $name
* @return mixed