From 97daebfa9e8bb0cd8df1c20c400a678f41f937b8 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 13 Feb 2016 15:23:53 +1100 Subject: [PATCH] Use BadMethodCallException for graceful failure (Twig only) Fixes #1571 This also fixes method inheritance for behaviors by using parent::__call() to look for any methods provided by extensions, catches the exception, then continues with BAU --- modules/cms/classes/ComponentBase.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/cms/classes/ComponentBase.php b/modules/cms/classes/ComponentBase.php index a4507b963..d9dbcbf53 100644 --- a/modules/cms/classes/ComponentBase.php +++ b/modules/cms/classes/ComponentBase.php @@ -7,6 +7,7 @@ use Config; use Cms\Classes\CodeBase; use Cms\Classes\CmsException; use October\Rain\Extension\Extendable; +use BadMethodCallException; /** * Component base class @@ -36,7 +37,7 @@ abstract class ComponentBase extends Extendable public $name; /** - * @var boolean Determines whether the component is hidden in the back-end UI. + * @var boolean Determines whether the component is hidden from the back-end UI. */ public $isHidden = false; @@ -265,15 +266,16 @@ abstract class ComponentBase extends Extendable */ public function __call($method, $parameters) { - if (method_exists($this, $method)) { - return call_user_func_array([$this, $method], $parameters); + try { + parent::__call($method, $parameters); } + catch (BadMethodCallException $ex) {} if (method_exists($this->controller, $method)) { return call_user_func_array([$this->controller, $method], $parameters); } - throw new CmsException(Lang::get('cms::lang.component.method_not_found', [ + throw new BadMethodCallException(Lang::get('cms::lang.component.method_not_found', [ 'name' => get_class($this), 'method' => $method ]));