Browse Source

working on caching.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
c225242290
  1. 2
      framework/base/ErrorHandler.php
  2. 61
      framework/base/InlineActionFilter.php
  3. 8
      framework/base/SecurityManager.php
  4. 9
      framework/caching/ApcCache.php
  5. 198
      framework/caching/Cache.php
  6. 113
      framework/caching/CacheDependency.php
  7. 9
      framework/caching/ChainedDependency.php
  8. 14
      framework/caching/DbCache.php
  9. 12
      framework/caching/DbDependency.php
  10. 9
      framework/caching/Dependency.php
  11. 10
      framework/caching/DirectoryDependency.php
  12. 13
      framework/caching/DummyCache.php
  13. 11
      framework/caching/EAcceleratorCache.php
  14. 9
      framework/caching/ExpressionDependency.php
  15. 10
      framework/caching/FileCache.php
  16. 10
      framework/caching/FileDependency.php
  17. 9
      framework/caching/MemCache.php
  18. 11
      framework/caching/WinCache.php
  19. 10
      framework/caching/XCache.php
  20. 10
      framework/caching/ZendDataCache.php
  21. 2
      framework/console/commands/MigrateController.php
  22. 2
      framework/console/commands/ShellController.php
  23. 4
      framework/web/AssetManager.php
  24. 14
      framework/web/Request.php
  25. 2
      framework/web/Sort.php
  26. 2
      framework/web/Theme.php
  27. 4
      framework/web/ThemeManager.php
  28. 8
      framework/web/UrlManager.php

2
framework/base/ErrorHandler.php

@ -34,7 +34,7 @@ class ErrorHandler extends ApplicationComponent
public $discardExistingOutput = true;
/**
* @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.
*/
public $errorAction;

61
framework/base/InlineActionFilter.php

@ -1,61 +0,0 @@
<?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);
}
}

8
framework/base/SecurityManager.php

@ -99,13 +99,13 @@ class SecurityManager extends ApplicationComponent
return $this->_validationKey;
}
else {
if (($key = Yii::app()->getGlobalState(self::STATE_VALIDATION_KEY)) !== null) {
if (($key = \Yii::$application->getGlobalState(self::STATE_VALIDATION_KEY)) !== null) {
$this->setValidationKey($key);
}
else {
$key = $this->generateRandomKey();
$this->setValidationKey($key);
Yii::app()->setGlobalState(self::STATE_VALIDATION_KEY, $key);
\Yii::$application->setGlobalState(self::STATE_VALIDATION_KEY, $key);
}
return $this->_validationKey;
}
@ -135,13 +135,13 @@ class SecurityManager extends ApplicationComponent
return $this->_encryptionKey;
}
else {
if (($key = Yii::app()->getGlobalState(self::STATE_ENCRYPTION_KEY)) !== null) {
if (($key = \Yii::$application->getGlobalState(self::STATE_ENCRYPTION_KEY)) !== null) {
$this->setEncryptionKey($key);
}
else {
$key = $this->generateRandomKey();
$this->setEncryptionKey($key);
Yii::app()->setGlobalState(self::STATE_ENCRYPTION_KEY, $key);
\Yii::$application->setGlobalState(self::STATE_ENCRYPTION_KEY, $key);
}
return $this->_encryptionKey;
}

9
framework/caching/ApcCache.php

@ -2,12 +2,13 @@
/**
* CApcCache class file
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CApcCache provides APC caching in terms of an application component.
*
@ -17,9 +18,7 @@
* See {@link CCache} manual for common cache operations that are supported by CApcCache.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching
* @since 1.0
* @since 2.0
*/
class CApcCache extends CCache
{

198
framework/caching/Cache.php

@ -1,15 +1,19 @@
<?php
/**
* CCache class file.
* Cache class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
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
* later by {@link get}. In both operations, a key identifying the data item is required.
@ -20,7 +24,7 @@
* 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.
*
* CCache implements the interface {@link ICache} with the following methods:
* Cache implements the interface {@link ICache} with the following methods:
* <ul>
* <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>
@ -40,12 +44,10 @@
* <li>{@link unserializeValue} (optional)</li>
* </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>
* @version $Id$
* @package system.caching
* @since 1.0
* @since 2.0
*/
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.
*/
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
* 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
* cache keys, otherwise there might be unexpected behavior.
* @since 1.1.11
**/
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.
* <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
* serializer. Since the two serialization formats are incompatible, caches should be purged before switching this on to prevent errors.
* @since 1.1.11
* @var array|boolean the functions used to serialize and unserialize cached data. Defaults to null, meaning
* using the default PHP `serialize()` and `unserialize()` functions. If you want to use some more efficient
* serializer (e.g. [igbinary](http://pecl.php.net/package/igbinary)), you may configure this property with
* 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.
@ -94,16 +85,15 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
{
parent::init();
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
* @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;
}
@ -111,18 +101,24 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
/**
* Retrieves a value from cache with a specified key.
* @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)
{
if (($value = $this->getValue($this->generateUniqueKey($id))) !== false) {
$data = $this->autoSerialize ? $this->unserializeValue($value) : $value;
if (!$this->autoSerialize || (is_array($data) && (!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()))) {
Yii::trace('Serving "' . $id . '" from cache', 'system.caching.' . get_class($this));
return $this->autoSerialize ? $data[0] : $data;
}
$value = $this->getValue($this->generateCacheKey($id));
if ($value === false || $this->serializer === false) {
return $value;
} elseif ($this->serializer === null) {
$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
* is returned in terms of (key,value) pairs.
* 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();
$results = array();
$uids = array();
foreach ($ids as $id) {
$uniqueIDs[$id] = $this->generateUniqueKey($id);
$results[$id] = false;
$uids[$id] = $this->generateCacheKey($id);
}
$values = $this->getValues($uniqueIDs);
foreach ($uniqueIDs as $id => $uniqueID) {
if (!isset($values[$uniqueID])) {
continue;
$values = $this->getValues($uids);
$results = array();
if ($this->serializer === false) {
foreach ($uids as $id => $uid) {
$results[$id] = isset($values[$uid]) ? $values[$uid] : false;
}
$data = $this->autoSerialize ? $this->unserializeValue($values[$uniqueID]) : $values[$uniqueID];
if (!$this->autoSerialize || (is_array($data) && (!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()))) {
Yii::trace('Serving "' . $id . '" from cache', 'system.caching.' . get_class($this));
$results[$id] = $this->autoSerialize ? $data[0] : $data;
} else {
foreach ($uids as $id => $uid) {
$results[$id] = false;
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;
@ -165,17 +165,20 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* @param string $id the key identifying 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 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
*/
public function set($id, $value, $expire = 0, $dependency = null)
{
Yii::trace('Saving "' . $id . '" to cache', 'system.caching.' . get_class($this));
if ($dependency !== null && $this->autoSerialize) {
if ($dependency !== null && $this->serializer !== false) {
$dependency->evaluateDependency();
}
$data = $this->autoSerialize ? $this->serializeValue(array($value, $dependency)) : $value;
return $this->setValue($this->generateUniqueKey($id), $data, $expire);
if ($this->serializer === null) {
$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
* @param string $id the key identifying 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 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
*/
public function add($id, $value, $expire = 0, $dependency = null)
{
Yii::trace('Adding "' . $id . '" to cache', 'system.caching.' . get_class($this));
if ($dependency !== null && $this->autoSerialize) {
if ($dependency !== null && $this->serializer !== false) {
$dependency->evaluateDependency();
}
$data = $this->autoSerialize ? $this->serializeValue(array($value, $dependency)) : $value;
return $this->addValue($this->generateUniqueKey($id), $data, $expire);
if ($this->serializer === null) {
$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
*/
public function delete($id)
{
Yii::trace('Deleting "' . $id . '" from cache', 'system.caching.' . get_class($this));
return $this->deleteValue($this->generateUniqueKey($id));
return $this->deleteValue($this->generateCacheKey($id));
}
/**
@ -215,7 +220,6 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
*/
public function flush()
{
Yii::trace('Flushing cache', 'system.caching.' . get_class($this));
return $this->flushValues();
}
@ -227,12 +231,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* is needed.
* @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.
* @throws CException if this method is not overridden by child classes
*/
protected function getValue($key)
{
throw new CException(Yii::t('yii', '{className} does not support get() functionality.',
array('{className}' => get_class($this))));
return false;
}
/**
@ -264,12 +266,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* @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.
* @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)
{
throw new CException(Yii::t('yii', '{className} does not support set() functionality.',
array('{className}' => get_class($this))));
return true;
}
/**
@ -283,12 +283,10 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* @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.
* @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)
{
throw new CException(Yii::t('yii', '{className} does not support add() functionality.',
array('{className}' => get_class($this))));
return true;
}
/**
@ -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.
* @param string $key the key of the value to be deleted
* @return boolean if no error happens during deletion
* @throws CException if this method is not overridden by child classes
*/
protected function deleteValue($key)
{
throw new CException(Yii::t('yii', '{className} does not support delete() functionality.',
array('{className}' => get_class($this))));
return true;
}
/**
* Deletes all values from cache.
* Child classes may implement this method to realize the flush operation.
* @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()
{
throw new CException(Yii::t('yii', '{className} does not support flushValues() functionality.',
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);
return true;
}
/**
@ -392,7 +349,6 @@ abstract class Cache extends ApplicationComponent implements \ArrayAccess
* Deletes the value with the specified key from cache
* This method is required by the interface ArrayAccess.
* @param string $id the key of the value to be deleted
* @return boolean if no error happens during deletion
*/
public function offsetUnset($id)
{

113
framework/caching/CacheDependency.php

@ -0,0 +1,113 @@
<?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;
}
}

9
framework/caching/ChainedDependency.php

@ -2,12 +2,13 @@
/**
* CChainedCacheDependency class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CChainedCacheDependency represents a list of cache dependencies.
*
@ -22,9 +23,7 @@
* @property boolean $hasChanged Whether the dependency is changed or not.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching.dependencies
* @since 1.0
* @since 2.0
*/
class CChainedCacheDependency extends CComponent implements ICacheDependency
{

14
framework/caching/DbCache.php

@ -2,12 +2,14 @@
/**
* CDbCache class file
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CDbCache implements a cache application component by storing cached data in a database.
*
@ -27,9 +29,7 @@
* @property CDbConnection $dbConnection The DB connection instance.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching
* @since 1.0
* @since 2.0
*/
class CDbCache extends CCache
{
@ -150,7 +150,7 @@ EOD;
return $this->_db;
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;
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.',
@ -158,7 +158,7 @@ EOD;
}
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);
}
}

12
framework/caching/DbDependency.php

@ -2,12 +2,14 @@
/**
* CDbCacheDependency class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CDbCacheDependency represents a dependency based on the query result of a SQL statement.
*
@ -17,9 +19,7 @@
* component. It is this DB connection that is used to perform the query.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching.dependencies
* @since 1.0
* @since 2.0
*/
class CDbCacheDependency extends CCacheDependency
{
@ -102,7 +102,7 @@ class CDbCacheDependency extends CCacheDependency
return $this->_db;
else
{
if(($this->_db=Yii::app()->getComponent($this->connectionID)) instanceof CDbConnection)
if(($this->_db=\Yii::$application->getComponent($this->connectionID)) instanceof CDbConnection)
return $this->_db;
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.',

9
framework/caching/Dependency.php

@ -2,12 +2,13 @@
/**
* CCacheDependency class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CCacheDependency is the base class for cache dependency classes.
*
@ -20,9 +21,7 @@
* This data is available after {@link evaluateDependency} is called.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching.dependencies
* @since 1.0
* @since 2.0
*/
class CCacheDependency extends CComponent implements ICacheDependency
{

10
framework/caching/DirectoryDependency.php

@ -2,12 +2,14 @@
/**
* CDirectoryCacheDependency class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CDirectoryCacheDependency represents a dependency based on change of a directory.
*
@ -25,9 +27,7 @@
* accessing modification time of multiple files under the directory.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching.dependencies
* @since 1.0
* @since 2.0
*/
class CDirectoryCacheDependency extends CCacheDependency
{

13
framework/caching/DummyCache.php

@ -2,24 +2,23 @@
/**
* CDummyCache class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CDummyCache is a placeholder cache component.
*
* 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
* non-caching mode to caching mode.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching
* @since 1.0
* @since 2.0
*/
class CDummyCache extends CApplicationComponent implements ICache, ArrayAccess
{
@ -36,7 +35,7 @@ class CDummyCache extends CApplicationComponent implements ICache, ArrayAccess
{
parent::init();
if($this->keyPrefix===null)
$this->keyPrefix=Yii::app()->getId();
$this->keyPrefix=\Yii::$application->getId();
}
/**

11
framework/caching/EAcceleratorCache.php

@ -2,12 +2,14 @@
/**
* CEAcceleratorCache class file
*
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]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/
*/
namespace yii\caching;
/**
* CEAcceleratorCache implements a cache application module based on {@link http://eaccelerator.net/ eaccelerator}.
*
@ -18,9 +20,8 @@
* 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.
*
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com>
* @version $Id$
* @package system.caching
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CEAcceleratorCache extends CCache
{

9
framework/caching/ExpressionDependency.php

@ -2,12 +2,13 @@
/**
* CExpressionDependency class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CExpressionDependency represents a dependency based on the result of a PHP expression.
*
@ -17,9 +18,7 @@
* the same as the one evaluated when storing the data to cache.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching.dependencies
* @since 1.0
* @since 2.0
*/
class CExpressionDependency extends CCacheDependency
{

10
framework/caching/FileCache.php

@ -2,12 +2,13 @@
/**
* CFileCache class file
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CFileCache provides a file-based caching mechanism.
*
@ -21,8 +22,7 @@
* when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching
* @since 2.0
*/
class CFileCache extends CCache
{
@ -56,7 +56,7 @@ class CFileCache extends CCache
{
parent::init();
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))
mkdir($this->cachePath,0777,true);
}

10
framework/caching/FileDependency.php

@ -2,12 +2,14 @@
/**
* CFileCacheDependency class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CFileCacheDependency represents a dependency based on a file's last modification time.
*
@ -17,9 +19,7 @@
* last modification time remains unchanged.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching.dependencies
* @since 1.0
* @since 2.0
*/
class CFileCacheDependency extends CCacheDependency
{

9
framework/caching/MemCache.php

@ -2,12 +2,13 @@
/**
* CMemCache class file
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
namespace yii\caching;
/**
* CMemCache implements a cache application component based on {@link http://memcached.org/ memcached}.
*
@ -55,9 +56,7 @@
* @property array $servers List of memcache server configurations. Each element is a {@link CMemCacheServerConfiguration}.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.caching
* @since 1.0
* @since 2.0
*/
class CMemCache extends CCache
{

11
framework/caching/WinCache.php

@ -2,12 +2,13 @@
/**
* CWinCache class file
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @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/
*/
namespace yii\caching;
/**
* CWinCache implements a cache application component based on {@link http://www.iis.net/expand/wincacheforphp WinCache}.
*
@ -15,10 +16,8 @@
*
* See {@link CCache} manual for common cache operations that are supported by CWinCache.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @version $Id$
* @package system.caching
* @since 1.1.2
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CWinCache extends CCache {
/**

10
framework/caching/XCache.php

@ -2,12 +2,13 @@
/**
* CXCache class file
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]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/
*/
namespace yii\caching;
/**
* CXCache implements a cache application module based on {@link http://xcache.lighttpd.net/ xcache}.
*
@ -16,9 +17,8 @@
*
* See {@link CCache} manual for common cache operations that are supported by CXCache.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Id$
* @package system.caching
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CXCache extends CCache
{

10
framework/caching/ZendDataCache.php

@ -2,12 +2,13 @@
/**
* CZendDataCache class file
*
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]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/
*/
namespace yii\caching;
/**
* CZendDataCache implements a cache application module based on the Zend Data Cache
* delivered with {@link http://www.zend.com/en/products/server/ ZendServer}.
@ -16,9 +17,8 @@
*
* See {@link CCache} manual for common cache operations that are supported by CZendDataCache.
*
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com>
* @version $Id$
* @package system.caching
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CZendDataCache extends CCache
{

2
framework/console/commands/MigrateController.php

@ -416,7 +416,7 @@ class MigrateCommand extends CConsoleCommand
{
if($this->_db!==null)
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;
else
die("Error: CMigrationCommand.connectionID '{$this->connectionID}' is invalid. Please make sure it refers to the ID of a CDbConnection application component.\n");

2
framework/console/commands/ShellController.php

@ -112,7 +112,7 @@ EOD;
if(($_path_=@getenv('YIIC_SHELL_COMMAND_PATH'))!==false)
$_runner_->addCommands($_path_);
$_commands_=$_runner_->commands;
$log=Yii::app()->log;
$log=\Yii::$application->log;
while(($_line_=$this->prompt("\n>>"))!==false)
{

4
framework/web/AssetManager.php

@ -97,7 +97,7 @@ class CAssetManager extends CApplicationComponent
{
if($this->_basePath===null)
{
$request=Yii::app()->getRequest();
$request=\Yii::$application->getRequest();
$this->setBasePath(dirname($request->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH);
}
return $this->_basePath;
@ -125,7 +125,7 @@ class CAssetManager extends CApplicationComponent
{
if($this->_baseUrl===null)
{
$request=Yii::app()->getRequest();
$request=\Yii::$application->getRequest();
$this->setBaseUrl($request->getBaseUrl().'/'.self::DEFAULT_BASEPATH);
}
return $this->_baseUrl;

14
framework/web/Request.php

@ -130,7 +130,7 @@ class CHttpRequest extends CApplicationComponent
}
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
$url=$this->getHostInfo().$url;
header('Location: '.$url, true, $statusCode);
if($terminate)
Yii::app()->end();
\Yii::$application->end();
}
/**
@ -816,7 +816,7 @@ class CHttpRequest extends CApplicationComponent
{
// clean up the application first because the file downloading could take long time
// which may cause timeout of some resources (such as DB connection)
Yii::app()->end(0,false);
\Yii::$application->end(0,false);
echo $content;
exit(0);
}
@ -858,7 +858,7 @@ class CHttpRequest extends CApplicationComponent
* <b>Example</b>:
* <pre>
* <?php
* Yii::app()->request->xSendFile('/home/user/Pictures/picture1.jpg',array(
* \Yii::$application->request->xSendFile('/home/user/Pictures/picture1.jpg',array(
* 'saveName'=>'image1.jpg',
* 'mimeType'=>'image/jpeg',
* 'terminate'=>false,
@ -906,7 +906,7 @@ class CHttpRequest extends CApplicationComponent
header(trim($options['xHeader']).': '.$filePath);
if(!isset($options['terminate']) || $options['terminate'])
Yii::app()->end();
\Yii::$application->end();
}
/**
@ -1029,7 +1029,7 @@ class CCookieCollection extends CMap
$cookies=array();
if($this->_request->enableCookieValidation)
{
$sm=Yii::app()->getSecurityManager();
$sm=\Yii::$application->getSecurityManager();
foreach($_COOKIE as $name=>$value)
{
if(is_string($value) && ($value=$sm->validateData($value))!==false)
@ -1090,7 +1090,7 @@ class CCookieCollection extends CMap
{
$value=$cookie->value;
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','>='))
setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly);
else

2
framework/web/Sort.php

@ -303,7 +303,7 @@ class CSort extends CComponent
else
$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);
}

2
framework/web/Theme.php

@ -126,7 +126,7 @@ class CTheme extends CComponent
$module=$module->getParentModule();
}
if($module===null)
$layoutName=Yii::app()->layout;
$layoutName=\Yii::$application->layout;
else
{
$layoutName=$module->layout;

4
framework/web/ThemeManager.php

@ -96,7 +96,7 @@ class CThemeManager extends CApplicationComponent
public function getBasePath()
{
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;
}
@ -117,7 +117,7 @@ class CThemeManager extends CApplicationComponent
public function getBaseUrl()
{
if($this->_baseUrl===null)
$this->_baseUrl=Yii::app()->getBaseUrl().'/'.self::DEFAULT_BASEPATH;
$this->_baseUrl=\Yii::$application->getBaseUrl().'/'.self::DEFAULT_BASEPATH;
return $this->_baseUrl;
}

8
framework/web/UrlManager.php

@ -214,7 +214,7 @@ class CUrlManager extends CApplicationComponent
{
if(empty($this->rules) || $this->getUrlFormat()===self::GET_FORMAT)
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));
if(($data=$cache->get(self::CACHE_KEY))!==false && isset($data[1]) && $data[1]===$hash)
@ -466,9 +466,9 @@ class CUrlManager extends CApplicationComponent
else
{
if($this->showScriptName)
$this->_baseUrl=Yii::app()->getRequest()->getScriptUrl();
$this->_baseUrl=\Yii::$application->getRequest()->getScriptUrl();
else
$this->_baseUrl=Yii::app()->getRequest()->getBaseUrl();
$this->_baseUrl=\Yii::$application->getRequest()->getBaseUrl();
return $this->_baseUrl;
}
}
@ -767,7 +767,7 @@ class CUrlRule extends CBaseUrlRule
if($this->hasHostInfo)
{
$hostInfo=Yii::app()->getRequest()->getHostInfo();
$hostInfo=\Yii::$application->getRequest()->getHostInfo();
if(stripos($url,$hostInfo)===0)
$url=substr($url,strlen($hostInfo));
}

Loading…
Cancel
Save