summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe.Boulain <>2009-07-15 09:01:05 +0000
committerChristophe.Boulain <>2009-07-15 09:01:05 +0000
commit3ba065922fadd3dfc9e60014690e139a5568f8a9 (patch)
tree232f99f1a77b64def015fce4445bf572773f93ca
parentf1c27f46100582a1e52a27b616bf468e849068e7 (diff)
Merging latests 3.1 changes into trunk
-rw-r--r--HISTORY9
-rw-r--r--framework/Caching/TDbCache.php76
-rw-r--r--framework/PradoBase.php47
-rw-r--r--framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js2
-rw-r--r--framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js2
-rw-r--r--framework/Web/THttpResponse.php44
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php4
-rw-r--r--framework/Web/UI/TPage.php31
8 files changed, 172 insertions, 43 deletions
diff --git a/HISTORY b/HISTORY
index e9389dfd..f5bc8fb0 100644
--- a/HISTORY
+++ b/HISTORY
@@ -1,15 +1,24 @@
Version 3.2 to be released
NEW: Issue#83 - PHP configuration style (Carl)
+NEW: Port Yii's DBO (Christophe)
+NEW: Port Yii's ActiveRecords (Robin)
+NEW: Port Yii's Models and Behaviors (Robin)
Version 3.1.6 to be released
BUG: Issue#98 - Missing file in quickstart demo (Chrisotphe)
+BUG: Issue#115 - Clientside registry of serverside controls don't cover all controls: Prado.WebUI.TAutoComplete, Prado.WebUI.TInPlaceTextBox (Yves)
BUG: Issue#117 - Consider TValidationSummary.DisplayMode="HeaderOnly" if TValidationSummary.ShowMessageBox is set (Yves)
BUG: Issue#164 - CultureInfo::validCulture should be declared as a static method (Christophe)
BUG: Issue#168 - TSqlMapXmlConfiguration: CacheModel properties are not set (Yves)
+BUG: Issue#172 - TDbCache fails to recognize need to re-create cache table (Yves)
ENH: Issue#174 - TErrorHandler: HTTP error messages contains sensitive information (Yves)
ENH: Issue#175 - TBulletedList: Introduce TBulletStyle::None (Yves)
+ENH: Issue#176 - THttpResponse::writeFile() add additional parameters to take more influence on behavior (forceDownload, clientFileName, fileSize), add png to defaultMimeTypes (Yves)
+BUG: TCallbackErrorHandler::displayException() force HTTP status "500 Internal Server Error" to ensure TCallbackOptions.ClientSide.OnFailure is raised (Yves)
ENH: TAssetManager: introduce protected property "Published" to allow subclasses access (Yves)
ENH: TFirePhpLogRoute: bypass to TBrowserLogRoute if headers already sent / php.ini (output_buffering=Off, implicit_flush=On) (Yves)
+EHN: Performance optimization in PradoBase::createComponent() (Yves)
+EHN: Add property TPage.EnableStateCompression and related modifications in TPageStateFormatter since it is unnecessary to compress clientstate if TCachePageStatePersister/TSessionPageStatePersister is used (Yves)
Version 3.1.5 May 24, 2009
BUG: Issue#55 - TPropertyAccess.get and has don't recognize magic getter __get (Yves)
diff --git a/framework/Caching/TDbCache.php b/framework/Caching/TDbCache.php
index 376ff249..8ea8eae9 100644
--- a/framework/Caching/TDbCache.php
+++ b/framework/Caching/TDbCache.php
@@ -174,22 +174,28 @@ class TDbCache extends TCache
* If {@link setAutoCreateCacheTable AutoCreateCacheTableName} is 'true' check existence of cache table
* and create table if does not exist.
*
+ * @param boolean Force override global state check
* @return void
* @throws TConfigurationException if any error happens during creating database or cache table.
* @since 3.1.5
*/
- protected function initializeCache()
+ protected function initializeCache($force=false)
{
- if($this->_cacheInitialized) return;
-
+ if($this->_cacheInitialized && !$force) return;
$db=$this->getDbConnection();
$db->setActive(true);
try
{
$key = 'TDbCache:' . $this->_cacheTable . ':created';
- $this -> _createCheck = $this -> getApplication() -> getGlobalState($key, 0);
+ if($force)
+ $this -> _createCheck = false;
+ else
+ $this -> _createCheck = $this -> getApplication() -> getGlobalState($key, 0);
if($this->_autoCreate && !$this -> _createCheck) {
+
+ Prado::trace(($force ? 'Force initializing: ' : 'Initializing: ') . $this -> id . ', ' . $this->_cacheTable, 'System.Caching.TDbCache');
+
$sql='SELECT 1 FROM '.$this->_cacheTable.' WHERE 0';
$db->createCommand($sql)->queryScalar();
@@ -202,6 +208,8 @@ class TDbCache extends TCache
// DB table not exists
if($this->_autoCreate)
{
+ Prado::trace('Autocreate: ' . $this->_cacheTable, 'System.Caching.TDbCache');
+
$driver=$db->getDriverName();
if($driver==='mysql')
$blob='LONGBLOB';
@@ -246,6 +254,7 @@ class TDbCache extends TCache
if($force || $next <= $now)
{
if(!$this->_cacheInitialized) $this->initializeCache();
+ Prado::trace(($force ? 'Force flush of expired items: ' : 'Flush expired items: ') . $this -> id . ', ' . $this->_cacheTable, 'System.Caching.TDbCache');
$sql='DELETE FROM '.$this->_cacheTable.' WHERE expire<>0 AND expire<'.$now;
$this->getDbConnection()->createCommand($sql)->execute();
$this -> getApplication() -> setGlobalState($key, $now);
@@ -453,8 +462,16 @@ class TDbCache extends TCache
protected function getValue($key)
{
if(!$this->_cacheInitialized) $this->initializeCache();
- $sql='SELECT value FROM '.$this->_cacheTable.' WHERE itemkey=\''.$key.'\' AND (expire=0 OR expire>'.time().') ORDER BY expire DESC';
- return $this->_db->createCommand($sql)->queryScalar();
+ try {
+ $sql='SELECT value FROM '.$this->_cacheTable.' WHERE itemkey=\''.$key.'\' AND (expire=0 OR expire>'.time().') ORDER BY expire DESC';
+ $command=$this->_db->createCommand($sql);
+ return $command->queryScalar();
+ }
+ catch(Exception $e)
+ {
+ $this->initializeCache(true);
+ return $command->queryScalar();
+ }
}
/**
@@ -496,7 +513,16 @@ class TDbCache extends TCache
}
catch(Exception $e)
{
- return false;
+ try
+ {
+ $this->initializeCache(true);
+ $command->execute();
+ return true;
+ }
+ catch(Exception $e)
+ {
+ return false;
+ }
}
}
@@ -509,10 +535,19 @@ class TDbCache extends TCache
protected function deleteValue($key)
{
if(!$this->_cacheInitialized) $this->initializeCache();
- $command=$this->_db->createCommand("DELETE FROM {$this->_cacheTable} WHERE itemkey=:key");
- $command->bindValue(':key',$key,PDO::PARAM_STR);
- $command->execute();
- return true;
+ try
+ {
+ $command=$this->_db->createCommand("DELETE FROM {$this->_cacheTable} WHERE itemkey=:key");
+ $command->bindValue(':key',$key,PDO::PARAM_STR);
+ $command->execute();
+ return true;
+ }
+ catch(Exception $e)
+ {
+ $this->initializeCache(true);
+ $command->execute();
+ return true;
+ }
}
/**
@@ -522,7 +557,24 @@ class TDbCache extends TCache
public function flush()
{
if(!$this->_cacheInitialized) $this->initializeCache();
- $this->_db->createCommand("DELETE FROM {$this->_cacheTable}")->execute();
+ try
+ {
+ $command = $this->_db->createCommand("DELETE FROM {$this->_cacheTable}");
+ $command->execute();
+ }
+ catch(Exception $e)
+ {
+ try
+ {
+ $this->initializeCache(true);
+ $command->execute();
+ return true;
+ }
+ catch(Exception $e)
+ {
+ return false;
+ }
+ }
return true;
}
}
diff --git a/framework/PradoBase.php b/framework/PradoBase.php
index 084dd62b..3bf747df 100644
--- a/framework/PradoBase.php
+++ b/framework/PradoBase.php
@@ -62,6 +62,11 @@ class PradoBase
private static $_logger=null;
/**
+ * @var array list of class exists checks
+ */
+ protected static $classExists = array();
+
+ /**
* @return string the version of Prado framework
*/
public static function getVersion()
@@ -226,17 +231,41 @@ class PradoBase
*/
public static function createComponent($type)
{
- self::using($type);
- if(($pos=strrpos($type,'.'))!==false)
- $type=substr($type,$pos+1);
+ if(!isset(self::$classExists[$type]))
+ self::$classExists[$type] = class_exists($type, false);
+
+ if( !isset(self::$_usings[$type]) && !self::$classExists[$type]) {
+ self::using($type);
+ self::$classExists[$type] = class_exists($type, false);
+ }
+
+ if( ($pos = strrpos($type, '.')) !== false)
+ $type = substr($type,$pos+1);
+
if(($n=func_num_args())>1)
{
- $args=func_get_args();
- $s='$args[1]';
- for($i=2;$i<$n;++$i)
- $s.=",\$args[$i]";
- eval("\$component=new $type($s);");
- return $component;
+ $args = func_get_args();
+ switch($n) {
+ case 2:
+ return new $type($args[1]);
+ break;
+ case 3:
+ return new $type($args[1], $args[2]);
+ break;
+ case 4:
+ return new $type($args[1], $args[2], $args[3]);
+ break;
+ case 5:
+ return new $type($args[1], $args[2], $args[3], $args[4]);
+ break;
+ default:
+ $s='$args[1]';
+ for($i=2;$i<$n;++$i)
+ $s.=",\$args[$i]";
+ eval("\$component=new $type($s);");
+ return $component;
+ break;
+ }
}
else
return new $type;
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js
index 5402c4e7..56395d44 100644
--- a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js
@@ -110,6 +110,8 @@ Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete,
if(options.AutoPostBack)
this.onInit(options);
+
+ Prado.Registry.set(options.ID, this);
},
doCallback : function(event, options)
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js b/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js
index 51e3f489..052a18b0 100644
--- a/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js
@@ -18,6 +18,8 @@ Prado.WebUI.TInPlaceTextBox = Base.extend(
Prado.WebUI.TInPlaceTextBox.register(this);
this.createEditorInput();
this.initializeListeners();
+
+ Prado.Registry.set(options.ID, this);
},
/**
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php
index e3373855..3222f22f 100644
--- a/framework/Web/THttpResponse.php
+++ b/framework/Web/THttpResponse.php
@@ -43,7 +43,7 @@ Prado::using('System.Web.THttpResponseAdapter');
* or {@link TGlobalization::setCharset() TGlobalization.Charset} is set.
*
* Since 3.1.2, HTTP status code can be set with the {@link setStatusCode StatusCode} property.
- *
+ *
* Note: Some HTTP Status codes can require additional header or body information. So, if you use {@link setStatusCode StatusCode}
* in your application, be sure to add theses informations.
* E.g : to make an http authentication :
@@ -53,12 +53,12 @@ Prado::using('System.Web.THttpResponseAdapter');
* $response=$this->getResponse();
* $response->setStatusCode(401);
* $response->appendHeader('WWW-Authenticate: Basic realm="Test"');
- * }
+ * }
* </code>
- *
+ *
* This event handler will sent the 401 status code (Unauthorized) to the browser, with the WWW-Authenticate header field. This
* will force the browser to ask for a username and a password.
- *
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package System.Web
@@ -70,10 +70,10 @@ class THttpResponse extends TModule implements ITextWriter
* @var The differents defined status code by RFC 2616 {@link http://www.faqs.org/rfcs/rfc2616}
*/
private static $HTTP_STATUS_CODES = array(
- 100 => 'Continue', 101 => 'Switching Protocols',
- 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
- 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect',
- 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
+ 100 => 'Continue', 101 => 'Switching Protocols',
+ 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
+ 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect',
+ 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported'
);
@@ -259,7 +259,7 @@ class THttpResponse extends TModule implements ITextWriter
* Set the HTTP status code for the response.
* The code and its reason will be sent to client using the currently requested http protocol version (see {@link THttpRequest::getHttpProtocolVersion})
* Keep in mind that HTTP/1.0 clients might not understand all status codes from HTTP/1.1
- *
+ *
* @param integer HTTP status code
* @param string HTTP status reason, defaults to standard HTTP reasons
*/
@@ -315,13 +315,17 @@ class THttpResponse extends TModule implements ITextWriter
* @param string content to be set. If null, the content will be read from the server file pointed to by $fileName.
* @param string mime type of the content.
* @param array list of headers to be sent. Each array element represents a header string (e.g. 'Content-Type: text/plain').
+ * @param boolean force download of file, even if browser able to display inline. Defaults to 'true'.
+ * @param string force a specific file name on client side. Defaults to 'null' means auto-detect.
+ * @param integer size of file or content in bytes if already known. Defaults to 'null' means auto-detect.
* @throws TInvalidDataValueException if the file cannot be found
*/
- public function writeFile($fileName,$content=null,$mimeType=null,$headers=null)
+ public function writeFile($fileName,$content=null,$mimeType=null,$headers=null,$forceDownload=true,$clientFileName=null,$fileSize=null)
{
static $defaultMimeTypes=array(
'css'=>'text/css',
'gif'=>'image/gif',
+ 'png'=>'image/png',
'jpg'=>'image/jpeg',
'jpeg'=>'image/jpeg',
'htm'=>'text/html',
@@ -343,7 +347,15 @@ class THttpResponse extends TModule implements ITextWriter
$mimeType=$defaultMimeTypes[$ext];
}
}
- $fn=basename($fileName);
+
+ if($clientFileName===null)
+ $clientFileName=basename($fileName);
+ else
+ $clientFileName=basename($clientFileName);
+
+ if($fileSize===null || $fileSize < 0)
+ $fileSize = ($content===null?filesize($fileName):strlen($content));
+
$this->sendHttpHeader();
if(is_array($headers))
{
@@ -357,8 +369,8 @@ class THttpResponse extends TModule implements ITextWriter
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
}
header("Content-type: $mimeType");
- header('Content-Length: '.($content===null?filesize($fileName):strlen($content)));
- header("Content-Disposition: attachment; filename=\"$fn\"");
+ header('Content-Length: '.$fileSize);
+ header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\"");
header('Content-Transfer-Encoding: binary');
if($content===null)
readfile($fileName);
@@ -388,7 +400,7 @@ class THttpResponse extends TModule implements ITextWriter
* You can set the set {@link setStatusCode StatusCode} to a value between 300 and 399 before
* calling this function to change the type of redirection.
* If not specified, StatusCode will be 302 (Found) by default
- *
+ *
* @param string URL to be redirected to. If the URL is a relative one, the base URL of
* the current request will be inserted at the beginning.
*/
@@ -403,7 +415,7 @@ class THttpResponse extends TModule implements ITextWriter
header('Location: '.str_replace('&amp;','&',$url), true, $this->_status);
else
header('Location: '.str_replace('&amp;','&',$url));
-
+
exit();
}
@@ -440,7 +452,7 @@ class THttpResponse extends TModule implements ITextWriter
if($this->_bufferOutput)
ob_flush();
}
-
+
/**
* Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)
*/
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
index 90eed970..b91da695 100644
--- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -316,13 +316,13 @@ class TCallbackErrorHandler extends TErrorHandler
{
$response = $this->getApplication()->getResponse();
$trace = TJavaScript::jsonEncode($this->getExceptionStackTrace($exception));
- $response->appendHeader('HTTP/1.0 500 Internal Error');
+ $response->setStatusCode(500, 'Internal Server Error');
$response->appendHeader(TActivePageAdapter::CALLBACK_ERROR_HEADER.': '.$trace);
}
else
{
error_log("Error happened while processing an existing error:\n".$exception->__toString());
- header('HTTP/1.0 500 Internal Error');
+ header('HTTP/1.0 500 Internal Server Error', true, 500);
}
$this->getApplication()->getResponse()->flush();
}
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 12433715..6f7e533d 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -134,6 +134,11 @@ class TPage extends TTemplateControl
*/
private $_enableStateEncryption=false;
/**
+ * @var boolean whether page state should be compressed
+ * @since 3.1.6
+ */
+ private $_enableStateCompression=true;
+ /**
* @var string page state persister class name
*/
private $_statePersisterClass='System.Web.UI.TPageStatePersister';
@@ -283,7 +288,7 @@ class TPage extends TTemplateControl
$this->setAdapter(new TActivePageAdapter($this));
// Decode Callback postData from UTF-8 to current Charset
- if (($g=$this->getApplication()->getGlobalization(false))!==null &&
+ if (($g=$this->getApplication()->getGlobalization(false))!==null &&
strtoupper($enc=$g->getCharset())!='UTF-8')
foreach ($this->_postData as $k=>$v)
$this->_postData[$k]=iconv('UTF-8',$enc.'//IGNORE',$v);
@@ -1124,6 +1129,24 @@ class TPage extends TTemplateControl
}
/**
+ * @return boolean whether page state should be compressed. Defaults to true.
+ * @since 3.1.6
+ */
+ public function getEnableStateCompression()
+ {
+ return $this->_enableStateCompression;
+ }
+
+ /**
+ * @param boolean whether page state should be compressed.
+ * @since 3.1.6
+ */
+ public function setEnableStateCompression($value)
+ {
+ $this->_enableStateCompression=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
* @return string the requested page path for this page
*/
public function getPagePath()
@@ -1234,7 +1257,7 @@ class TPageStateFormatter
$str=$sm->hashData(Prado::serialize($data));
else
$str=Prado::serialize($data);
- if(extension_loaded('zlib'))
+ if($page->getEnableStateCompression() && extension_loaded('zlib'))
$str=gzcompress($str);
if($page->getEnableStateEncryption())
$str=$sm->encrypt($str);
@@ -1256,7 +1279,7 @@ class TPageStateFormatter
$sm=$page->getApplication()->getSecurityManager();
if($page->getEnableStateEncryption())
$str=$sm->decrypt($str);
- if(extension_loaded('zlib'))
+ if($page->getEnableStateCompression() && extension_loaded('zlib'))
$str=@gzuncompress($str);
if($page->getEnableStateValidation())
{
@@ -1270,4 +1293,4 @@ class TPageStateFormatter
}
}
-?>
+?> \ No newline at end of file