Commit c2252422 by Qiang Xue

working on caching.

parent 0c85d56b
...@@ -34,7 +34,7 @@ class ErrorHandler extends ApplicationComponent ...@@ -34,7 +34,7 @@ class ErrorHandler extends ApplicationComponent
public $discardExistingOutput = true; public $discardExistingOutput = true;
/** /**
* @var string the route (eg 'site/error') to the controller action that will be used to display external errors. * @var string the route (eg 'site/error') to the controller action that will be used to display external errors.
* Inside the action, it can retrieve the error information by Yii::app()->errorHandler->error. * Inside the action, it can retrieve the error information by \Yii::$application->errorHandler->error.
* This property defaults to null, meaning ErrorHandler will handle the error display. * This property defaults to null, meaning ErrorHandler will handle the error display.
*/ */
public $errorAction; public $errorAction;
......
<?php
/**
* CInlineFilter class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/**
* CInlineFilter represents a filter defined as a controller method.
*
* CInlineFilter executes the 'filterXYZ($action)' method defined
* in the controller, where the name 'XYZ' can be retrieved from the {@link name} property.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.web.filters
* @since 1.0
*/
class CInlineFilter extends CFilter
{
/**
* @var string name of the filter. It stands for 'XYZ' in the filter method name 'filterXYZ'.
*/
public $name;
/**
* Creates an inline filter instance.
* The creation is based on a string describing the inline method name
* and action names that the filter shall or shall not apply to.
* @param CController $controller the controller who hosts the filter methods
* @param string $filterName the filter name
* @return CInlineFilter the created instance
* @throws CException if the filter method does not exist
*/
public static function create($controller,$filterName)
{
if(method_exists($controller,'filter'.$filterName))
{
$filter=new CInlineFilter;
$filter->name=$filterName;
return $filter;
}
else
throw new CException(Yii::t('yii','Filter "{filter}" is invalid. Controller "{class}" does not have the filter method "filter{filter}".',
array('{filter}'=>$filterName, '{class}'=>get_class($controller))));
}
/**
* Performs the filtering.
* This method calls the filter method defined in the controller class.
* @param CFilterChain $filterChain the filter chain that the filter is on.
*/
public function filter($filterChain)
{
$method='filter'.$this->name;
$filterChain->controller->$method($filterChain);
}
}
...@@ -99,13 +99,13 @@ class SecurityManager extends ApplicationComponent ...@@ -99,13 +99,13 @@ class SecurityManager extends ApplicationComponent
return $this->_validationKey; return $this->_validationKey;
} }
else { else {
if (($key = Yii::app()->getGlobalState(self::STATE_VALIDATION_KEY)) !== null) { if (($key = \Yii::$application->getGlobalState(self::STATE_VALIDATION_KEY)) !== null) {
$this->setValidationKey($key); $this->setValidationKey($key);
} }
else { else {
$key = $this->generateRandomKey(); $key = $this->generateRandomKey();
$this->setValidationKey($key); $this->setValidationKey($key);
Yii::app()->setGlobalState(self::STATE_VALIDATION_KEY, $key); \Yii::$application->setGlobalState(self::STATE_VALIDATION_KEY, $key);
} }
return $this->_validationKey; return $this->_validationKey;
} }
...@@ -135,13 +135,13 @@ class SecurityManager extends ApplicationComponent ...@@ -135,13 +135,13 @@ class SecurityManager extends ApplicationComponent
return $this->_encryptionKey; return $this->_encryptionKey;
} }
else { else {
if (($key = Yii::app()->getGlobalState(self::STATE_ENCRYPTION_KEY)) !== null) { if (($key = \Yii::$application->getGlobalState(self::STATE_ENCRYPTION_KEY)) !== null) {
$this->setEncryptionKey($key); $this->setEncryptionKey($key);
} }
else { else {
$key = $this->generateRandomKey(); $key = $this->generateRandomKey();
$this->setEncryptionKey($key); $this->setEncryptionKey($key);
Yii::app()->setGlobalState(self::STATE_ENCRYPTION_KEY, $key); \Yii::$application->setGlobalState(self::STATE_ENCRYPTION_KEY, $key);
} }
return $this->_encryptionKey; return $this->_encryptionKey;
} }
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CApcCache class file * CApcCache class file
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CApcCache provides APC caching in terms of an application component. * CApcCache provides APC caching in terms of an application component.
* *
...@@ -17,9 +18,7 @@ ...@@ -17,9 +18,7 @@
* See {@link CCache} manual for common cache operations that are supported by CApcCache. * See {@link CCache} manual for common cache operations that are supported by CApcCache.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
* @since 1.0
*/ */
class CApcCache extends CCache class CApcCache extends CCache
{ {
......
<?php <?php
/** /**
* CCache class file. * Cache class file.
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
use yii\base\ApplicationComponent;
use yii\base\Exception;
/** /**
* CCache is the base class for cache classes with different cache storage implementation. * Cache is the base class for cache classes with different cache storage implementation.
* *
* A data item can be stored in cache by calling {@link set} and be retrieved back * A data item can be stored in cache by calling {@link set} and be retrieved back
* later by {@link get}. In both operations, a key identifying the data item is required. * later by {@link get}. In both operations, a key identifying the data item is required.
...@@ -20,7 +24,7 @@ ...@@ -20,7 +24,7 @@
* Note, by definition, cache does not ensure the existence of a value * Note, by definition, cache does not ensure the existence of a value
* even if it does not expire. Cache is not meant to be a persistent storage. * even if it does not expire. Cache is not meant to be a persistent storage.
* *
* CCache implements the interface {@link ICache} with the following methods: * Cache implements the interface {@link ICache} with the following methods:
* <ul> * <ul>
* <li>{@link get} : retrieve the value with a key (if any) from cache</li> * <li>{@link get} : retrieve the value with a key (if any) from cache</li>
* <li>{@link set} : store the value with a key into cache</li> * <li>{@link set} : store the value with a key into cache</li>
...@@ -40,12 +44,10 @@ ...@@ -40,12 +44,10 @@
* <li>{@link unserializeValue} (optional)</li> * <li>{@link unserializeValue} (optional)</li>
* </ul> * </ul>
* *
* CCache also implements ArrayAccess so that it can be used like an array. * Cache also implements ArrayAccess so that it can be used like an array.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
* @since 1.0
*/ */
abstract class Cache extends ApplicationComponent implements \ArrayAccess abstract class Cache extends ApplicationComponent implements \ArrayAccess
{ {
...@@ -55,36 +57,25 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -55,36 +57,25 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* pool of cached data, the same prefix should be set for each of the applications explicitly. * pool of cached data, the same prefix should be set for each of the applications explicitly.
*/ */
public $keyPrefix; public $keyPrefix;
/** /**
* @var boolean whether to md5-hash the cache key for normalization purposes. Defaults to true. Setting this property to false makes sure the cache * @var boolean whether to hash the cache key for normalization purpose. Defaults to true.
* Setting this property to false makes sure the cache
* key will not be tampered when calling the relevant methods {@link get()}, {@link set()}, {@link add()} and {@link delete()}. This is useful if a Yii * key will not be tampered when calling the relevant methods {@link get()}, {@link set()}, {@link add()} and {@link delete()}. This is useful if a Yii
* application as well as an external application need to access the same cache pool (also see description of {@link keyPrefix} regarding this use case). * application as well as an external application need to access the same cache pool (also see description of {@link keyPrefix} regarding this use case).
* However, without normalization you should make sure the affected cache backend does support the structure (charset, length, etc.) of all the provided * However, without normalization you should make sure the affected cache backend does support the structure (charset, length, etc.) of all the provided
* cache keys, otherwise there might be unexpected behavior. * cache keys, otherwise there might be unexpected behavior.
* @since 1.1.11
**/ **/
public $hashKey = true; public $hashKey = true;
/**
* @var boolean whether to automatically serialize/unserialize the cache values. Defaults to true. Setting this property to false makes sure the cache
* value will not be tampered when calling the methods {@link set()} and {@link add()}. This is useful in case you want to store data which simply
* does not require serialization (e.g. integers, strings or raw binary data). Thus there might be a small increase in performance and a smaller overall
* cache size. Take in mind that you will be unable to store PHP structures like arrays or objects, you would have to serialize and unserialize them manually.
* Another negative side effect is that providing a dependency via {@link set()} or {@link add()} will have no effect since dependencies rely on serialization.
* Since all the relevant core application components rely on dependency support, you should be very careful disabling this feature. Usually you want to
* configure a dedicated cache component for the sole purpose of storing raw unserialized data, the main cache component should always support serialization.
* @since 1.1.11
**/
public $autoSerialize = true;
/** /**
* @var boolean wether to make use of the {@link http://pecl.php.net/package/igbinary igbinary} serializer for cache entry serialization. Defaults to false. * @var array|boolean the functions used to serialize and unserialize cached data. Defaults to null, meaning
* <strong>NOTE:</strong> If this is set to true while the igbinary extension has not been loaded, cache serialization will silently fall back to PHP's default * using the default PHP `serialize()` and `unserialize()` functions. If you want to use some more efficient
* serializer. Since the two serialization formats are incompatible, caches should be purged before switching this on to prevent errors. * serializer (e.g. [igbinary](http://pecl.php.net/package/igbinary)), you may configure this property with
* @since 1.1.11 * a two-element array. The first element specifies the serialization function, and the second the deserialization
* function. If this property is set false, data will be directly sent to and retrieved from the underlying
* cache component without any serialization or deserialization. You should not turn off serialization if
* you are using [[CacheDependency|cache dependency]], because it relies on data serialization.
*/ */
public $useIgbinarySerializer = false; public $serializer;
/** /**
* Initializes the application component. * Initializes the application component.
...@@ -94,16 +85,15 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -94,16 +85,15 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
{ {
parent::init(); parent::init();
if ($this->keyPrefix === null) { if ($this->keyPrefix === null) {
$this->keyPrefix = Yii::app()->getId(); $this->keyPrefix = \Yii::$application->id;
} }
$this->useIgbinarySerializer = $this->useIgbinarySerializer && extension_loaded('igbinary');
} }
/** /**
* @param string $key a key identifying a value to be cached * @param string $key a key identifying a value to be cached
* @return sring a key generated from the provided key which ensures the uniqueness across applications * @return string a key generated from the provided key which ensures the uniqueness across applications
*/ */
protected function generateUniqueKey($key) protected function generateCacheKey($key)
{ {
return $this->hashKey ? md5($this->keyPrefix . $key) : $this->keyPrefix . $key; return $this->hashKey ? md5($this->keyPrefix . $key) : $this->keyPrefix . $key;
} }
...@@ -111,18 +101,24 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -111,18 +101,24 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
/** /**
* Retrieves a value from cache with a specified key. * Retrieves a value from cache with a specified key.
* @param string $id a key identifying the cached value * @param string $id a key identifying the cached value
* @return mixed the value stored in cache, false if the value is not in the cache, expired or the dependency has changed. * @return mixed the value stored in cache, false if the value is not in the cache, expired,
* or the dependency associated with the cached data has changed.
*/ */
public function get($id) public function get($id)
{ {
if (($value = $this->getValue($this->generateUniqueKey($id))) !== false) { $value = $this->getValue($this->generateCacheKey($id));
$data = $this->autoSerialize ? $this->unserializeValue($value) : $value; if ($value === false || $this->serializer === false) {
if (!$this->autoSerialize || (is_array($data) && (!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()))) { return $value;
Yii::trace('Serving "' . $id . '" from cache', 'system.caching.' . get_class($this)); } elseif ($this->serializer === null) {
return $this->autoSerialize ? $data[0] : $data; $value = unserialize($value);
} } else {
$value = call_user_func($this->serializer[1], $value);
}
if (is_array($value) && ($value[1] instanceof CacheDependency) || !$value[1]->getHasChanged()) {
return $value[0];
} else {
return false;
} }
return false;
} }
/** /**
...@@ -135,23 +131,27 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -135,23 +131,27 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* is returned in terms of (key,value) pairs. * is returned in terms of (key,value) pairs.
* If a value is not cached or expired, the corresponding array value will be false. * If a value is not cached or expired, the corresponding array value will be false.
*/ */
public function mget($ids) public function mget(array $ids)
{ {
$uniqueIDs = array(); $uids = array();
$results = array();
foreach ($ids as $id) { foreach ($ids as $id) {
$uniqueIDs[$id] = $this->generateUniqueKey($id); $uids[$id] = $this->generateCacheKey($id);
$results[$id] = false;
} }
$values = $this->getValues($uniqueIDs); $values = $this->getValues($uids);
foreach ($uniqueIDs as $id => $uniqueID) { $results = array();
if (!isset($values[$uniqueID])) { if ($this->serializer === false) {
continue; foreach ($uids as $id => $uid) {
$results[$id] = isset($values[$uid]) ? $values[$uid] : false;
} }
$data = $this->autoSerialize ? $this->unserializeValue($values[$uniqueID]) : $values[$uniqueID]; } else {
if (!$this->autoSerialize || (is_array($data) && (!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()))) { foreach ($uids as $id => $uid) {
Yii::trace('Serving "' . $id . '" from cache', 'system.caching.' . get_class($this)); $results[$id] = false;
$results[$id] = $this->autoSerialize ? $data[0] : $data; if (isset($values[$uid])) {
$value = $this->serializer === null ? unserialize($values[$uid]) : call_user_func($this->serializer[1], $values[$uid]);
if (is_array($value) && (!($value[1] instanceof CacheDependency) || !$value[1]->getHasChanged())) {
$results[$id] = $value[0];
}
}
} }
} }
return $results; return $results;
...@@ -165,17 +165,20 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -165,17 +165,20 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* @param string $id the key identifying the value to be cached * @param string $id the key identifying the value to be cached
* @param mixed $value the value to be cached * @param mixed $value the value to be cached
* @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire. * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
* @param ICacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labeled invalid. * @param CacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labeled invalid.
* @return boolean true if the value is successfully stored into cache, false otherwise * @return boolean true if the value is successfully stored into cache, false otherwise
*/ */
public function set($id, $value, $expire = 0, $dependency = null) public function set($id, $value, $expire = 0, $dependency = null)
{ {
Yii::trace('Saving "' . $id . '" to cache', 'system.caching.' . get_class($this)); if ($dependency !== null && $this->serializer !== false) {
if ($dependency !== null && $this->autoSerialize) {
$dependency->evaluateDependency(); $dependency->evaluateDependency();
} }
$data = $this->autoSerialize ? $this->serializeValue(array($value, $dependency)) : $value; if ($this->serializer === null) {
return $this->setValue($this->generateUniqueKey($id), $data, $expire); $value = array(serialize($value), $dependency);
} elseif ($this->serializer !== false) {
$value = array(call_user_func($this->serializer[0], $value), $dependency);
}
return $this->setValue($this->generateCacheKey($id), $value, $expire);
} }
/** /**
...@@ -184,17 +187,20 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -184,17 +187,20 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* @param string $id the key identifying the value to be cached * @param string $id the key identifying the value to be cached
* @param mixed $value the value to be cached * @param mixed $value the value to be cached
* @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire. * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
* @param ICacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labeled invalid. * @param CacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labeled invalid.
* @return boolean true if the value is successfully stored into cache, false otherwise * @return boolean true if the value is successfully stored into cache, false otherwise
*/ */
public function add($id, $value, $expire = 0, $dependency = null) public function add($id, $value, $expire = 0, $dependency = null)
{ {
Yii::trace('Adding "' . $id . '" to cache', 'system.caching.' . get_class($this)); if ($dependency !== null && $this->serializer !== false) {
if ($dependency !== null && $this->autoSerialize) {
$dependency->evaluateDependency(); $dependency->evaluateDependency();
} }
$data = $this->autoSerialize ? $this->serializeValue(array($value, $dependency)) : $value; if ($this->serializer === null) {
return $this->addValue($this->generateUniqueKey($id), $data, $expire); $value = array(serialize($value), $dependency);
} elseif ($this->serializer !== false) {
$value = array(call_user_func($this->serializer[0], $value), $dependency);
}
return $this->addValue($this->generateCacheKey($id), $value, $expire);
} }
/** /**
...@@ -204,8 +210,7 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -204,8 +210,7 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
*/ */
public function delete($id) public function delete($id)
{ {
Yii::trace('Deleting "' . $id . '" from cache', 'system.caching.' . get_class($this)); return $this->deleteValue($this->generateCacheKey($id));
return $this->deleteValue($this->generateUniqueKey($id));
} }
/** /**
...@@ -215,7 +220,6 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -215,7 +220,6 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
*/ */
public function flush() public function flush()
{ {
Yii::trace('Flushing cache', 'system.caching.' . get_class($this));
return $this->flushValues(); return $this->flushValues();
} }
...@@ -227,12 +231,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -227,12 +231,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* is needed. * is needed.
* @param string $key a unique key identifying the cached value * @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired. * @return string the value stored in cache, false if the value is not in the cache or expired.
* @throws CException if this method is not overridden by child classes
*/ */
protected function getValue($key) protected function getValue($key)
{ {
throw new CException(Yii::t('yii', '{className} does not support get() functionality.', return false;
array('{className}' => get_class($this))));
} }
/** /**
...@@ -264,12 +266,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -264,12 +266,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* @param string $value the value to be cached * @param string $value the value to be cached
* @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire. * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
* @return boolean true if the value is successfully stored into cache, false otherwise * @return boolean true if the value is successfully stored into cache, false otherwise
* @throws CException if this method is not overridden by child classes
*/ */
protected function setValue($key, $value, $expire) protected function setValue($key, $value, $expire)
{ {
throw new CException(Yii::t('yii', '{className} does not support set() functionality.', return true;
array('{className}' => get_class($this))));
} }
/** /**
...@@ -283,12 +283,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -283,12 +283,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* @param string $value the value to be cached * @param string $value the value to be cached
* @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire. * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
* @return boolean true if the value is successfully stored into cache, false otherwise * @return boolean true if the value is successfully stored into cache, false otherwise
* @throws CException if this method is not overridden by child classes
*/ */
protected function addValue($key, $value, $expire) protected function addValue($key, $value, $expire)
{ {
throw new CException(Yii::t('yii', '{className} does not support add() functionality.', return true;
array('{className}' => get_class($this))));
} }
/** /**
...@@ -296,61 +294,20 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -296,61 +294,20 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* This method should be implemented by child classes to delete the data from actual cache storage. * This method should be implemented by child classes to delete the data from actual cache storage.
* @param string $key the key of the value to be deleted * @param string $key the key of the value to be deleted
* @return boolean if no error happens during deletion * @return boolean if no error happens during deletion
* @throws CException if this method is not overridden by child classes
*/ */
protected function deleteValue($key) protected function deleteValue($key)
{ {
throw new CException(Yii::t('yii', '{className} does not support delete() functionality.', return true;
array('{className}' => get_class($this))));
} }
/** /**
* Deletes all values from cache. * Deletes all values from cache.
* Child classes may implement this method to realize the flush operation. * Child classes may implement this method to realize the flush operation.
* @return boolean whether the flush operation was successful. * @return boolean whether the flush operation was successful.
* @throws CException if this method is not overridden by child classes
* @since 1.1.5
*/ */
protected function flushValues() protected function flushValues()
{ {
throw new CException(Yii::t('yii', '{className} does not support flushValues() functionality.', return true;
array('{className}' => get_class($this))));
}
/**
* Serializes the value before it will be stored in the actual cache backend.
* This method will be called if {@link autoSerialize} is set to true. Child classes may override this method to change
* the way the value is being serialized. The default implementation simply makes use of the PHP serialize() function
* unless {@link useIgbinarySerializer} is set to true and the igbinary extension is installed.
* Make sure to override {@link unserializeValue()} as well if you want to change the serialization process.
* @param mixed $value the unserialized representation of the value
* @return string the serialized representation of the value
* @since 1.1.11
**/
protected function serializeValue($value)
{
if ($this->useIgbinarySerializer) {
return igbinary_serialize($value);
}
return serialize($value);
}
/**
* Unserializes the value after it was retrieved from the actual cache backend.
* This method will be called if {@link autoSerialize} is set to true. Child classes may override this method to change
* the way the value is being unserialized. The default implementation simply makes use of the PHP unserialize() function
* unless {@link useIgbinarySerializer} is set to true and the igbinary extension is installed.
* Make sure to override {@link serializeValue()} as well if you want to change the serialization process.
* @param string $value the serialized representation of the value
* @return mixed the unserialized representation of the value
* @since 1.1.11
**/
protected function unserializeValue($value)
{
if ($this->useIgbinarySerializer) {
return igbinary_unserialize($value);
}
return unserialize($value);
} }
/** /**
...@@ -392,7 +349,6 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess ...@@ -392,7 +349,6 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* Deletes the value with the specified key from cache * Deletes the value with the specified key from cache
* This method is required by the interface ArrayAccess. * This method is required by the interface ArrayAccess.
* @param string $id the key of the value to be deleted * @param string $id the key of the value to be deleted
* @return boolean if no error happens during deletion
*/ */
public function offsetUnset($id) public function offsetUnset($id)
{ {
......
<?php
/**
* CacheDependency class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\caching;
/**
* CacheDependency is the base class for cache dependency classes.
*
* CacheDependency implements the {@link ICacheDependency} interface.
* Child classes should override its {@link generateDependentData} for
* actual dependency checking.
*
* @property boolean $hasChanged Whether the dependency has changed.
* @property mixed $dependentData The data used to determine if dependency has been changed.
* This data is available after {@link evaluateDependency} is called.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CacheDependency extends \yii\base\Object
{
/**
* @var boolean Whether this dependency is reusable or not.
* If set to true, dependent data for this cache dependency will only be generated once per request.
* You can then use the same cache dependency for multiple separate cache calls on the same page
* without the overhead of re-evaluating the dependency each time.
* Defaults to false;
* @since 1.1.11
*/
public $reuseDependentData = false;
/**
* @var array cached data for reusable dependencies.
* @since 1.1.11
*/
private static $_reusableData = array();
private $_hash;
private $_data;
/**
* Evaluates the dependency by generating and saving the data related with dependency.
* This method is invoked by cache before writing data into it.
*/
public function evaluateDependency()
{
if ($this->reuseDependentData) {
$hash = $this->getHash();
if (!isset(self::$_reusableData[$hash]['dependentData'])) {
self::$_reusableData[$hash]['dependentData'] = $this->generateDependentData();
}
$this->_data = self::$_reusableData[$hash]['dependentData'];
} else {
$this->_data = $this->generateDependentData();
}
}
/**
* @return boolean whether the dependency has changed.
*/
public function getHasChanged()
{
if ($this->reuseDependentData) {
$hash = $this->getHash();
if (!isset(self::$_reusableData[$hash]['hasChanged'])) {
if (!isset(self::$_reusableData[$hash]['dependentData'])) {
self::$_reusableData[$hash]['dependentData'] = $this->generateDependentData();
}
self::$_reusableData[$hash]['hasChanged'] = self::$_reusableData[$hash]['dependentData'] != $this->_data;
}
return self::$_reusableData[$hash]['hasChanged'];
} else {
return $this->generateDependentData() != $this->_data;
}
}
/**
* @return mixed the data used to determine if dependency has been changed.
* This data is available after {@link evaluateDependency} is called.
*/
public function getDependentData()
{
return $this->_data;
}
/**
* Generates the data needed to determine if dependency has been changed.
* Derived classes should override this method to generate actual dependent data.
* @return mixed the data needed to determine if dependency has been changed.
*/
protected function generateDependentData()
{
return null;
}
/**
* Generates a unique hash that identifies this cache dependency.
* @return string the hash for this cache dependency
*/
private function getHash()
{
if ($this->_hash === null) {
$this->_hash = sha1(serialize($this));
}
return $this->_hash;
}
}
\ No newline at end of file
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CChainedCacheDependency class file. * CChainedCacheDependency class file.
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CChainedCacheDependency represents a list of cache dependencies. * CChainedCacheDependency represents a list of cache dependencies.
* *
...@@ -22,9 +23,7 @@ ...@@ -22,9 +23,7 @@
* @property boolean $hasChanged Whether the dependency is changed or not. * @property boolean $hasChanged Whether the dependency is changed or not.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching.dependencies
* @since 1.0
*/ */
class CChainedCacheDependency extends CComponent implements ICacheDependency class CChainedCacheDependency extends CComponent implements ICacheDependency
{ {
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
/** /**
* CDbCache class file * CDbCache class file
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CDbCache implements a cache application component by storing cached data in a database. * CDbCache implements a cache application component by storing cached data in a database.
* *
...@@ -27,9 +29,7 @@ ...@@ -27,9 +29,7 @@
* @property CDbConnection $dbConnection The DB connection instance. * @property CDbConnection $dbConnection The DB connection instance.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
* @since 1.0
*/ */
class CDbCache extends CCache class CDbCache extends CCache
{ {
...@@ -150,7 +150,7 @@ EOD; ...@@ -150,7 +150,7 @@ EOD;
return $this->_db; return $this->_db;
else if(($id=$this->connectionID)!==null) else if(($id=$this->connectionID)!==null)
{ {
if(($this->_db=Yii::app()->getComponent($id)) instanceof CDbConnection) if(($this->_db=\Yii::$application->getComponent($id)) instanceof CDbConnection)
return $this->_db; return $this->_db;
else else
throw new CException(Yii::t('yii','CDbCache.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.', throw new CException(Yii::t('yii','CDbCache.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.',
...@@ -158,7 +158,7 @@ EOD; ...@@ -158,7 +158,7 @@ EOD;
} }
else else
{ {
$dbFile=Yii::app()->getRuntimePath().DIRECTORY_SEPARATOR.'cache-'.Yii::getVersion().'.db'; $dbFile=\Yii::$application->getRuntimePath().DIRECTORY_SEPARATOR.'cache-'.Yii::getVersion().'.db';
return $this->_db=new CDbConnection('sqlite:'.$dbFile); return $this->_db=new CDbConnection('sqlite:'.$dbFile);
} }
} }
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
/** /**
* CDbCacheDependency class file. * CDbCacheDependency class file.
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CDbCacheDependency represents a dependency based on the query result of a SQL statement. * CDbCacheDependency represents a dependency based on the query result of a SQL statement.
* *
...@@ -17,9 +19,7 @@ ...@@ -17,9 +19,7 @@
* component. It is this DB connection that is used to perform the query. * component. It is this DB connection that is used to perform the query.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching.dependencies
* @since 1.0
*/ */
class CDbCacheDependency extends CCacheDependency class CDbCacheDependency extends CCacheDependency
{ {
...@@ -102,7 +102,7 @@ class CDbCacheDependency extends CCacheDependency ...@@ -102,7 +102,7 @@ class CDbCacheDependency extends CCacheDependency
return $this->_db; return $this->_db;
else else
{ {
if(($this->_db=Yii::app()->getComponent($this->connectionID)) instanceof CDbConnection) if(($this->_db=\Yii::$application->getComponent($this->connectionID)) instanceof CDbConnection)
return $this->_db; return $this->_db;
else else
throw new CException(Yii::t('yii','CDbCacheDependency.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.', throw new CException(Yii::t('yii','CDbCacheDependency.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.',
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CCacheDependency class file. * CCacheDependency class file.
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CCacheDependency is the base class for cache dependency classes. * CCacheDependency is the base class for cache dependency classes.
* *
...@@ -20,9 +21,7 @@ ...@@ -20,9 +21,7 @@
* This data is available after {@link evaluateDependency} is called. * This data is available after {@link evaluateDependency} is called.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching.dependencies
* @since 1.0
*/ */
class CCacheDependency extends CComponent implements ICacheDependency class CCacheDependency extends CComponent implements ICacheDependency
{ {
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
/** /**
* CDirectoryCacheDependency class file. * CDirectoryCacheDependency class file.
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CDirectoryCacheDependency represents a dependency based on change of a directory. * CDirectoryCacheDependency represents a dependency based on change of a directory.
* *
...@@ -25,9 +27,7 @@ ...@@ -25,9 +27,7 @@
* accessing modification time of multiple files under the directory. * accessing modification time of multiple files under the directory.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching.dependencies
* @since 1.0
*/ */
class CDirectoryCacheDependency extends CCacheDependency class CDirectoryCacheDependency extends CCacheDependency
{ {
......
...@@ -2,24 +2,23 @@ ...@@ -2,24 +2,23 @@
/** /**
* CDummyCache class file. * CDummyCache class file.
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CDummyCache is a placeholder cache component. * CDummyCache is a placeholder cache component.
* *
* CDummyCache does not cache anything. It is provided so that one can always configure * CDummyCache does not cache anything. It is provided so that one can always configure
* a 'cache' application component and he does not need to check if Yii::app()->cache is null or not. * a 'cache' application component and he does not need to check if \Yii::$application->cache is null or not.
* By replacing CDummyCache with some other cache component, one can quickly switch from * By replacing CDummyCache with some other cache component, one can quickly switch from
* non-caching mode to caching mode. * non-caching mode to caching mode.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
* @since 1.0
*/ */
class CDummyCache extends CApplicationComponent implements ICache, ArrayAccess class CDummyCache extends CApplicationComponent implements ICache, ArrayAccess
{ {
...@@ -36,7 +35,7 @@ class CDummyCache extends CApplicationComponent implements ICache, ArrayAccess ...@@ -36,7 +35,7 @@ class CDummyCache extends CApplicationComponent implements ICache, ArrayAccess
{ {
parent::init(); parent::init();
if($this->keyPrefix===null) if($this->keyPrefix===null)
$this->keyPrefix=Yii::app()->getId(); $this->keyPrefix=\Yii::$application->getId();
} }
/** /**
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
/** /**
* CEAcceleratorCache class file * CEAcceleratorCache class file
* *
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CEAcceleratorCache implements a cache application module based on {@link http://eaccelerator.net/ eaccelerator}. * CEAcceleratorCache implements a cache application module based on {@link http://eaccelerator.net/ eaccelerator}.
* *
...@@ -18,9 +20,8 @@ ...@@ -18,9 +20,8 @@
* Please note that as of v0.9.6, eAccelerator no longer supports data caching. * Please note that as of v0.9.6, eAccelerator no longer supports data caching.
* This means if you still want to use this component, your eAccelerator should be of 0.9.5.x or lower version. * This means if you still want to use this component, your eAccelerator should be of 0.9.5.x or lower version.
* *
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
*/ */
class CEAcceleratorCache extends CCache class CEAcceleratorCache extends CCache
{ {
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CExpressionDependency class file. * CExpressionDependency class file.
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CExpressionDependency represents a dependency based on the result of a PHP expression. * CExpressionDependency represents a dependency based on the result of a PHP expression.
* *
...@@ -17,9 +18,7 @@ ...@@ -17,9 +18,7 @@
* the same as the one evaluated when storing the data to cache. * the same as the one evaluated when storing the data to cache.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching.dependencies
* @since 1.0
*/ */
class CExpressionDependency extends CCacheDependency class CExpressionDependency extends CCacheDependency
{ {
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CFileCache class file * CFileCache class file
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CFileCache provides a file-based caching mechanism. * CFileCache provides a file-based caching mechanism.
* *
...@@ -21,8 +22,7 @@ ...@@ -21,8 +22,7 @@
* when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance. * when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
*/ */
class CFileCache extends CCache class CFileCache extends CCache
{ {
...@@ -56,7 +56,7 @@ class CFileCache extends CCache ...@@ -56,7 +56,7 @@ class CFileCache extends CCache
{ {
parent::init(); parent::init();
if($this->cachePath===null) if($this->cachePath===null)
$this->cachePath=Yii::app()->getRuntimePath().DIRECTORY_SEPARATOR.'cache'; $this->cachePath=\Yii::$application->getRuntimePath().DIRECTORY_SEPARATOR.'cache';
if(!is_dir($this->cachePath)) if(!is_dir($this->cachePath))
mkdir($this->cachePath,0777,true); mkdir($this->cachePath,0777,true);
} }
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
/** /**
* CFileCacheDependency class file. * CFileCacheDependency class file.
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CFileCacheDependency represents a dependency based on a file's last modification time. * CFileCacheDependency represents a dependency based on a file's last modification time.
* *
...@@ -17,9 +19,7 @@ ...@@ -17,9 +19,7 @@
* last modification time remains unchanged. * last modification time remains unchanged.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching.dependencies
* @since 1.0
*/ */
class CFileCacheDependency extends CCacheDependency class CFileCacheDependency extends CCacheDependency
{ {
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CMemCache class file * CMemCache class file
* *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CMemCache implements a cache application component based on {@link http://memcached.org/ memcached}. * CMemCache implements a cache application component based on {@link http://memcached.org/ memcached}.
* *
...@@ -55,9 +56,7 @@ ...@@ -55,9 +56,7 @@
* @property array $servers List of memcache server configurations. Each element is a {@link CMemCacheServerConfiguration}. * @property array $servers List of memcache server configurations. Each element is a {@link CMemCacheServerConfiguration}.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
* @since 1.0
*/ */
class CMemCache extends CCache class CMemCache extends CCache
{ {
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CWinCache class file * CWinCache class file
* *
* @author Alexander Makarov <sam@rmcreative.ru>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CWinCache implements a cache application component based on {@link http://www.iis.net/expand/wincacheforphp WinCache}. * CWinCache implements a cache application component based on {@link http://www.iis.net/expand/wincacheforphp WinCache}.
* *
...@@ -15,10 +16,8 @@ ...@@ -15,10 +16,8 @@
* *
* See {@link CCache} manual for common cache operations that are supported by CWinCache. * See {@link CCache} manual for common cache operations that are supported by CWinCache.
* *
* @author Alexander Makarov <sam@rmcreative.ru> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
* @since 1.1.2
*/ */
class CWinCache extends CCache { class CWinCache extends CCache {
/** /**
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CXCache class file * CXCache class file
* *
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CXCache implements a cache application module based on {@link http://xcache.lighttpd.net/ xcache}. * CXCache implements a cache application module based on {@link http://xcache.lighttpd.net/ xcache}.
* *
...@@ -16,9 +17,8 @@ ...@@ -16,9 +17,8 @@
* *
* See {@link CCache} manual for common cache operations that are supported by CXCache. * See {@link CCache} manual for common cache operations that are supported by CXCache.
* *
* @author Wei Zhuo <weizhuo[at]gmail[dot]com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
*/ */
class CXCache extends CCache class CXCache extends CCache
{ {
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
/** /**
* CZendDataCache class file * CZendDataCache class file
* *
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC * @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\caching;
/** /**
* CZendDataCache implements a cache application module based on the Zend Data Cache * CZendDataCache implements a cache application module based on the Zend Data Cache
* delivered with {@link http://www.zend.com/en/products/server/ ZendServer}. * delivered with {@link http://www.zend.com/en/products/server/ ZendServer}.
...@@ -16,9 +17,8 @@ ...@@ -16,9 +17,8 @@
* *
* See {@link CCache} manual for common cache operations that are supported by CZendDataCache. * See {@link CCache} manual for common cache operations that are supported by CZendDataCache.
* *
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com> * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$ * @since 2.0
* @package system.caching
*/ */
class CZendDataCache extends CCache class CZendDataCache extends CCache
{ {
......
...@@ -416,7 +416,7 @@ class MigrateCommand extends CConsoleCommand ...@@ -416,7 +416,7 @@ class MigrateCommand extends CConsoleCommand
{ {
if($this->_db!==null) if($this->_db!==null)
return $this->_db; return $this->_db;
else if(($this->_db=Yii::app()->getComponent($this->connectionID)) instanceof CDbConnection) else if(($this->_db=\Yii::$application->getComponent($this->connectionID)) instanceof CDbConnection)
return $this->_db; return $this->_db;
else else
die("Error: CMigrationCommand.connectionID '{$this->connectionID}' is invalid. Please make sure it refers to the ID of a CDbConnection application component.\n"); die("Error: CMigrationCommand.connectionID '{$this->connectionID}' is invalid. Please make sure it refers to the ID of a CDbConnection application component.\n");
......
...@@ -112,7 +112,7 @@ EOD; ...@@ -112,7 +112,7 @@ EOD;
if(($_path_=@getenv('YIIC_SHELL_COMMAND_PATH'))!==false) if(($_path_=@getenv('YIIC_SHELL_COMMAND_PATH'))!==false)
$_runner_->addCommands($_path_); $_runner_->addCommands($_path_);
$_commands_=$_runner_->commands; $_commands_=$_runner_->commands;
$log=Yii::app()->log; $log=\Yii::$application->log;
while(($_line_=$this->prompt("\n>>"))!==false) while(($_line_=$this->prompt("\n>>"))!==false)
{ {
......
...@@ -97,7 +97,7 @@ class CAssetManager extends CApplicationComponent ...@@ -97,7 +97,7 @@ class CAssetManager extends CApplicationComponent
{ {
if($this->_basePath===null) if($this->_basePath===null)
{ {
$request=Yii::app()->getRequest(); $request=\Yii::$application->getRequest();
$this->setBasePath(dirname($request->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH); $this->setBasePath(dirname($request->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH);
} }
return $this->_basePath; return $this->_basePath;
...@@ -125,7 +125,7 @@ class CAssetManager extends CApplicationComponent ...@@ -125,7 +125,7 @@ class CAssetManager extends CApplicationComponent
{ {
if($this->_baseUrl===null) if($this->_baseUrl===null)
{ {
$request=Yii::app()->getRequest(); $request=\Yii::$application->getRequest();
$this->setBaseUrl($request->getBaseUrl().'/'.self::DEFAULT_BASEPATH); $this->setBaseUrl($request->getBaseUrl().'/'.self::DEFAULT_BASEPATH);
} }
return $this->_baseUrl; return $this->_baseUrl;
......
...@@ -130,7 +130,7 @@ class CHttpRequest extends CApplicationComponent ...@@ -130,7 +130,7 @@ class CHttpRequest extends CApplicationComponent
} }
if($this->enableCsrfValidation) if($this->enableCsrfValidation)
Yii::app()->attachEventHandler('onBeginRequest',array($this,'validateCsrfToken')); \Yii::$application->attachEventHandler('onBeginRequest',array($this,'validateCsrfToken'));
} }
...@@ -762,7 +762,7 @@ class CHttpRequest extends CApplicationComponent ...@@ -762,7 +762,7 @@ class CHttpRequest extends CApplicationComponent
$url=$this->getHostInfo().$url; $url=$this->getHostInfo().$url;
header('Location: '.$url, true, $statusCode); header('Location: '.$url, true, $statusCode);
if($terminate) if($terminate)
Yii::app()->end(); \Yii::$application->end();
} }
/** /**
...@@ -816,7 +816,7 @@ class CHttpRequest extends CApplicationComponent ...@@ -816,7 +816,7 @@ class CHttpRequest extends CApplicationComponent
{ {
// clean up the application first because the file downloading could take long time // clean up the application first because the file downloading could take long time
// which may cause timeout of some resources (such as DB connection) // which may cause timeout of some resources (such as DB connection)
Yii::app()->end(0,false); \Yii::$application->end(0,false);
echo $content; echo $content;
exit(0); exit(0);
} }
...@@ -858,7 +858,7 @@ class CHttpRequest extends CApplicationComponent ...@@ -858,7 +858,7 @@ class CHttpRequest extends CApplicationComponent
* <b>Example</b>: * <b>Example</b>:
* <pre> * <pre>
* <?php * <?php
* Yii::app()->request->xSendFile('/home/user/Pictures/picture1.jpg',array( * \Yii::$application->request->xSendFile('/home/user/Pictures/picture1.jpg',array(
* 'saveName'=>'image1.jpg', * 'saveName'=>'image1.jpg',
* 'mimeType'=>'image/jpeg', * 'mimeType'=>'image/jpeg',
* 'terminate'=>false, * 'terminate'=>false,
...@@ -906,7 +906,7 @@ class CHttpRequest extends CApplicationComponent ...@@ -906,7 +906,7 @@ class CHttpRequest extends CApplicationComponent
header(trim($options['xHeader']).': '.$filePath); header(trim($options['xHeader']).': '.$filePath);
if(!isset($options['terminate']) || $options['terminate']) if(!isset($options['terminate']) || $options['terminate'])
Yii::app()->end(); \Yii::$application->end();
} }
/** /**
...@@ -1029,7 +1029,7 @@ class CCookieCollection extends CMap ...@@ -1029,7 +1029,7 @@ class CCookieCollection extends CMap
$cookies=array(); $cookies=array();
if($this->_request->enableCookieValidation) if($this->_request->enableCookieValidation)
{ {
$sm=Yii::app()->getSecurityManager(); $sm=\Yii::$application->getSecurityManager();
foreach($_COOKIE as $name=>$value) foreach($_COOKIE as $name=>$value)
{ {
if(is_string($value) && ($value=$sm->validateData($value))!==false) if(is_string($value) && ($value=$sm->validateData($value))!==false)
...@@ -1090,7 +1090,7 @@ class CCookieCollection extends CMap ...@@ -1090,7 +1090,7 @@ class CCookieCollection extends CMap
{ {
$value=$cookie->value; $value=$cookie->value;
if($this->_request->enableCookieValidation) if($this->_request->enableCookieValidation)
$value=Yii::app()->getSecurityManager()->hashData(serialize($value)); $value=\Yii::$application->getSecurityManager()->hashData(serialize($value));
if(version_compare(PHP_VERSION,'5.2.0','>=')) if(version_compare(PHP_VERSION,'5.2.0','>='))
setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly); setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly);
else else
......
...@@ -303,7 +303,7 @@ class CSort extends CComponent ...@@ -303,7 +303,7 @@ class CSort extends CComponent
else else
$directions=array($attribute=>$descending); $directions=array($attribute=>$descending);
$url=$this->createUrl(Yii::app()->getController(),$directions); $url=$this->createUrl(\Yii::$application->getController(),$directions);
return $this->createLink($attribute,$label,$url,$htmlOptions); return $this->createLink($attribute,$label,$url,$htmlOptions);
} }
......
...@@ -126,7 +126,7 @@ class CTheme extends CComponent ...@@ -126,7 +126,7 @@ class CTheme extends CComponent
$module=$module->getParentModule(); $module=$module->getParentModule();
} }
if($module===null) if($module===null)
$layoutName=Yii::app()->layout; $layoutName=\Yii::$application->layout;
else else
{ {
$layoutName=$module->layout; $layoutName=$module->layout;
......
...@@ -96,7 +96,7 @@ class CThemeManager extends CApplicationComponent ...@@ -96,7 +96,7 @@ class CThemeManager extends CApplicationComponent
public function getBasePath() public function getBasePath()
{ {
if($this->_basePath===null) if($this->_basePath===null)
$this->setBasePath(dirname(Yii::app()->getRequest()->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH); $this->setBasePath(dirname(\Yii::$application->getRequest()->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH);
return $this->_basePath; return $this->_basePath;
} }
...@@ -117,7 +117,7 @@ class CThemeManager extends CApplicationComponent ...@@ -117,7 +117,7 @@ class CThemeManager extends CApplicationComponent
public function getBaseUrl() public function getBaseUrl()
{ {
if($this->_baseUrl===null) if($this->_baseUrl===null)
$this->_baseUrl=Yii::app()->getBaseUrl().'/'.self::DEFAULT_BASEPATH; $this->_baseUrl=\Yii::$application->getBaseUrl().'/'.self::DEFAULT_BASEPATH;
return $this->_baseUrl; return $this->_baseUrl;
} }
......
...@@ -214,7 +214,7 @@ class CUrlManager extends CApplicationComponent ...@@ -214,7 +214,7 @@ class CUrlManager extends CApplicationComponent
{ {
if(empty($this->rules) || $this->getUrlFormat()===self::GET_FORMAT) if(empty($this->rules) || $this->getUrlFormat()===self::GET_FORMAT)
return; return;
if($this->cacheID!==false && ($cache=Yii::app()->getComponent($this->cacheID))!==null) if($this->cacheID!==false && ($cache=\Yii::$application->getComponent($this->cacheID))!==null)
{ {
$hash=md5(serialize($this->rules)); $hash=md5(serialize($this->rules));
if(($data=$cache->get(self::CACHE_KEY))!==false && isset($data[1]) && $data[1]===$hash) if(($data=$cache->get(self::CACHE_KEY))!==false && isset($data[1]) && $data[1]===$hash)
...@@ -466,9 +466,9 @@ class CUrlManager extends CApplicationComponent ...@@ -466,9 +466,9 @@ class CUrlManager extends CApplicationComponent
else else
{ {
if($this->showScriptName) if($this->showScriptName)
$this->_baseUrl=Yii::app()->getRequest()->getScriptUrl(); $this->_baseUrl=\Yii::$application->getRequest()->getScriptUrl();
else else
$this->_baseUrl=Yii::app()->getRequest()->getBaseUrl(); $this->_baseUrl=\Yii::$application->getRequest()->getBaseUrl();
return $this->_baseUrl; return $this->_baseUrl;
} }
} }
...@@ -767,7 +767,7 @@ class CUrlRule extends CBaseUrlRule ...@@ -767,7 +767,7 @@ class CUrlRule extends CBaseUrlRule
if($this->hasHostInfo) if($this->hasHostInfo)
{ {
$hostInfo=Yii::app()->getRequest()->getHostInfo(); $hostInfo=\Yii::$application->getRequest()->getHostInfo();
if(stripos($url,$hostInfo)===0) if(stripos($url,$hostInfo)===0)
$url=substr($url,strlen($hostInfo)); $url=substr($url,strlen($hostInfo));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment