From 1f6676f1d9fa4887db18fa400c969b71b1c7a4e3 Mon Sep 17 00:00:00 2001 From: romanb Date: Tue, 6 Jan 2009 21:47:29 +0000 Subject: [PATCH] cache driver corrections --- lib/Doctrine/ORM/Cache/Apc.php | 12 +-- lib/Doctrine/ORM/Cache/Array.php | 2 +- lib/Doctrine/ORM/Cache/Db.php | 11 +-- lib/Doctrine/ORM/Cache/Driver.php | 78 ------------------- lib/Doctrine/ORM/Cache/Exception.php | 34 -------- lib/Doctrine/ORM/Cache/Interface.php | 11 +-- lib/Doctrine/ORM/Cache/Memcache.php | 52 ++++++------- lib/Doctrine/ORM/Cache/Xcache.php | 10 +-- .../ORM/Mapping/AssociationMapping.php | 18 ----- .../ORM/Mapping/ClassMetadataFactory.php | 21 ++++- lib/Doctrine/ORM/Mapping/OneToOneMapping.php | 12 --- 11 files changed, 62 insertions(+), 199 deletions(-) delete mode 100644 lib/Doctrine/ORM/Cache/Driver.php delete mode 100644 lib/Doctrine/ORM/Cache/Exception.php diff --git a/lib/Doctrine/ORM/Cache/Apc.php b/lib/Doctrine/ORM/Cache/Apc.php index fcee4b724..77ac72097 100644 --- a/lib/Doctrine/ORM/Cache/Apc.php +++ b/lib/Doctrine/ORM/Cache/Apc.php @@ -18,31 +18,31 @@ * and is licensed under the LGPL. For more information, see * . */ - -#namespace Doctrine::ORM::Cache; + +#namespace Doctrine\ORM\Cache; /** * APC cache driver. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org + * @link www.doctrine-project.org * @since 1.0 * @version $Revision: 4910 $ * @author Konsta Vesterinen + * @author Roman Borschel */ -class Doctrine_Cache_Apc extends Doctrine_Cache_Driver +class Doctrine_ORM_Cache_ApcCache implements Doctrine_ORM_Cache_Cache { /** * constructor * * @param array $options associative array of cache driver options */ - public function __construct($options = array()) + public function __construct() { if ( ! extension_loaded('apc')) { throw new Doctrine_Cache_Exception('The apc extension must be loaded for using this backend !'); } - parent::__construct($options); } /** diff --git a/lib/Doctrine/ORM/Cache/Array.php b/lib/Doctrine/ORM/Cache/Array.php index 8d61e1fde..cd82169af 100644 --- a/lib/Doctrine/ORM/Cache/Array.php +++ b/lib/Doctrine/ORM/Cache/Array.php @@ -28,7 +28,7 @@ * @version $Revision: 4910 $ * @author Konsta Vesterinen */ -class Doctrine_Cache_Array implements Doctrine_Cache_Interface +class Doctrine_ORM_Cache_ArrayCache implements Doctrine_ORM_Cache_Cache { /** * @var array $data an array of cached data diff --git a/lib/Doctrine/ORM/Cache/Db.php b/lib/Doctrine/ORM/Cache/Db.php index bd5bd5352..47b495a91 100644 --- a/lib/Doctrine/ORM/Cache/Db.php +++ b/lib/Doctrine/ORM/Cache/Db.php @@ -30,8 +30,10 @@ * @version $Revision: 3931 $ * @author Konsta Vesterinen */ -class Doctrine_Cache_Db extends Doctrine_Cache_Driver implements Countable +class Doctrine_ORM_Cache_DbCache implements Doctrine_ORM_Cache_Cache, Countable { + private $_options = array(); + /** * constructor * @@ -40,17 +42,16 @@ class Doctrine_Cache_Db extends Doctrine_Cache_Driver implements Countable public function __construct($options) { if ( ! isset($options['connection']) || - ! ($options['connection'] instanceof Doctrine_Connection)) { + ! ($options['connection'] instanceof Doctrine_DBAL_Connection)) { - throw new Doctrine_Cache_Exception('Connection option not set.'); + throw new Doctrine_Exception('Connection option not set.'); } if ( ! isset($options['tableName']) || ! is_string($options['tableName'])) { - throw new Doctrine_Cache_Exception('Table name option not set.'); + throw new Doctrine_Exception('Table name option not set.'); } - $this->_options = $options; } diff --git a/lib/Doctrine/ORM/Cache/Driver.php b/lib/Doctrine/ORM/Cache/Driver.php deleted file mode 100644 index 99038fa72..000000000 --- a/lib/Doctrine/ORM/Cache/Driver.php +++ /dev/null @@ -1,78 +0,0 @@ -. - */ - -/** - * Base class for cache drivers. - * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org - * @since 1.0 - * @version $Revision: 4910 $ - * @author Konsta Vesterinen - */ -abstract class Doctrine_Cache_Driver implements Doctrine_Cache_Interface -{ - /** - * @var array $_options an array of options - */ - protected $_options = array(); - - /** - * constructor - * - * @param array $_options an array of options - */ - public function __construct($options) - { - $this->_options = $options; - } - - /** - * setOption - * - * @param mixed $option the option name - * @param mixed $value option value - * @return boolean TRUE on success, FALSE on failure - */ - public function setOption($option, $value) - { - if (isset($this->_options[$option])) { - $this->_options[$option] = $value; - return true; - } - return false; - } - - /** - * getOption - * - * @param mixed $option the option name - * @return mixed option value - */ - public function getOption($option) - { - if ( ! isset($this->_options[$option])) { - return null; - } - - return $this->_options[$option]; - } -} diff --git a/lib/Doctrine/ORM/Cache/Exception.php b/lib/Doctrine/ORM/Cache/Exception.php deleted file mode 100644 index 7ba86d28d..000000000 --- a/lib/Doctrine/ORM/Cache/Exception.php +++ /dev/null @@ -1,34 +0,0 @@ -. - */ -Doctrine::autoload('Doctrine_Exception'); -/** - * Doctrine_Cache_Exception - * - * @package Doctrine - * @subpackage Cache - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org - * @since 1.0 - * @version $Revision: 3882 $ - * @author Konsta Vesterinen - */ -class Doctrine_Cache_Exception extends Doctrine_Exception -{ } diff --git a/lib/Doctrine/ORM/Cache/Interface.php b/lib/Doctrine/ORM/Cache/Interface.php index ef608d0b7..564150889 100644 --- a/lib/Doctrine/ORM/Cache/Interface.php +++ b/lib/Doctrine/ORM/Cache/Interface.php @@ -19,18 +19,19 @@ * . */ +#namespace Doctrine\ORM\Cache; + /** - * Doctrine_Cache_Interface + * Interface for cache drivers. * - * @package Doctrine - * @subpackage Cache * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org + * @link www.doctrine-project.org * @since 1.0 * @version $Revision: 3931 $ * @author Konsta Vesterinen + * @author Roman Borschel */ -interface Doctrine_Cache_Interface +interface Doctrine_ORM_Cache_Cache { /** * Test if a cache entry is available for the given id and (if yes) return it (false else). diff --git a/lib/Doctrine/ORM/Cache/Memcache.php b/lib/Doctrine/ORM/Cache/Memcache.php index 0b1da74f0..ec163d7d6 100644 --- a/lib/Doctrine/ORM/Cache/Memcache.php +++ b/lib/Doctrine/ORM/Cache/Memcache.php @@ -28,45 +28,43 @@ * @version $Revision: 4910 $ * @author Konsta Vesterinen */ -class Doctrine_Cache_Memcache extends Doctrine_Cache_Driver +class Doctrine_ORM_Cache_MemcacheCache implements Doctrine_ORM_Cache_Cache { /** * @var Memcache $_memcache memcache object */ - protected $_memcache = null; + private $_memcache; /** * constructor * * @param array $options associative array of cache driver options */ - public function __construct($options = array()) + public function __construct() { if ( ! extension_loaded('memcache')) { throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.'); } - parent::__construct($options); + } - if (isset($options['servers'])) { - $value= $options['servers']; - if (isset($value['host'])) { - // in this case, $value seems to be a simple associative array (one server only) - $value = array(0 => $value); // let's transform it into a classical array of associative arrays - } - $this->setOption('servers', $value); - } - - $this->_memcache = new Memcache; + /** + * Sets the memcache instance to use. + * + * @param Memcache $memcache + */ + public function setMemcache(Memcache $memcache) + { + $this->_memcache = $memcache; + } - foreach ($this->_options['servers'] as $server) { - if ( ! array_key_exists('persistent', $server)) { - $server['persistent'] = true; - } - if ( ! array_key_exists('port', $server)) { - $server['port'] = 11211; - } - $this->_memcache->addServer($server['host'], $server['port'], $server['persistent']); - } + /** + * Gets the memcache instance used by the cache. + * + * @return Memcache + */ + public function getMemcache() + { + return $this->_memcache; } /** @@ -104,13 +102,7 @@ class Doctrine_Cache_Memcache extends Doctrine_Cache_Driver */ public function save($id, $data, $lifeTime = false) { - if ($this->_options['compression']) { - $flag = MEMCACHE_COMPRESSED; - } else { - $flag = 0; - } - - $result = $this->_memcache->set($id, $data, $flag, $lifeTime); + return $this->_memcache->set($id, $data, 0, $lifeTime); } /** diff --git a/lib/Doctrine/ORM/Cache/Xcache.php b/lib/Doctrine/ORM/Cache/Xcache.php index e8b35fa58..1cc801169 100644 --- a/lib/Doctrine/ORM/Cache/Xcache.php +++ b/lib/Doctrine/ORM/Cache/Xcache.php @@ -28,20 +28,16 @@ * @version $Revision: $ * @author Dmitry Bakaleinik (dima@snaiper.net) */ -class Doctrine_Cache_Xcache extends Doctrine_Cache_Driver +class Doctrine_ORM_Cache_XcacheCache implements Doctrine_ORM_Cache_Cache { /** * constructor - * - * @param array $options associative array of cache driver options */ - public function __construct($options = array()) + public function __construct() { if ( ! extension_loaded('xcache')) { - throw new Doctrine_Cache_Exception('In order to use Xcache driver, the xcache extension must be loaded.'); + throw new Doctrine_Exception('In order to use Xcache driver, the xcache extension must be loaded.'); } - - parent::__construct($options); } /** diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php index 9192c87b8..100c0e817 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php +++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php @@ -121,27 +121,9 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping */ public function __construct(array $mapping) { - //$this->_initMappingArray(); - //$mapping = $this->_validateAndCompleteMapping($mapping); - //$this->_mapping = array_merge($this->_mapping, $mapping);*/ - $this->_validateAndCompleteMapping($mapping); } - protected function _initMappingArray() - { - $this->_mapping = array( - 'fieldName' => null, - 'sourceEntity' => null, - 'targetEntity' => null, - 'mappedBy' => null, - 'joinColumns' => null, - 'joinTable' => null, - 'optional' => true, - 'cascades' => array() - ); - } - /** * Validates & completes the mapping. Mapping defaults are applied here. * diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 7774ae0ee..9a78d831d 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -43,7 +43,6 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory private $_cacheDriver; /** - * Constructor. * Creates a new factory instance that uses the given metadata driver implementation. * * @param $driver The metadata driver to use. @@ -54,11 +53,21 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory $this->_targetPlatform = $targetPlatform; } + /** + * Sets the cache driver used by the factory to cache ClassMetadata instances. + * + * @param object $cacheDriver + */ public function setCacheDriver($cacheDriver) { $this->_cacheDriver = $cacheDriver; } + /** + * Gets the cache driver used by the factory to cache ClassMetadata instances. + * + * @return object + */ public function getCacheDriver() { return $this->_cacheDriver; @@ -75,10 +84,10 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory if ( ! isset($this->_loadedMetadata[$className])) { if ($this->_cacheDriver) { if ($this->_cacheDriver->contains("$className\$CLASSMETADATA")) { - $this->_loadedMetadata[$className] = $this->_cacheDriver->get("$className\$CLASSMETADATA"); + $this->_loadedMetadata[$className] = $this->_cacheDriver->fetch("$className\$CLASSMETADATA"); } else { $this->_loadMetadata($className); - $this->_cacheDriver->put("$className\$CLASSMETADATA", $this->_loadedMetadata[$className]); + $this->_cacheDriver->save($this->_loadedMetadata[$className], "$className\$CLASSMETADATA", null); } } else { $this->_loadMetadata($className); @@ -144,6 +153,12 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory } } + /** + * Creates a new ClassMetadata instance for the given class name. + * + * @param string $className + * @return Doctrine\ORM\Mapping\ClassMetadata + */ protected function _newClassMetadataInstance($className) { return new Doctrine_ORM_Mapping_ClassMetadata($className); diff --git a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php index 9fabda4ab..5a608253e 100644 --- a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php +++ b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php @@ -52,7 +52,6 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat protected $_deleteOrphans = false; /** - * Constructor. * Creates a new OneToOneMapping. * * @param array $mapping The mapping info. @@ -61,17 +60,6 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat { parent::__construct($mapping); } - - /** - * {@inheritdoc} - * - * @override - */ - protected function _initMappingArray() - { - parent::_initMappingArray(); - $this->_mapping['deleteOrphans'] = false; - } /** * {@inheritdoc}