diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2015-01-22 09:14:12 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2015-01-22 09:14:12 +0100 |
commit | 5230f8f8a86fc1ae5d90f8c74ae65c93e197502b (patch) | |
tree | e870d29e21c14d5b1683d638dff978afe0a104fa /framework/Caching | |
parent | 53e4cd65205ac33d7dbc61a767f467c1b896dfc6 (diff) |
Apply namespaces to class inheritances (pt1)
Diffstat (limited to 'framework/Caching')
-rw-r--r-- | framework/Caching/ICache.php | 64 | ||||
-rw-r--r-- | framework/Caching/ICacheDependency.php | 32 | ||||
-rw-r--r-- | framework/Caching/TAPCCache.php | 1 | ||||
-rw-r--r-- | framework/Caching/TApplicationStateCacheDependency.php | 2 | ||||
-rw-r--r-- | framework/Caching/TCache.php | 16 | ||||
-rw-r--r-- | framework/Caching/TCacheDependency.php | 2 | ||||
-rw-r--r-- | framework/Caching/TCacheDependencyList.php | 1 | ||||
-rw-r--r-- | framework/Caching/TDbCache.php | 26 | ||||
-rw-r--r-- | framework/Caching/TDirectoryCacheDependency.php | 3 | ||||
-rw-r--r-- | framework/Caching/TEACache.php | 2 | ||||
-rw-r--r-- | framework/Caching/TGlobalStateCacheDependency.php | 1 | ||||
-rw-r--r-- | framework/Caching/TMemCache.php | 7 | ||||
-rw-r--r-- | framework/Caching/TSqliteCache.php | 5 | ||||
-rw-r--r-- | framework/Caching/TXCache.php | 1 |
14 files changed, 141 insertions, 22 deletions
diff --git a/framework/Caching/ICache.php b/framework/Caching/ICache.php new file mode 100644 index 00000000..f2a13f03 --- /dev/null +++ b/framework/Caching/ICache.php @@ -0,0 +1,64 @@ +<?php +/** + * Core interfaces essential for TApplication class. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package Prado\Caching + */ + +namespace Prado\Caching; + +/** + * ICache interface. + * + * This interface must be implemented by cache managers. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package Prado\Caching + * @since 3.0 + */ +interface ICache +{ + /** + * Retrieves a value from cache with a specified key. + * @param string a key identifying the cached value + * @return mixed the value stored in cache, false if the value is not in the cache or expired. + */ + public function get($id); + /** + * Stores a value identified by a key into cache. + * If the cache already contains such a key, the existing value and + * expiration time will be replaced with the new ones. + * + * @param string the key identifying the value to be cached + * @param mixed the value to be cached + * @param integer the number of seconds in which the cached value will expire. 0 means never expire. + * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid. + * @return boolean true if the value is successfully stored into cache, false otherwise + */ + public function set($id,$value,$expire=0,$dependency=null); + /** + * Stores a value identified by a key into cache if the cache does not contain this key. + * Nothing will be done if the cache already contains the key. + * @param string the key identifying the value to be cached + * @param mixed the value to be cached + * @param integer the number of seconds in which the cached value will expire. 0 means never expire. + * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid. + * @return boolean true if the value is successfully stored into cache, false otherwise + */ + public function add($id,$value,$expire=0,$dependency=null); + /** + * Deletes a value with the specified key from cache + * @param string the key of the value to be deleted + * @return boolean if no error happens during deletion + */ + public function delete($id); + /** + * Deletes all values from cache. + * Be careful of performing this operation if the cache is shared by multiple applications. + */ + public function flush(); +}
\ No newline at end of file diff --git a/framework/Caching/ICacheDependency.php b/framework/Caching/ICacheDependency.php new file mode 100644 index 00000000..4a81b714 --- /dev/null +++ b/framework/Caching/ICacheDependency.php @@ -0,0 +1,32 @@ +<?php +/** + * Core interfaces essential for TApplication class. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package Prado\Caching + */ + +namespace Prado\Caching; + +/** + * ICacheDependency interface. + * + * This interface must be implemented by classes meant to be used as + * cache dependencies. + * + * Classes implementing this interface must support serialization and unserialization. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package Prado\Caching + * @since 3.0 + */ +interface ICacheDependency +{ + /** + * @return boolean whether the dependency has changed. Defaults to false. + */ + public function getHasChanged(); +}
\ No newline at end of file diff --git a/framework/Caching/TAPCCache.php b/framework/Caching/TAPCCache.php index 53f1069e..77c114d8 100644 --- a/framework/Caching/TAPCCache.php +++ b/framework/Caching/TAPCCache.php @@ -10,6 +10,7 @@ */ namespace Prado\Caching; +use Prado\Exceptions\TConfigurationException; /** * TAPCCache class diff --git a/framework/Caching/TApplicationStateCacheDependency.php b/framework/Caching/TApplicationStateCacheDependency.php index ee36ba54..db7c38d3 100644 --- a/framework/Caching/TApplicationStateCacheDependency.php +++ b/framework/Caching/TApplicationStateCacheDependency.php @@ -10,6 +10,8 @@ */ namespace Prado\Caching; +use Prado\Prado; +use Prado\TApplicationMode; /** * TApplicationStateCacheDependency class. diff --git a/framework/Caching/TCache.php b/framework/Caching/TCache.php index 88a391c9..a243c236 100644 --- a/framework/Caching/TCache.php +++ b/framework/Caching/TCache.php @@ -10,7 +10,9 @@ */ namespace Prado\Caching; -Prado::using('System.Collections.TList'); +use Prado\Exceptions\TConfigurationException; +use Prado\Exceptions\TNotSupportedException; +use Prado\TPropertyValue; /** * TCache class @@ -38,14 +40,14 @@ Prado::using('System.Collections.TList'); * - {@link deleteValue} * and optionally {@link flush} * - * Since version 3.1.2, TCache implements the ArrayAccess interface such that + * Since version 3.1.2, TCache implements the \ArrayAccess interface such that * the cache acts as an array. * * @author Qiang Xue <qiang.xue@gmail.com> * @package Prado\Caching * @since 3.0 */ -abstract class TCache extends TModule implements ICache, ArrayAccess +abstract class TCache extends \Prado\TModule implements ICache, \ArrayAccess { private $_prefix=null; private $_primary=true; @@ -241,7 +243,7 @@ abstract class TCache extends TModule implements ICache, ArrayAccess /** * Returns whether there is a cache entry with a specified key. - * This method is required by the interface ArrayAccess. + * This method is required by the interface \ArrayAccess. * @param string a key identifying the cached value * @return boolean */ @@ -252,7 +254,7 @@ abstract class TCache extends TModule implements ICache, ArrayAccess /** * Retrieves the value from cache with a specified key. - * This method is required by the interface ArrayAccess. + * This method is required by the interface \ArrayAccess. * @param string a key identifying the cached value * @return mixed the value stored in cache, false if the value is not in the cache or expired. */ @@ -265,7 +267,7 @@ abstract class TCache extends TModule implements ICache, ArrayAccess * Stores the value identified by a key into cache. * If the cache already contains such a key, the existing value will be * replaced with the new ones. To add expiration and dependencies, use the set() method. - * This method is required by the interface ArrayAccess. + * This method is required by the interface \ArrayAccess. * @param string the key identifying the value to be cached * @param mixed the value to be cached */ @@ -276,7 +278,7 @@ abstract class TCache extends TModule implements ICache, ArrayAccess /** * 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 the key of the value to be deleted * @return boolean if no error happens during deletion */ diff --git a/framework/Caching/TCacheDependency.php b/framework/Caching/TCacheDependency.php index 7b2b1261..e10793f6 100644 --- a/framework/Caching/TCacheDependency.php +++ b/framework/Caching/TCacheDependency.php @@ -39,6 +39,6 @@ namespace Prado\Caching; * @package Prado\Caching * @since 3.1.0 */ -abstract class TCacheDependency extends TComponent implements ICacheDependency +abstract class TCacheDependency extends \Prado\TComponent implements ICacheDependency { }
\ No newline at end of file diff --git a/framework/Caching/TCacheDependencyList.php b/framework/Caching/TCacheDependencyList.php index 6e43d428..a093825a 100644 --- a/framework/Caching/TCacheDependencyList.php +++ b/framework/Caching/TCacheDependencyList.php @@ -10,6 +10,7 @@ */ namespace Prado\Caching; +use Prado\Exceptions\TInvalidDataTypeException; /** * TCacheDependencyList class. diff --git a/framework/Caching/TDbCache.php b/framework/Caching/TDbCache.php index 968fac30..cee1b193 100644 --- a/framework/Caching/TDbCache.php +++ b/framework/Caching/TDbCache.php @@ -10,7 +10,11 @@ */ namespace Prado\Caching; -Prado::using('System.Data.TDbConnection'); +use Prado\Prado; +use Prado\Data\TDataSourceConfig; +use Prado\Data\TDbConnection; +use Prado\Exceptions\TConfigurationException; +use Prado\TPropertyValue; /** * TDbCache class @@ -201,7 +205,7 @@ class TDbCache extends TCache $this -> getApplication() -> setGlobalState($key, time()); } } - catch(Exception $e) + catch(\Exception $e) { // DB table not exists if($this->_autoCreate) @@ -464,7 +468,7 @@ class TDbCache extends TCache $command=$this->getDbConnection()->createCommand($sql); return unserialize($command->queryScalar()); } - catch(Exception $e) + catch(\Exception $e) { $this->initializeCache(true); return unserialize($command->queryScalar()); @@ -503,12 +507,12 @@ class TDbCache extends TCache try { $command=$this->getDbConnection()->createCommand($sql); - $command->bindValue(':key',$key,PDO::PARAM_STR); - $command->bindValue(':value',serialize($value),PDO::PARAM_LOB); + $command->bindValue(':key',$key,\PDO::PARAM_STR); + $command->bindValue(':value',serialize($value),\PDO::PARAM_LOB); $command->execute(); return true; } - catch(Exception $e) + catch(\Exception $e) { try { @@ -516,7 +520,7 @@ class TDbCache extends TCache $command->execute(); return true; } - catch(Exception $e) + catch(\Exception $e) { return false; } @@ -535,11 +539,11 @@ class TDbCache extends TCache try { $command=$this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable} WHERE itemkey=:key"); - $command->bindValue(':key',$key,PDO::PARAM_STR); + $command->bindValue(':key',$key,\PDO::PARAM_STR); $command->execute(); return true; } - catch(Exception $e) + catch(\Exception $e) { $this->initializeCache(true); $command->execute(); @@ -559,7 +563,7 @@ class TDbCache extends TCache $command = $this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable}"); $command->execute(); } - catch(Exception $e) + catch(\Exception $e) { try { @@ -567,7 +571,7 @@ class TDbCache extends TCache $command->execute(); return true; } - catch(Exception $e) + catch(\Exception $e) { return false; } diff --git a/framework/Caching/TDirectoryCacheDependency.php b/framework/Caching/TDirectoryCacheDependency.php index d78aa87a..28924f12 100644 --- a/framework/Caching/TDirectoryCacheDependency.php +++ b/framework/Caching/TDirectoryCacheDependency.php @@ -10,6 +10,9 @@ */ namespace Prado\Caching; +use Prado\Exceptions\TInvalidDataValueException; +use Prado\Exceptions\TIOException; +use Prado\TPropertyValue; /** * TDirectoryCacheDependency class. diff --git a/framework/Caching/TEACache.php b/framework/Caching/TEACache.php index 073b7f79..29dabffa 100644 --- a/framework/Caching/TEACache.php +++ b/framework/Caching/TEACache.php @@ -1 +1 @@ -<?php
/**
* TEACache class file
*
* @author Dario rigolin <drigolin@e-portaltech.it>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005-2014 PradoSoft
* @license http://www.pradosoft.com/license/
* @package Prado\Caching
*/
namespace Prado\Caching;
/**
* TEACache class
*
* TEACache implements a cache application module based on {@link http://eaccelerator.net/ eAccelerator}.
*
* By definition, cache does not ensure the existence of a value
* even if it never expires. Cache is not meant to be an persistent storage.
*
* To use this module, the eAccelerator PHP extension must be loaded and enabled
*
* 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.
*
* Some usage examples of TEACache are as follows,
* <code>
* $cache=new TEACache; // TEACache may also be loaded as a Prado application module
* $cache->init(null);
* $cache->add('object',$object);
* $object2=$cache->get('object');
* </code>
*
* If loaded, TEACache will register itself with {@link TApplication} as the
* cache module. It can be accessed via {@link TApplication::getCache()}.
*
* TEACache may be configured in application configuration file as follows
* <code>
* <module id="cache" class="System.Caching.TEACache" />
* </code>
*
* @author Dario Rigolin <drigolin@e-portaltech.it>
* @package Prado\Caching
* @since 3.2.2
*/
class TEACache extends TCache
{
/**
* Initializes this module.
* This method is required by the IModule interface.
* @param TXmlElement configuration for this module, can be null
* @throws TConfigurationException if eaccelerator extension is not installed or not started, check your php.ini
*/
public function init($config)
{
if(!function_exists('eaccelerator_get'))
throw new TConfigurationException('eacceleratorcache_extension_required');
parent::init($config);
}
/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string 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.
*/
protected function getValue($key)
{
$value = eaccelerator_get($key);
return ($value === null) ? false : $value;
}
/**
* Stores a value identified by a key in cache.
* This is the implementation of the method declared in the parent class.
*
* @param string the key identifying the value to be cached
* @param string the value to be cached
* @param integer 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
*/
protected function setValue($key,$value,$expire)
{
return eaccelerator_put($key,$value,$expire);
}
/**
* Stores a value identified by a key into cache if the cache does not contain this key.
* This is the implementation of the method declared in the parent class.
*
* @param string the key identifying the value to be cached
* @param string the value to be cached
* @param integer 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
*/
protected function addValue($key,$value,$expire)
{
return (null === eaccelerator_get($key)) ? $this->setValue($key,$value,$expire) : false;
}
/**
* Deletes a value with the specified key from cache
* This is the implementation of the method declared in the parent class.
* @param string the key of the value to be deleted
* @return boolean if no error happens during deletion
*/
protected function deleteValue($key)
{
return eaccelerator_rm($key);
}
/**
* Deletes all values from cache.
* Be careful of performing this operation if the cache is shared by multiple applications.
*/
public function flush()
{
// first, remove expired content from cache
eaccelerator_gc();
// now, remove leftover cache-keys
$keys = eaccelerator_list_keys();
foreach($keys as $key)
$this->deleteValue(substr($key['name'], 1));
return true;
}
}
\ No newline at end of file +<?php
/**
* TEACache class file
*
* @author Dario rigolin <drigolin@e-portaltech.it>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005-2014 PradoSoft
* @license http://www.pradosoft.com/license/
* @package Prado\Caching
*/
namespace Prado\Caching;
use Prado\Exceptions\TConfigurationException;
/**
* TEACache class
*
* TEACache implements a cache application module based on {@link http://eaccelerator.net/ eAccelerator}.
*
* By definition, cache does not ensure the existence of a value
* even if it never expires. Cache is not meant to be an persistent storage.
*
* To use this module, the eAccelerator PHP extension must be loaded and enabled
*
* 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.
*
* Some usage examples of TEACache are as follows,
* <code>
* $cache=new TEACache; // TEACache may also be loaded as a Prado application module
* $cache->init(null);
* $cache->add('object',$object);
* $object2=$cache->get('object');
* </code>
*
* If loaded, TEACache will register itself with {@link TApplication} as the
* cache module. It can be accessed via {@link TApplication::getCache()}.
*
* TEACache may be configured in application configuration file as follows
* <code>
* <module id="cache" class="System.Caching.TEACache" />
* </code>
*
* @author Dario Rigolin <drigolin@e-portaltech.it>
* @package Prado\Caching
* @since 3.2.2
*/
class TEACache extends TCache
{
/**
* Initializes this module.
* This method is required by the IModule interface.
* @param TXmlElement configuration for this module, can be null
* @throws TConfigurationException if eaccelerator extension is not installed or not started, check your php.ini
*/
public function init($config)
{
if(!function_exists('eaccelerator_get'))
throw new TConfigurationException('eacceleratorcache_extension_required');
parent::init($config);
}
/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string 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.
*/
protected function getValue($key)
{
$value = eaccelerator_get($key);
return ($value === null) ? false : $value;
}
/**
* Stores a value identified by a key in cache.
* This is the implementation of the method declared in the parent class.
*
* @param string the key identifying the value to be cached
* @param string the value to be cached
* @param integer 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
*/
protected function setValue($key,$value,$expire)
{
return eaccelerator_put($key,$value,$expire);
}
/**
* Stores a value identified by a key into cache if the cache does not contain this key.
* This is the implementation of the method declared in the parent class.
*
* @param string the key identifying the value to be cached
* @param string the value to be cached
* @param integer 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
*/
protected function addValue($key,$value,$expire)
{
return (null === eaccelerator_get($key)) ? $this->setValue($key,$value,$expire) : false;
}
/**
* Deletes a value with the specified key from cache
* This is the implementation of the method declared in the parent class.
* @param string the key of the value to be deleted
* @return boolean if no error happens during deletion
*/
protected function deleteValue($key)
{
return eaccelerator_rm($key);
}
/**
* Deletes all values from cache.
* Be careful of performing this operation if the cache is shared by multiple applications.
*/
public function flush()
{
// first, remove expired content from cache
eaccelerator_gc();
// now, remove leftover cache-keys
$keys = eaccelerator_list_keys();
foreach($keys as $key)
$this->deleteValue(substr($key['name'], 1));
return true;
}
}
\ No newline at end of file diff --git a/framework/Caching/TGlobalStateCacheDependency.php b/framework/Caching/TGlobalStateCacheDependency.php index b10b5e01..0c622445 100644 --- a/framework/Caching/TGlobalStateCacheDependency.php +++ b/framework/Caching/TGlobalStateCacheDependency.php @@ -10,6 +10,7 @@ */ namespace Prado\Caching; +use Prado\Prado; /** * TGlobalStateCacheDependency class. diff --git a/framework/Caching/TMemCache.php b/framework/Caching/TMemCache.php index 8c92bab1..659d9fd5 100644 --- a/framework/Caching/TMemCache.php +++ b/framework/Caching/TMemCache.php @@ -11,6 +11,11 @@ */ namespace Prado\Caching; +use Prado\Exceptions\TConfigurationException; +use Prado\Exceptions\TInvalidOperationException; +use Prado\Prado; +use Prado\TPropertyValue; +use Prado\Xml\TXmlElement; /** * TMemCache class @@ -159,7 +164,7 @@ class TMemCache extends TCache { if(!extension_loaded('memcache')) throw new TConfigurationException('memcache_extension_required'); - $this->_cache=new Memcache; + $this->_cache=new \Memcache; $this->loadConfig($config); if(count($this->_servers)) { diff --git a/framework/Caching/TSqliteCache.php b/framework/Caching/TSqliteCache.php index 12d3e225..348a37f0 100644 --- a/framework/Caching/TSqliteCache.php +++ b/framework/Caching/TSqliteCache.php @@ -10,6 +10,9 @@ */ namespace Prado\Caching; +use Prado\Exceptions\TConfigurationException; +use Prado\Exceptions\TInvalidOperationException; +use Prado\Prado; /** * TSqliteCache class @@ -121,7 +124,7 @@ class TSqliteCache extends TCache if($this->_file===null) $this->_file=$this->getApplication()->getRuntimePath().'/sqlite.cache'; $error=''; - if(($this->_db=new SQLiteDatabase($this->_file,0666,$error))===false) + if(($this->_db=new \SQLiteDatabase($this->_file,0666,$error))===false) throw new TConfigurationException('sqlitecache_connection_failed',$error); if(@$this->_db->query('DELETE FROM '.self::CACHE_TABLE.' WHERE expire<>0 AND expire<'.time())===false) { diff --git a/framework/Caching/TXCache.php b/framework/Caching/TXCache.php index 96af68f5..6f3cf815 100644 --- a/framework/Caching/TXCache.php +++ b/framework/Caching/TXCache.php @@ -10,6 +10,7 @@ */ namespace Prado\Caching; +use Prado\Exceptions\TConfigurationException; /** * TXCache class |