From c7dad835b3947d4088e1774c7ff5e22c423ea1da Mon Sep 17 00:00:00 2001 From: Gevorg Mansuryan Date: Mon, 27 Aug 2018 23:09:49 +0400 Subject: [PATCH] added Console App Support --- src/Router.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Router.php b/src/Router.php index e630150..d31f664 100644 --- a/src/Router.php +++ b/src/Router.php @@ -64,19 +64,21 @@ public function dispatch() call_user_func($route->callable, $rule); } - try { - if ($request = $rule->parseRequest($this->urlManager, $app->request)) { - $params = ArrayHelper::merge($request, [$event]); - foreach ($route->getMiddleware() as $callBack) { - if (is_callable($callBack)) { - call_user_func_array($callBack, $params); - } else { - call_user_func_array([$callBack, 'handle'], $params); + if (Yii::$app instanceof \yii\web\Application) { + try { + if ($request = $rule->parseRequest($this->urlManager, $app->request)) { + $params = ArrayHelper::merge($request, [$event]); + foreach ($route->getMiddleware() as $callBack) { + if (is_callable($callBack)) { + call_user_func_array($callBack, $params); + } else { + call_user_func_array([$callBack, 'handle'], $params); + } } } + } catch (UrlNormalizerRedirectException $e) { + //ignore this at this time } - } catch (UrlNormalizerRedirectException $e) { - //ignore this at this time } $this->urlManager->addRules([$rule], true);