From 48ca7030718806334c68cc3e236ede60a9449515 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Thu, 20 Oct 2016 00:52:29 +0800 Subject: [PATCH] Routing js alert only work in @route() #306 --- .../Renderer/Edge/WindwalkerExtension.php | 2 +- src/Core/Router/MainRouter.php | 33 ------------------- src/Core/Router/PackageRouter.php | 26 +++++++++++++-- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/Core/Renderer/Edge/WindwalkerExtension.php b/src/Core/Renderer/Edge/WindwalkerExtension.php index 736d68a1..34ea767b 100644 --- a/src/Core/Renderer/Edge/WindwalkerExtension.php +++ b/src/Core/Renderer/Edge/WindwalkerExtension.php @@ -148,7 +148,7 @@ public function messages($expression) */ public function route($expression) { - return "route{$expression}) ?>"; + return "generate{$expression}) ?>"; } /** diff --git a/src/Core/Router/MainRouter.php b/src/Core/Router/MainRouter.php index eda6fd4a..4d5228ce 100644 --- a/src/Core/Router/MainRouter.php +++ b/src/Core/Router/MainRouter.php @@ -173,39 +173,6 @@ public function build($route, $queries = array(), $type = MainRouter::TYPE_RAW) return $url; } - /** - * build - * - * @param string $route - * @param array $queries - * @param string $type - * - * @return string - * @throws \OutOfRangeException - */ - public function route($route, $queries = [], $type = MainRouter::TYPE_PATH) - { - try - { - return $this->build($route, $queries, $type); - } - catch (\OutOfRangeException $e) - { - $config = Ioc::getConfig(); - - if ($config->get('routing.debug', false)) - { - throw new \OutOfRangeException($e->getMessage(), $e->getCode(), $e); - } - elseif ($config->get('system.debug', false)) - { - return sprintf('javascript:alert(\'%s\')', htmlentities($e->getMessage(), ENT_QUOTES, 'UTF-8')); - } - - return '#'; - } - } - /** * match * diff --git a/src/Core/Router/PackageRouter.php b/src/Core/Router/PackageRouter.php index 4b92e64f..93ba5771 100644 --- a/src/Core/Router/PackageRouter.php +++ b/src/Core/Router/PackageRouter.php @@ -70,11 +70,33 @@ public function route($route, $queries = [], $type = MainRouter::TYPE_PATH) } catch (\OutOfRangeException $e) { - if ($this->package->app->get('routing.debug', false)) + if ($this->package->app->get('routing.debug', true)) { throw new \OutOfRangeException($e->getMessage(), $e->getCode(), $e); } - elseif ($this->package->app->get('system.debug', false)) + + return '#'; + } + } + + /** + * generate + * + * @param string $route + * @param array $queries + * @param string $type + * + * @return string + */ + public function generate($route, $queries = [], $type = MainRouter::TYPE_PATH) + { + try + { + return $this->route($route, $queries, $type); + } + catch (\OutOfRangeException $e) + { + if ($this->package->app->get('system.debug', false)) { return sprintf('javascript:alert(\'%s\')', htmlentities($e->getMessage(), ENT_QUOTES, 'UTF-8')); }