From 4e719adc722d8860ea7c8b860db84218607fc98a Mon Sep 17 00:00:00 2001 From: Malikin Sergey Date: Sat, 14 Feb 2015 16:34:42 +0300 Subject: [PATCH 1/2] Add throwing exception, when controller action not found If undefined action passed In UrlGenerator::action(), it's throw fatal exception `Call to a member function domain() on a non-object` with fully uninformative debug stack because route, which was returned by `$this->routes->getByAction($action)` is not checked, before it passes to `$this->toRoute(...` and can be `null` instead of `Route` So, it seems logical to add some check, as in UrlGenerator::route() --- src/Illuminate/Routing/UrlGenerator.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Routing/UrlGenerator.php b/src/Illuminate/Routing/UrlGenerator.php index dac9c06b257b..4c309bc413ee 100755 --- a/src/Illuminate/Routing/UrlGenerator.php +++ b/src/Illuminate/Routing/UrlGenerator.php @@ -518,6 +518,8 @@ protected function getRouteScheme($route) * @param mixed $parameters * @param bool $absolute * @return string + * + * @throws \InvalidArgumentException */ public function action($action, $parameters = array(), $absolute = true) { @@ -529,8 +531,13 @@ public function action($action, $parameters = array(), $absolute = true) { $action = trim($action, '\\'); } - - return $this->toRoute($this->routes->getByAction($action), $parameters, $absolute); + + if ( !is_null($route = $this->routes->getByAction($action))) + { + return $this->toRoute($route, $parameters, $absolute); + } + throw new InvalidArgumentException("Action {$action} not defined."); + } /** From 4a94ca48103dfa0a046ff6b8160b1b123bdebb4c Mon Sep 17 00:00:00 2001 From: Malikin Sergey Date: Sat, 14 Feb 2015 16:45:40 +0300 Subject: [PATCH 2/2] fix cs --- src/Illuminate/Routing/UrlGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Routing/UrlGenerator.php b/src/Illuminate/Routing/UrlGenerator.php index 4c309bc413ee..9d360f651c5d 100755 --- a/src/Illuminate/Routing/UrlGenerator.php +++ b/src/Illuminate/Routing/UrlGenerator.php @@ -532,12 +532,12 @@ public function action($action, $parameters = array(), $absolute = true) $action = trim($action, '\\'); } - if ( !is_null($route = $this->routes->getByAction($action))) + if ( ! is_null($route = $this->routes->getByAction($action))) { return $this->toRoute($route, $parameters, $absolute); } + throw new InvalidArgumentException("Action {$action} not defined."); - } /**