From 635bc7999312c870068691bf65db2921f9734efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 30 Mar 2021 14:24:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Abstracts/BaseApplication.php | 37 +++++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/System/Abstracts/BaseApplication.php b/System/Abstracts/BaseApplication.php index 7145f0ea..964bc6bf 100644 --- a/System/Abstracts/BaseApplication.php +++ b/System/Abstracts/BaseApplication.php @@ -186,19 +186,32 @@ abstract class BaseApplication extends Service if (is_string($value)) { $value = Snowflake::createObject($value); } - if (is_array($value) && isset($value[0]) && !($value[0] instanceof \Closure)) { - if (!is_callable($value, true)) { - throw new InitException("Class does not hav callback."); - } - $event->on($key, $value, [], true); - } else { - foreach ($value as $item) { - if (!is_callable($item, true)) { - throw new InitException("Class does not hav callback."); - } - $event->on($key, $item, [], true); - } + $this->addEvent($event, $key, $value); + } + } + + + /** + * @param $event + * @param $key + * @param $value + * @throws InitException + */ + private function addEvent($event, $key, $value): void + { + if ($value instanceof \Closure) { + $event->on($key, $value, [], true); + return; + } + if (isset($value[0]) && is_object($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); } }