cache driver corrections
This commit is contained in:
parent
7363fc3ec0
commit
1f6676f1d9
@ -18,31 +18,31 @@
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.org>.
|
||||
*/
|
||||
|
||||
#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 <kvesteri@cc.hut.fi>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@
|
||||
* @version $Revision: 4910 $
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
*/
|
||||
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
|
||||
|
@ -30,8 +30,10 @@
|
||||
* @version $Revision: 3931 $
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: Driver.php 4910 2008-09-12 08:51:56Z romanb $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.org>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 <kvesteri@cc.hut.fi>
|
||||
*/
|
||||
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];
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: Exception.php 3882 2008-02-22 18:11:35Z jwage $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.org>.
|
||||
*/
|
||||
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 <kvesteri@cc.hut.fi>
|
||||
*/
|
||||
class Doctrine_Cache_Exception extends Doctrine_Exception
|
||||
{ }
|
@ -19,18 +19,19 @@
|
||||
* <http://www.phpdoctrine.org>.
|
||||
*/
|
||||
|
||||
#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 <kvesteri@cc.hut.fi>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
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).
|
||||
|
@ -28,45 +28,43 @@
|
||||
* @version $Revision: 4910 $
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
|
@ -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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user