Permalink
Browse files

Moved map method check to Engine. Added get method to Loader. Added n…

…ew tests.
  • Loading branch information...
1 parent b4b4346 commit b30d5e5fa2de08c3e91c1165ee226fd83f29ba9b @mikecao committed Oct 12, 2016
Showing with 30 additions and 19 deletions.
  1. +2 −4 .gitignore
  2. +1 −1 VERSION
  3. +5 −10 flight/Engine.php
  4. +0 −4 flight/Flight.php
  5. +8 −0 flight/core/Loader.php
  6. +7 −0 tests/FlightTest.php
  7. +7 −0 tests/MapTest.php
View
@@ -1,6 +1,4 @@
-composer.phar
+.idea
vendor/
-
-# 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.phar
composer.lock
View
@@ -1 +1 @@
-1.2.21
+1.2.22
View
@@ -56,6 +56,7 @@ public function __construct() {
* @param string $name Method name
* @param array $params Method parameters
* @return mixed Callback results
+ * @throws \Exception
*/
public function __call($name, $params) {
$callback = $this->dispatcher->get($name);
@@ -64,6 +65,10 @@ public function __call($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;
return $this->loader->load($name, $shared);
@@ -272,16 +277,6 @@ public function path($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 ***/
/**
View
@@ -74,10 +74,6 @@ private function __clone() {}
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);
}
@@ -138,6 +138,14 @@ public function newInstance($class, array $params = array()) {
}
/**
+ * @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.
*/
public function reset() {
@@ -73,4 +73,11 @@ function testMap(){
$this->assertEquals('hello', $result);
}
+
+ // Unmapped method
+ function testUnmapped() {
+ $this->setExpectedException('Exception', 'doesNotExist must be a mapped method.');
+
+ Flight::doesNotExist();
+ }
}
View
@@ -62,4 +62,11 @@ function testStaticClassMethodMapping(){
$this->assertEquals('goodbye', $result);
}
+
+ // Unmapped method
+ function testUnmapped() {
+ $this->setExpectedException('Exception', 'doesNotExist must be a mapped method.');
+
+ $this->app->doesNotExist();
+ }
}

0 comments on commit b30d5e5

Please sign in to comment.