From a9ced778ee182cdc8bbd53f65c26d4bcb268fc95 Mon Sep 17 00:00:00 2001 From: Shane Armstrong Date: Wed, 12 Oct 2016 15:48:58 +0100 Subject: [PATCH] #203 - Executing an unmapped method within the engine dispatcher now throws an Exception, clarified the return class of Flight::app() --- flight/Engine.php | 10 ++++++++++ flight/Flight.php | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/flight/Engine.php b/flight/Engine.php index 914e08e..8c0c41a 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -272,6 +272,16 @@ class Engine { $this->loader->addDirectory($dir); } + /** + * Checks for mapped event within the engine dispatcher. + * + * @param $name + * @return bool + */ + public function isEvent($name) { + return !is_null($this->dispatcher->get($name)); + } + /*** Extensible Methods ***/ /** diff --git a/flight/Flight.php b/flight/Flight.php index f58dc2c..c2de4f9 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -69,15 +69,20 @@ class Flight { * @param string $name Method name * @param array $params Method parameters * @return mixed Callback results + * @throws \Exception */ public static function __callStatic($name, $params) { $app = Flight::app(); + if (!method_exists($app, $name) && !$app->isEvent($name)) { + throw new \Exception("{$name} must be a mapped method"); + } + return \flight\core\Dispatcher::invokeMethod(array($app, $name), $params); } /** - * @return object Application instance + * @return \flight\Engine Application instance */ public static function app() { static $initialized = false;