diff --git a/UPGRADE_TO_1_2 b/UPGRADE_TO_1_2 index ef78cbbd8..74aa5c80e 100644 --- a/UPGRADE_TO_1_2 +++ b/UPGRADE_TO_1_2 @@ -812,7 +812,7 @@ fetching relationships. Now if we were to do the following PHP we'll get the SQL with an order by. [php] - $q = Doctrine::getTable('User') + $q = Doctrine_Core::getTable('User') ->createQuery('u') ->leftJoin('u.Articles a'); @@ -826,7 +826,7 @@ Now you should see this SQL query. Or if you lazily fetch the `Articles` they will be lazily loaded with the order by. [php] - $user = Doctrine::getTable('User')->find(1); + $user = Doctrine_Core::getTable('User')->find(1); $articles = $user->Articles; This would execute the following SQL query. diff --git a/lib/Doctrine/Cache/Memcache.php b/lib/Doctrine/Cache/Memcache.php index f366c204d..ed34fe885 100644 --- a/lib/Doctrine/Cache/Memcache.php +++ b/lib/Doctrine/Cache/Memcache.php @@ -43,7 +43,7 @@ class Doctrine_Cache_Memcache extends Doctrine_Cache_Driver * * @param array $options associative array of cache driver options */ - public function __construct($options = array()) + public function __construct($options = array()) { if ( ! extension_loaded('memcache')) { throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.'); @@ -59,16 +59,13 @@ public function __construct($options = array()) $this->setOption('servers', $value); } - $this->_memcache = new Memcache; + $this->_memcache = new Memcached; 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']); + $this->_memcache->addServer($server['host'], $server['port']); } } @@ -105,13 +102,7 @@ protected function _doContains($id) */ protected function _doSave($id, $data, $lifeTime = false) { - if ($this->_options['compression']) { - $flag = MEMCACHE_COMPRESSED; - } else { - $flag = 0; - } - - return $this->_memcache->set($id, $data, $flag, $lifeTime); + return $this->_memcache->set($id, $data, $lifeTime); } /** diff --git a/lib/Doctrine/Cache/Memcached.php b/lib/Doctrine/Cache/Memcached.php new file mode 100644 index 000000000..9e823ef87 --- /dev/null +++ b/lib/Doctrine/Cache/Memcached.php @@ -0,0 +1,142 @@ +. + */ + +/** + * Memcached cache driver + * + * @package Doctrine + * @subpackage Cache + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 1.0 + * @version $Revision: 7490 $ + * @author Konsta Vesterinen + * @author Jonathan H. Wage + */ +class Doctrine_Cache_Memcached extends Doctrine_Cache_Driver +{ + /** + * @var Memcache $_memcached memcache object + */ + protected $_memcached = null; + + /** + * constructor + * + * @param array $options associative array of cache driver options + */ + public function __construct($options = array()) + { + if ( ! extension_loaded('memcached')) { + throw new Doctrine_Cache_Exception('In order to use Memcached driver, the memcached 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->_memcached = new Memcached; + + foreach ($this->_options['servers'] as $server) { + if ( ! array_key_exists('port', $server)) { + $server['port'] = 11211; + } + $this->_memcached->addServer($server['host'], $server['port']); + } + } + + /** + * Test if a cache record exists for the passed id + * + * @param string $id cache id + * @return mixed Returns either the cached data or false + */ + protected function _doFetch($id, $testCacheValidity = true) + { + return $this->_memcached->get($id); + } + + /** + * Test if a cache is available or not (for the given id) + * + * @param string $id cache id + * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record + */ + protected function _doContains($id) + { + return (bool) $this->_memcached->get($id); + } + + /** + * Save a cache record directly. This method is implemented by the cache + * drivers and used in Doctrine_Cache_Driver::save() + * + * @param string $id cache id + * @param string $data data to cache + * @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime) + * @return boolean true if no problem + */ + protected function _doSave($id, $data, $lifeTime = false) + { + return $this->_memcached->set($id, $data, $lifeTime); + } + + /** + * Remove a cache record directly. This method is implemented by the cache + * drivers and used in Doctrine_Cache_Driver::delete() + * + * @param string $id cache id + * @return boolean true if no problem + */ + protected function _doDelete($id) + { + return $this->_memcached->delete($id); + } + + /** + * Fetch an array of all keys stored in cache + * + * @return array Returns the array of cache keys + */ + protected function _getCacheKeys() + { + $keys = array(); + $allSlabs = $this->_memcached->getExtendedStats('slabs'); + + foreach ($allSlabs as $server => $slabs) { + foreach (array_keys($slabs) as $slabId) { + $dump = $this->_memcached->getExtendedStats('cachedump', (int) $slabId); + foreach ($dump as $entries) { + if ($entries) { + $keys = array_merge($keys, array_keys($entries)); + } + } + } + } + return $keys; + } +} \ No newline at end of file diff --git a/lib/Doctrine/Hydrator/RecordDriver.php b/lib/Doctrine/Hydrator/RecordDriver.php index b4944428b..bd60adf8f 100644 --- a/lib/Doctrine/Hydrator/RecordDriver.php +++ b/lib/Doctrine/Hydrator/RecordDriver.php @@ -106,7 +106,7 @@ public function setLastElement(&$prev, &$coll, $index, $dqlAlias, $oneToOne) return; } - if (count($coll) > 0) { + if (is_object($coll) && count($coll) > 0) { $prev[$dqlAlias] = $coll->getLast(); } } diff --git a/lib/Doctrine/Query/Tokenizer.php b/lib/Doctrine/Query/Tokenizer.php index 402274132..aed58797d 100644 --- a/lib/Doctrine/Query/Tokenizer.php +++ b/lib/Doctrine/Query/Tokenizer.php @@ -93,7 +93,7 @@ public function tokenizeQuery($query) break; case 'by': - continue; + break; default: if ( ! isset($p)) { diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 4cf111a0c..e4bf69ffb 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -31,8 +31,8 @@ * @version $Revision$ * @link www.doctrine-project.org * @since 1.0 - * @method mixed findBy*(mixed $value) magic finders; @see __call() - * @method mixed findOneBy*(mixed $value) magic finders; @see __call() + * method mixed findBy*(mixed $value) magic finders; @see __call() + * method mixed findOneBy*(mixed $value) magic finders; @see __call() */ class Doctrine_Table extends Doctrine_Configurable implements Countable, Serializable {