From 08298ba09e08249687f9df4e12865a8b388e7522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 7 Sep 2020 17:08:58 +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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/System/Abstracts/BaseApplication.php b/System/Abstracts/BaseApplication.php index de0a87f6..799754f7 100644 --- a/System/Abstracts/BaseApplication.php +++ b/System/Abstracts/BaseApplication.php @@ -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