This commit is contained in:
2021-03-30 14:28:25 +08:00
parent 635bc79993
commit b57ca5e9ea
+21 -5
View File
@@ -196,6 +196,8 @@ abstract class BaseApplication extends Service
* @param $key
* @param $value
* @throws InitException
* @throws NotFindClassException
* @throws ReflectionException
*/
private function addEvent($event, $key, $value): void
{
@@ -203,16 +205,30 @@ abstract class BaseApplication extends Service
$event->on($key, $value, [], true);
return;
}
if (isset($value[0]) && is_object($value[0])) {
if (is_object($value)) {
$event->on($key, $value, [], true);
return;
}
foreach ($value as $item) {
if (!is_callable($item, true)) {
throw new InitException("Class does not hav callback.");
if (is_array($value)) {
if (is_object($value[0]) && !($value[0] instanceof \Closure)) {
$event->on($key, $value, [], true);
return;
}
if (is_string($value[0])) {
$value[0] = Snowflake::createObject($value[0]);
$event->on($key, $value, [], true);
return;
}
foreach ($value as $item) {
if (!is_callable($item, true)) {
throw new InitException("Class does not hav callback.");
}
$event->on($key, $item, [], true);
}
$event->on($key, $item, [], true);
}
}