Browse Source

fix for issue #786 plus minor improvement to Dispatcher

Jason Hinkle 11 years ago
parent
commit
309421050e

+ 2 - 0
phreeze/index.php

@@ -31,6 +31,8 @@ $route_map = array(
 
 
 $router = new SimpleRouter('/','Test.JSON',$route_map);
 $router = new SimpleRouter('/','Test.JSON',$route_map);
 
 
+Dispatcher::$FAST_LOOKUP = true;
+
 Dispatcher::Dispatch(
 Dispatcher::Dispatch(
 	$phreezer,
 	$phreezer,
 	null,
 	null,

+ 3 - 5
phreeze/libs/Controller/TestController.php

@@ -43,7 +43,7 @@ class TestController extends Controller
 
 
 		$id = mt_rand(1, 10000);
 		$id = mt_rand(1, 10000);
 		$world = $this->Phreezer->Get("World",$id);
 		$world = $this->Phreezer->Get("World",$id);
-		$this->RenderJSON($world);
+		$this->RenderJSON($world,'',true);
 	}
 	}
 	
 	
 	
 	
@@ -71,11 +71,9 @@ class TestController extends Controller
 		for ($i = 0; $i < $query_count; $i++) {
 		for ($i = 0; $i < $query_count; $i++) {
 				
 				
 			$id = mt_rand(1, 10000);
 			$id = mt_rand(1, 10000);
-
-			$world = $this->Phreezer->Get("World",$id);
-
+
 			// convert the Phreezable object into a simple structure for output
 			// convert the Phreezable object into a simple structure for output
-			$arr[] = array('id'=>$world->Id,'randomNumber'=>$world->Randomnumber);
+			$arr[] = $this->Phreezer->Get("World",$id)->ToObject();
 		}
 		}
 			
 			
 		$this->RenderJSON($arr);
 		$this->RenderJSON($arr);

+ 10 - 1
phreeze/libs/Model/World.php

@@ -39,11 +39,20 @@ class World extends WorldDAO
 		// the controller create/update methods validate before saving.  this will be a
 		// the controller create/update methods validate before saving.  this will be a
 		// redundant validation check, however it will ensure data integrity at the model
 		// redundant validation check, however it will ensure data integrity at the model
 		// level based on validation rules.  comment this line out if this is not desired
 		// level based on validation rules.  comment this line out if this is not desired
-		if (!$this->Validate()) throw new Exception('Unable to Save World: ' .  implode(', ', $this->GetValidationErrors()));
+		// if (!$this->Validate()) throw new Exception('Unable to Save World: ' .  implode(', ', $this->GetValidationErrors()));
 
 
 		// OnSave must return true or eles Phreeze will cancel the save operation
 		// OnSave must return true or eles Phreeze will cancel the save operation
 		return true;
 		return true;
 	}
 	}
+	
+	/**
+	 * @return multitype:NULL boolean
+	 */
+	public function ToObject($options = null)
+	{
+		$obj = array('id'=>$this->Id,'randomNumber'=>$this->Randomnumber);
+		return $obj;
+	}
 
 
 }
 }
 
 

+ 25 - 5
phreeze/libs/verysimple/Phreeze/Dispatcher.php

@@ -12,7 +12,7 @@ require_once("verysimple/Util/ExceptionThrower.php");
  * @author     VerySimple Inc.
  * @author     VerySimple Inc.
  * @copyright  1997-2007 VerySimple, Inc.
  * @copyright  1997-2007 VerySimple, Inc.
  * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
  * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
- * @version    2.6
+ * @version    2.7
  */
  */
 class Dispatcher
 class Dispatcher
 {
 {
@@ -21,6 +21,14 @@ class Dispatcher
 	 * @var boolean default = true
 	 * @var boolean default = true
 	 */
 	 */
 	static $IGNORE_DEPRECATED = true;
 	static $IGNORE_DEPRECATED = true;
+	
+	/**
+	 * FAST_LOOKUP mode instructs the dispatcher to assume that the controller and method
+	 * supplied by the router are valid and not do any checking for the existance of
+	 * the controller file or the method before trying to call it
+	 * @var boolean use fast lookup mode if true 
+	 */
+	static $FAST_LOOKUP = false;
 
 
 	/**
 	/**
 	 * This is a case-insensitive version of file_exists
 	 * This is a case-insensitive version of file_exists
@@ -59,16 +67,28 @@ class Dispatcher
 	 */
 	 */
 	static function Dispatch($phreezer,$renderEngine,$action='',$context=null,$router=null)
 	static function Dispatch($phreezer,$renderEngine,$action='',$context=null,$router=null)
 	{
 	{
-		if ($router == null)
-		{
+		if ($router == null) {
 			require_once('GenericRouter.php');
 			require_once('GenericRouter.php');
 			$router = new GenericRouter();
 			$router = new GenericRouter();
 		}
 		}
 
 
+		// get the route and normalize the controller name
 		list($controller_param,$method_param) = $router->GetRoute( $action );
 		list($controller_param,$method_param) = $router->GetRoute( $action );
-
-		// normalize the input
 		$controller_class = $controller_param."Controller";
 		$controller_class = $controller_param."Controller";
+	
+		if (self::$FAST_LOOKUP) {
+
+			if (!class_exists($controller_class)) {
+				$controller_file = "Controller/$controller_class.php";
+				include_once $controller_file;
+			}
+			
+			$controller = new $controller_class($phreezer,$renderEngine,$context,$router);
+			$controller->$method_param();
+			
+			return true;
+		}
+		
 		
 		
 		// if the controller was in a sub-directory, get rid of the directory path
 		// if the controller was in a sub-directory, get rid of the directory path
 		$slashPos = strpos($controller_class,'/');
 		$slashPos = strpos($controller_class,'/');