Browse Source

Merge branch 'master' of https://github.com/jasonhinkle/FrameworkBenchmarks into jasonhinkle-master

Patrick Falls 12 years ago
parent
commit
f0f437c979

+ 8 - 13
phreeze/deploy/nginx.conf

@@ -58,29 +58,24 @@ http {
         #location ~ \.php$ {
         #    proxy_pass   http://127.0.0.1;
         #}
+        
+        root /home/ubuntu/FrameworkBenchmarks/;
+        index  index.php;
+        
+        location /phreeze/ {
+            try_files $uri $uri/ /phreeze/index.php?_REWRITE_COMMAND=$uri&$args;
+        }
 
         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
         #
         location ~ \.php$ {
-            root /home/ubuntu/FrameworkBenchmarks;
+            try_files $uri =404;
             fastcgi_pass   127.0.0.1:9001;
             fastcgi_index  index.php;
 #            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        /usr/local/nginx/conf/fastcgi_params;
         }
-
-	    # url rewriting for a Phreeze application called "example" 
-	    #
-	    location ~ ^/phreeze/(.*) {
-	        try_files /phreeze/$1 /phreeze/$1/ /phreeze/index.php?_REWRITE_COMMAND=$1&args;
-	    }
-	    
-	    # url rewriting for phreeze app that is installed in the htdocs root
-	    #
-	    #location ~ ^/(.*) {
-	    #    try_files /$1 /$1/ /index.php?_REWRITE_COMMAND=$1&args;
-	    #}
     
         # deny access to .htaccess files, if Apache's document root
         # concurs with nginx's one

+ 1 - 1
phreeze/index.php

@@ -24,7 +24,7 @@ $route_map = array(
 		'GET:db' => array('route' => 'Test.DB')
 );
 
-$router = new GenericRouter('./','Test.JSON',$route_map);
+$router = new GenericRouter('/phreeze/','Test.JSON',$route_map);
 
 Dispatcher::Dispatch(
 	$phreezer,

+ 5 - 2
phreeze/libs/verysimple/HTTP/RequestUtil.php

@@ -2,8 +2,6 @@
 /** @package	verysimple::HTTP */
 
 /** import supporting libraries */
-require_once("FileUpload.php");
-require_once("verysimple/String/VerySimpleStringUtil.php");
 
 /**
  * Static utility class for processing form post/request data
@@ -366,6 +364,7 @@ class RequestUtil
 		$tmp_path = $upload['tmp_name'];
 		$info = pathinfo($upload['name']);
 
+		require_once("FileUpload.php");
 		$fupload = new FileUpload();
 		$fupload->Name = $info['basename'];
 		$fupload->Size = $upload['size'];
@@ -455,6 +454,8 @@ class RequestUtil
 
 		if (self::$ENCODE_NON_ASCII)
 		{
+			require_once("verysimple/String/VerySimpleStringUtil.php");
+			
 			if (is_array($val))
 			{
 				foreach ($val as $k=>$v)
@@ -478,6 +479,8 @@ class RequestUtil
 	 */
 	public static function HasNonAsciiChars($fieldname)
 	{
+		require_once("verysimple/String/VerySimpleStringUtil.php");
+		
 		$val = isset($_REQUEST[$fieldname]) ? $_REQUEST[$fieldname] : '';
 		return VerySimpleStringUtil::EncodeToHTML($val) != $val;
 	}

+ 11 - 7
phreeze/libs/verysimple/Phreeze/Controller.php

@@ -4,16 +4,11 @@
 /** import supporting libraries */
 require_once("verysimple/HTTP/RequestUtil.php");
 require_once("verysimple/HTTP/Context.php");
-require_once("verysimple/HTTP/BrowserDevice.php");
-require_once("verysimple/Authentication/Authenticator.php");
-require_once("verysimple/Authentication/Auth401.php");
-require_once("verysimple/Authentication/IAuthenticatable.php");
-require_once("verysimple/String/VerySimpleStringUtil.php");
-require_once("DataPage.php");
 require_once("Phreezer.php");
 require_once("Criteria.php");
 require_once("IRouter.php");
 require_once("GenericRouter.php");
+require_once("verysimple/Authentication/IAuthenticatable.php");
 
 /**
  * Controller is a base controller object used for an MVC pattern
@@ -151,6 +146,8 @@ abstract class Controller
 	 */
 	protected function Require401Authentication(IAuthenticatable $authenticatable, $realm = "Login Required", $qs_username_field = "", $qs_password_field = "")
 	{
+		require_once("verysimple/Authentication/Auth401.php");
+		
 		$user = $this->Get401Authentication($authenticatable,$qs_username_field, $qs_password_field);
 
 		// we only want to output 401 headers if the user is not already authenticated
@@ -290,6 +287,7 @@ abstract class Controller
 	 */
 	public function GetDevice()
 	{
+		require_once("verysimple/HTTP/BrowserDevice.php");
 		return BrowserDevice::GetInstance();
 	}
 
@@ -345,8 +343,10 @@ abstract class Controller
 	 * @param Array $supressProps (In the format Array("PropName1","PropName2")
 	 * @param bool noMap set to true to render this DataPage regardless of whether there is a FieldMap
 	 */
-	protected function RenderXML(DataPage $page,$additionalProps = null, $supressProps = null, $noMap = false)
+	protected function RenderXML($page,$additionalProps = null, $supressProps = null, $noMap = false)
 	{
+		require_once("verysimple/String/VerySimpleStringUtil.php");
+		
 		if (!is_array($supressProps)) $supressProps = array();
 
 		// never include these props
@@ -620,6 +620,8 @@ abstract class Controller
 	 */
 	public function ClearCurrentUser()
 	{
+		require_once("verysimple/Authentication/Authenticator.php");
+		
 		$this->_cu = null;
 		Authenticator::ClearAuthentication($this->GUID);
 	}
@@ -647,6 +649,8 @@ abstract class Controller
 	{
 		if (!$this->_cu)
 		{
+			require_once("verysimple/Authentication/Authenticator.php");
+			
 			$this->Phreezer->Observe("Loading CurrentUser from Session");
 			$this->_cu = Authenticator::GetCurrentUser($this->GUID);
 

+ 62 - 43
phreeze/libs/verysimple/Phreeze/DataAdapter.php

@@ -4,11 +4,7 @@
 /** import supporting libraries */
 require_once("IObservable.php");
 require_once("ConnectionSetting.php");
-require_once("DataPage.php");
-require_once("DataSet.php");
-require_once("QueryBuilder.php");
 require_once("verysimple/DB/DataDriver/IDataDriver.php");
-require_once("verysimple/IO/Includer.php");
 
 /**
  * DataAdapter abstracts and provides access to the data store
@@ -17,7 +13,7 @@ require_once("verysimple/IO/Includer.php");
  * @author     VerySimple Inc. <[email protected]>
  * @copyright  1997-2005 VerySimple Inc.
  * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
- * @version    2.0
+ * @version    2.1
  */
 class DataAdapter implements IObservable
 {
@@ -35,6 +31,9 @@ class DataAdapter implements IObservable
 	/** @var used internally to keep track of communication error re-tries */
 	private $_num_retries = 0;
 	
+	/** @var static singleton instance of the data adapter */
+	static $ADAPTER_INSTANCE = null;
+	
 	/** @var instance of the driver class, used for escaping */
 	static $DRIVER_INSTANCE = null;
 	
@@ -52,47 +51,15 @@ class DataAdapter implements IObservable
     function __construct($csetting, $listener = null, IDataDriver $driver = null)
     {
     	$this->_driver = $driver;
-    	
-    	
-    	if ($this->_driver == null) 
-    	{
-    		// the driver was not explicitly provided so we will try to create one from 
-    		// the connection setting based on the database types that we do know about
-    		switch($csetting->Type)
-    		{
-    			case "mysql":
-					include_once("verysimple/DB/DataDriver/MySQL.php");
-    				$this->_driver  = new DataDriverMySQL();
-    				break;
-    			case "mysqli":
-					include_once("verysimple/DB/DataDriver/MySQLi.php");
-    				$this->_driver  = new DataDriverMySQLi();
-    				break;
-    			case "sqlite":
-					include_once("verysimple/DB/DataDriver/SQLite.php");
-    				$this->_driver  = new DataDriverSQLite();
-    				break;
-    			default:
-    				try
-    				{
-    					Includer::IncludeFile("verysimple/DB/DataDriver/".$csetting->Type.".php");
-						$classname = "DataDriver" . $csetting->Type;
-    					$this->_driver  = new $classname();
-    				}
-    				catch (IncludeException $ex)
-		    		{
-		    			throw new Exception('Unknown DataDriver "' . $csetting->Type . '" specified in connection settings');
-		    		}
-    				break;
-    		}
+    	if ($this->_driver) DataAdapter::$DRIVER_INSTANCE = $this->_driver;
 
-    	}
-    	
-    	DataAdapter::$DRIVER_INSTANCE = $this->_driver;
-    	
-		$this->AttachObserver($listener);
 		$this->ConnectionSetting =& $csetting;
+
+		if ($listener) $this->AttachObserver($listener);
 		$this->Observe("DataAdapter Instantiated", OBSERVE_DEBUG);
+		
+		// set the singleton reference
+		DataAdapter::$ADAPTER_INSTANCE = $this;
 	}
 	
 	
@@ -107,6 +74,52 @@ class DataAdapter implements IObservable
 		$this->Close();
 	}
 	
+	/**
+	 * Load the data driver
+	 * @throws Exception
+	 */
+	public function LoadDriver()
+	{
+
+		if ($this->_driver == null)
+		{
+			require_once("verysimple/IO/Includer.php");
+			
+			// the driver was not explicitly provided so we will try to create one from
+			// the connection setting based on the database types that we do know about
+			switch($this->ConnectionSetting->Type)
+			{
+				case "mysql":
+					include_once("verysimple/DB/DataDriver/MySQL.php");
+					$this->_driver  = new DataDriverMySQL();
+					break;
+				case "mysqli":
+					include_once("verysimple/DB/DataDriver/MySQLi.php");
+					$this->_driver  = new DataDriverMySQLi();
+					break;
+				case "sqlite":
+					include_once("verysimple/DB/DataDriver/SQLite.php");
+					$this->_driver  = new DataDriverSQLite();
+					break;
+				default:
+					try
+					{
+						Includer::IncludeFile("verysimple/DB/DataDriver/".$this->ConnectionSetting->Type.".php");
+						$classname = "DataDriver" . $this->ConnectionSetting->Type;
+						$this->_driver  = new $classname();
+					}
+					catch (IncludeException $ex)
+					{
+						throw new Exception('Unknown DataDriver "' . $this->ConnectionSetting->Type . '" specified in connection settings');
+					}
+					break;
+			}
+		
+			DataAdapter::$DRIVER_INSTANCE = $this->_driver;
+		
+		}
+	}
+	
     /**
 	 * Returns name of the DB currently in use
 	 *
@@ -133,6 +146,8 @@ class DataAdapter implements IObservable
 		}
 		else
 		{
+			if (!$this->_driver) $this->LoadDriver();
+			
 			try
 			{
 				$this->_dbconn = $this->_driver->Open(
@@ -382,6 +397,8 @@ class DataAdapter implements IObservable
 	 */	
     public static function Escape($val)
     {
+    	if (DataAdapter::$ADAPTER_INSTANCE) DataAdapter::$ADAPTER_INSTANCE->LoadDriver();
+
 		// this is an unfortunate leftover from poor design of making this function static
 		// we cannon use the driver's escape method without a static reference
 		if (!DataAdapter::$DRIVER_INSTANCE) throw new Exception("DataAdapter must be instantiated before Escape can be called");
@@ -402,6 +419,8 @@ class DataAdapter implements IObservable
 	 */
 	public static function GetQuotedSql($val)
 	{
+		if (DataAdapter::$ADAPTER_INSTANCE) DataAdapter::$ADAPTER_INSTANCE->LoadDriver();
+		
 		// this is an unfortunate leftover from poor design of making this function static
 		// we cannon use the driver's escape method without a static reference
 		if (!DataAdapter::$DRIVER_INSTANCE) throw new Exception("DataAdapter must be instantiated before Escape can be called");

+ 14 - 11
phreeze/libs/verysimple/Phreeze/GenericRouter.php

@@ -3,16 +3,17 @@
 
 /** import supporting libraries */
 require_once('IRouter.php');
+require_once('verysimple/HTTP/RequestUtil.php');
 
-/**
+/**
  * Generic Router is an implementation of IRouter that uses patterns to connect
- * routes to a Controller/Method
- *
- * @package    verysimple::Phreeze
- * @author     VerySimple Inc.
- * @copyright  1997-2012 VerySimple, Inc.
- * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
- * @version    1.0
+ * routes to a Controller/Method
+ *
+ * @package    verysimple::Phreeze
+ * @author     VerySimple Inc.
+ * @copyright  1997-2013 VerySimple, Inc.
+ * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
+ * @version    1.1
  */
 class GenericRouter implements IRouter
 {
@@ -24,6 +25,8 @@ class GenericRouter implements IRouter
 
 	// cached route from last run:
 	private $cachedRoute;
+	
+	public static $ROUTE_NOT_FOUND = "Default.Error404";
 
 	/**
 	 * Instantiate the GenericRouter
@@ -117,7 +120,7 @@ class GenericRouter implements IRouter
 		}
 
 		// if we haven't returned by now, we've found no match:
-		return array("Default","Error404");
+		return explode('.', self::$ROUTE_NOT_FOUND,2);
 	}
 
 	/**
@@ -132,8 +135,8 @@ class GenericRouter implements IRouter
 			// if a root folder was provided, then we need to strip that out as well
 			if ($this->appRootUrl)
 			{
-				$prefix = $this->appRootUrl.'/';
-				while (substr($this->uri,0,strlen($prefix)) == $prefix)
+				$prefix = str_replace(RequestUtil::GetServerRootUrl(),'/',$this->appRootUrl);
+				if (substr($this->uri,0,strlen($prefix)) == $prefix)
 				{
 					$this->uri = substr($this->uri,strlen($prefix));
 				}

+ 27 - 26
phreeze/libs/verysimple/Phreeze/Phreezer.php

@@ -4,10 +4,7 @@
 /** import supporting libraries */
 require_once("Observable.php");
 require_once("Criteria.php");
-require_once("KeyMap.php");
-require_once("FieldMap.php");
 require_once("DataAdapter.php");
-require_once("NotFoundException.php");
 require_once("CacheRam.php");
 require_once("CacheNoCache.php");
 require_once("verysimple/IO/Includer.php");
@@ -21,7 +18,7 @@ require_once("verysimple/IO/Includer.php");
  * @author     VerySimple Inc.
  * @copyright  1997-2008 VerySimple, Inc.
  * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
- * @version    3.3.3
+ * @version    3.3.4
  */
 class Phreezer extends Observable
 {
@@ -33,7 +30,7 @@ class Phreezer extends Observable
 	 */
 	public $RenderEngine;
 
-	public static $Version = '3.3.3 HEAD';
+	public static $Version = '3.3.4 HEAD';
 
 	/**
 	 * @var int expiration time for query & value cache (in seconds) default = 5
@@ -103,7 +100,7 @@ class Phreezer extends Observable
 		$this->_level1Cache = new CacheRam();
 		$this->_level2Cache = new CacheNoCache();
 
-		parent::AttachObserver($observer);
+		if ($observer) parent::AttachObserver($observer);
 		$this->Observe("Phreeze Instantiated", OBSERVE_DEBUG);
 
 		$this->DataAdapter = new DataAdapter($csetting, $observer);
@@ -316,6 +313,7 @@ class Phreezer extends Observable
 
 		if (!$obj = $ds->Next())
 		{
+			require_once("NotFoundException.php");
 			throw new NotFoundException("$objectclass with specified criteria not found");
 		}
 
@@ -371,6 +369,7 @@ class Phreezer extends Observable
 			$fms = $this->GetFieldMaps($objectclass);
 
 			// the query builder will handle creating the SQL for us
+			require_once("QueryBuilder.php");
 			$builder = new QueryBuilder($this);
 			$builder->RecurseFieldMaps($objectclass, $fms);
 
@@ -379,6 +378,7 @@ class Phreezer extends Observable
 			$count_sql = $builder->GetCountSQL($criteria);
 		}
 
+		require_once("DataSet.php");
 		$ds = new DataSet($this, $objectclass, $sql, $cache_timeout);
 		$ds->CountSQL = $count_sql;
 
@@ -390,7 +390,7 @@ class Phreezer extends Observable
     * Get one instance of an object based on it's primary key value
     *
     * @access public
-    * @param string $objectclass the type of object that your DataSet will contain
+    * @param string $objectclass to query
     * @param variant $id the value of the primary key
     * @param int cache timeout (in seconds).  Default is Phreezer->ObjectCacheTimeout.  Set to 0 for no cache
     * @return Phreezable
@@ -422,11 +422,12 @@ class Phreezer extends Observable
 
 		$ds = $this->Query($objectclass, $criteria);
 
-		// tell the dataset that we will be able to cache this query
+		// this is cacheable
 		$ds->UnableToCache = false;
 
 		if (!$obj = $ds->Next())
 		{
+			require_once("NotFoundException.php");
 			throw new NotFoundException("$objectclass with primary key of $id not found");
 		}
 
@@ -488,15 +489,15 @@ class Phreezer extends Observable
 				{
 					$prop = $fm->PropertyName;
 					$val = $obj->$prop;
-
-					try
-					{
-						$sql .= $delim . "`" . $fm->ColumnName . "` = " . $this->GetQuotedSql($val);
-					}
-					catch (Exception $ex)
-					{
-						throw new Exception("Error escaping property '$prop'. value could not be converted to string");
-					}
+
+					try
+					{
+						$sql .= $delim . "`" . $fm->ColumnName . "` = " . $this->GetQuotedSql($val);
+					}
+					catch (Exception $ex)
+					{
+						throw new Exception("Error escaping property '$prop'. value could not be converted to string");
+					}
 
 					$delim = ", ";
 				}
@@ -539,15 +540,15 @@ class Phreezer extends Observable
 					if ($fm->FieldType != FM_CALCULATION)
 					{
 						$prop = $fm->PropertyName;
-						$val = $obj->$prop;
-
-						try
-						{
-							$sql .= $delim . ' ' . $this->GetQuotedSql($val);
-						}
-						catch (Exception $ex)
-						{
-							throw new Exception("Error escaping property '$prop'. value could not be converted to string");
+						$val = $obj->$prop;
+
+						try
+						{
+							$sql .= $delim . ' ' . $this->GetQuotedSql($val);
+						}
+						catch (Exception $ex)
+						{
+							throw new Exception("Error escaping property '$prop'. value could not be converted to string");
 						}
 
 						$delim = ", ";

+ 4 - 4
phreeze/libs/verysimple/String/VerySimpleStringUtil.php

@@ -59,10 +59,10 @@ class VerySimpleStringUtil
 
 		self::$SMART_QUOTE_CHARS =
 			array(
-				"Ô" => "'",
-				"Õ" => "'",
-				"Ò" => "\"",
-				"Ó" => "\"",
+				"�" => "'",
+				"�" => "'",
+				"�" => "\"",
+				"�" => "\"",
 				chr(145) => "'",
 				chr(146) => "'",
 				chr(147) => "\"",