Moved map method check to Engine. Added get method to Loader. Added new tests.

pull/301/head v1.2.22
Mike Cao 8 years ago
parent b4b43460eb
commit b30d5e5fa2

6
.gitignore vendored

@ -1,6 +1,4 @@
composer.phar .idea
vendor/ vendor/
composer.phar
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock composer.lock

@ -1 +1 @@
1.2.21 1.2.22

@ -56,6 +56,7 @@ class Engine {
* @param string $name Method name * @param string $name Method name
* @param array $params Method parameters * @param array $params Method parameters
* @return mixed Callback results * @return mixed Callback results
* @throws \Exception
*/ */
public function __call($name, $params) { public function __call($name, $params) {
$callback = $this->dispatcher->get($name); $callback = $this->dispatcher->get($name);
@ -64,6 +65,10 @@ class Engine {
return $this->dispatcher->run($name, $params); return $this->dispatcher->run($name, $params);
} }
if (!$this->loader->get($name)) {
throw new \Exception("{$name} must be a mapped method.");
}
$shared = (!empty($params)) ? (bool)$params[0] : true; $shared = (!empty($params)) ? (bool)$params[0] : true;
return $this->loader->load($name, $shared); return $this->loader->load($name, $shared);
@ -272,16 +277,6 @@ class Engine {
$this->loader->addDirectory($dir); $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 ***/ /*** Extensible Methods ***/
/** /**

@ -74,10 +74,6 @@ class Flight {
public static function __callStatic($name, $params) { public static function __callStatic($name, $params) {
$app = Flight::app(); $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 \flight\core\Dispatcher::invokeMethod(array($app, $name), $params);
} }

@ -137,6 +137,14 @@ class Loader {
} }
} }
/**
* @param string $name Registry name
* @return mixed Class information or null if not registered
*/
public function get($name) {
return isset($this->classes[$name]) ? $this->classes[$name] : null;
}
/** /**
* Resets the object to the initial state. * Resets the object to the initial state.
*/ */

@ -73,4 +73,11 @@ class FlightTest extends PHPUnit_Framework_TestCase
$this->assertEquals('hello', $result); $this->assertEquals('hello', $result);
} }
// Unmapped method
function testUnmapped() {
$this->setExpectedException('Exception', 'doesNotExist must be a mapped method.');
Flight::doesNotExist();
}
} }

@ -62,4 +62,11 @@ class MapTest extends PHPUnit_Framework_TestCase
$this->assertEquals('goodbye', $result); $this->assertEquals('goodbye', $result);
} }
// Unmapped method
function testUnmapped() {
$this->setExpectedException('Exception', 'doesNotExist must be a mapped method.');
$this->app->doesNotExist();
}
} }

Loading…
Cancel
Save