Commit 93e6cabe authored by jwage's avatar jwage

[2.0][DDC-48][DDC-47] Refactored cache drivers to allow more control over...

[2.0][DDC-48][DDC-47] Refactored cache drivers to allow more control over deleting, added namespacing to cache drivers and implemented clear-cache task
parent 5b60f878
<?php
/*
* $Id$
*
* 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.doctrine-project.org>.
*/
namespace Doctrine\Common\Cache;
/**
* Abstract cache driver class
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
abstract class AbstractCache implements Cache
{
/* @var string $cacheIdsIndexId The cache id to store the index of cache ids under */
private $_cacheIdsIndexId = 'doctrine_cache_ids';
/* @var string $namespace The namespace to prefix all cache ids with */
private $_namespace = null;
/**
* Set the namespace to prefix all cache ids with
*
* @param string $namespace
* @return void
*/
public function setNamespace($namespace)
{
$this->_namespace = $namespace;
}
/**
* {@inheritdoc}
*/
public function fetch($id)
{
$id = $this->_getNamespacedId($id);
return $this->_doFetch($this->_getNamespacedId($id));
}
/**
* {@inheritdoc}
*/
public function contains($id)
{
$id = $this->_getNamespacedId($id);
return $this->_doContains($id);
}
/**
* {@inheritdoc}
*/
public function save($id, $data, $lifeTime = false)
{
$id = $this->_getNamespacedId($id);
if ($this->_doSave($id, $data, $lifeTime)) {
$this->_saveId($id);
return true;
}
return false;
}
/**
* {@inheritdoc}
*/
public function delete($id)
{
$id = $this->_getNamespacedId($id);
if (strpos($id, '*') !== false) {
return $this->deleteByRegex('/' . str_replace('*', '.*', $id) . '/');
}
if ($this->_doDelete($id)) {
$this->_deleteId($id);
return true;
}
return false;
}
/**
* Delete all cache entries.
*
* @return array $deleted Array of the deleted cache ids
*/
public function deleteAll()
{
$ids = $this->getIds();
foreach ($ids as $id) {
$this->delete($id);
}
return $ids;
}
/**
* Delete cache entries where the id matches a PHP regular expressions
*
* @param string $regex
* @return array $deleted Array of the deleted cache ids
*/
public function deleteByRegex($regex)
{
$deleted = array();
$ids = $this->getIds();
foreach ($ids as $id) {
if (preg_match($regex, $id)) {
$this->delete($id);
$deleted[] = $id;
}
}
return $deleted;
}
/**
* Delete cache entries where the id has the passed prefix
*
* @param string $prefix
* @return array $deleted Array of the deleted cache ids
*/
public function deleteByPrefix($prefix)
{
$deleted = array();
$ids = $this->getIds();
foreach ($ids as $id) {
if (strpos($id, $prefix) == 0) {
$this->delete($id);
$deleted[] = $id;
}
}
return $deleted;
}
/**
* Delete cache entries where the id has the passed suffix
*
* @param string $suffix
* @return array $deleted Array of the deleted cache ids
*/
public function deleteBySuffix($suffix)
{
$deleted = array();
$ids = $this->getIds();
foreach ($ids as $id) {
if (substr($id, -1 * strlen($suffix)) == $suffix) {
$this->delete($id);
$deleted[] = $id;
}
}
return $deleted;
}
/**
* Count and return the number of cache entries.
*
* @return integer $count
*/
public function count()
{
$ids = $this->getIds();
return $ids ? count($ids) : 0;
}
/**
* Get an array of all the cache ids stored
*
* @return array $ids
*/
public function getIds()
{
$ids = $this->fetch($this->_cacheIdsIndexId);
return $ids ? $ids : array();
}
/**
* Prefix the passed id with the configured namespace value
*
* @param string $id The id to namespace
* @return string $id The namespaced id
*/
private function _getNamespacedId($id)
{
if ( ! $this->_namespace || strpos($id, $this->_namespace) === 0) {
return $id;
} else {
return $this->_namespace . $id;
}
}
/**
* Save a cache id to the index of cache ids
*
* @param string $id
* @return boolean TRUE if the id was successfully stored in the cache, FALSE otherwise.
*/
private function _saveId($id)
{
$ids = $this->getIds();
$ids[] = $id;
$cacheIdsIndexId = $this->_getNamespacedId($this->_cacheIdsIndexId);
return $this->_doSave($cacheIdsIndexId, $ids, null);
}
/**
* Delete a cache id from the index of cache ids
*
* @param string $id
* @return boolean TRUE if the entry was successfully removed from the cache, FALSE otherwise.
*/
private function _deleteId($id)
{
$ids = $this->getIds();
$key = array_search($id, $ids);
if ($key !== false) {
unset($ids[$key]);
$cacheIdsIndexId = $this->_getNamespacedId($this->_cacheIdsIndexId);
return $this->_doSave($cacheIdsIndexId, $ids, null);
}
return false;
}
/**
* Fetches an entry from the cache.
*
* @param string $id cache id The id of the cache entry to fetch.
* @return string The cached data or FALSE, if no cache entry exists for the given id.
*/
abstract protected function _doFetch($id);
/**
* Test if an entry exists in the cache.
*
* @param string $id cache id The cache id of the entry to check for.
* @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
*/
abstract protected function _doContains($id);
/**
* Puts data into the cache.
*
* @param string $id The cache id.
* @param string $data The cache entry/data.
* @param int $lifeTime The lifetime. If != false, sets a specific lifetime for this cache entry (null => infinite lifeTime).
* @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
*/
abstract protected function _doSave($id, $data, $lifeTime = false);
/**
* Deletes a cache entry.
*
* @param string $id cache id
* @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
*/
abstract protected function _doDelete($id);
}
\ No newline at end of file
...@@ -32,12 +32,12 @@ namespace Doctrine\Common\Cache; ...@@ -32,12 +32,12 @@ namespace Doctrine\Common\Cache;
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
*/ */
class ApcCache implements Cache class ApcCache extends AbstractCache
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($id) protected function _doFetch($id)
{ {
return apc_fetch($id); return apc_fetch($id);
} }
...@@ -45,7 +45,7 @@ class ApcCache implements Cache ...@@ -45,7 +45,7 @@ class ApcCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function contains($id) protected function _doContains($id)
{ {
return apc_fetch($id) === false ? false : true; return apc_fetch($id) === false ? false : true;
} }
...@@ -53,7 +53,7 @@ class ApcCache implements Cache ...@@ -53,7 +53,7 @@ class ApcCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function save($id, $data, $lifeTime = false) protected function _doSave($id, $data, $lifeTime = false)
{ {
return (bool) apc_store($id, $data, $lifeTime); return (bool) apc_store($id, $data, $lifeTime);
} }
...@@ -61,7 +61,7 @@ class ApcCache implements Cache ...@@ -61,7 +61,7 @@ class ApcCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function delete($id) protected function _doDelete($id)
{ {
return apc_delete($id); return apc_delete($id);
} }
......
...@@ -32,7 +32,7 @@ namespace Doctrine\Common\Cache; ...@@ -32,7 +32,7 @@ namespace Doctrine\Common\Cache;
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
*/ */
class ArrayCache implements Cache class ArrayCache extends AbstractCache
{ {
/** /**
* @var array $data * @var array $data
...@@ -42,7 +42,7 @@ class ArrayCache implements Cache ...@@ -42,7 +42,7 @@ class ArrayCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($id) protected function _doFetch($id)
{ {
if (isset($this->data[$id])) { if (isset($this->data[$id])) {
return $this->data[$id]; return $this->data[$id];
...@@ -53,7 +53,7 @@ class ArrayCache implements Cache ...@@ -53,7 +53,7 @@ class ArrayCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function contains($id) protected function _doContains($id)
{ {
return isset($this->data[$id]); return isset($this->data[$id]);
} }
...@@ -61,34 +61,18 @@ class ArrayCache implements Cache ...@@ -61,34 +61,18 @@ class ArrayCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function save($id, $data, $lifeTime = false) protected function _doSave($id, $data, $lifeTime = false)
{ {
$this->data[$id] = $data; $this->data[$id] = $data;
return true;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function delete($id) protected function _doDelete($id)
{ {
unset($this->data[$id]); unset($this->data[$id]);
} return true;
/**
* {@inheritdoc}
*/
public function deleteAll()
{
$this->data = array();
}
/**
* count
*
* @return integer
*/
public function count()
{
return count($this->data);
} }
} }
\ No newline at end of file
...@@ -34,7 +34,7 @@ use \Memcache; ...@@ -34,7 +34,7 @@ use \Memcache;
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
*/ */
class MemcacheCache implements Cache class MemcacheCache extends AbstractCache
{ {
/** /**
* @var Memcache * @var Memcache
...@@ -64,7 +64,7 @@ class MemcacheCache implements Cache ...@@ -64,7 +64,7 @@ class MemcacheCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($id) protected function _doFetch($id)
{ {
return $this->_memcache->get($id); return $this->_memcache->get($id);
} }
...@@ -72,7 +72,7 @@ class MemcacheCache implements Cache ...@@ -72,7 +72,7 @@ class MemcacheCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function contains($id) protected function _doContains($id)
{ {
return (bool) $this->_memcache->get($id); return (bool) $this->_memcache->get($id);
} }
...@@ -80,7 +80,7 @@ class MemcacheCache implements Cache ...@@ -80,7 +80,7 @@ class MemcacheCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function save($id, $data, $lifeTime = false) protected function _doSave($id, $data, $lifeTime = false)
{ {
return $this->_memcache->set($id, $data, 0, $lifeTime); return $this->_memcache->set($id, $data, 0, $lifeTime);
} }
...@@ -88,7 +88,7 @@ class MemcacheCache implements Cache ...@@ -88,7 +88,7 @@ class MemcacheCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function delete($id) protected function _doDelete($id)
{ {
return $this->_memcache->delete($id); return $this->_memcache->delete($id);
} }
......
...@@ -32,20 +32,20 @@ namespace Doctrine\Common\Cache; ...@@ -32,20 +32,20 @@ namespace Doctrine\Common\Cache;
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
*/ */
class XcacheCache implements Cache class XcacheCache extends AbstractCache
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($id) protected function _doFetch($id)
{ {
return $this->contains($id) ? xcache_get($id) : false; return $this->_doContains($id) ? xcache_get($id) : false;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function contains($id) protected function _doContains($id)
{ {
return xcache_isset($id); return xcache_isset($id);
} }
...@@ -53,7 +53,7 @@ class XcacheCache implements Cache ...@@ -53,7 +53,7 @@ class XcacheCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function save($id, $data, $lifeTime = false) protected function _doSave($id, $data, $lifeTime = false)
{ {
return xcache_set($id, $data, $lifeTime); return xcache_set($id, $data, $lifeTime);
} }
...@@ -61,7 +61,7 @@ class XcacheCache implements Cache ...@@ -61,7 +61,7 @@ class XcacheCache implements Cache
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function delete($id) protected function _doDelete($id)
{ {
return xcache_unset($id); return xcache_unset($id);
} }
......
...@@ -102,8 +102,10 @@ class DoctrineException extends \Exception ...@@ -102,8 +102,10 @@ class DoctrineException extends \Exception
} else { } else {
$dumper = function ($value) { return var_export($value, true); }; $dumper = function ($value) { return var_export($value, true); };
$message = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $method)); $message = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $method));
$message = ucfirst(str_replace('_', ' ', $message)) $message = ucfirst(str_replace('_', ' ', $message));
. ' (' . implode(', ', array_map($dumper, $arguments)) . ')'; if ($arguments) {
$message .= ' (' . implode(', ', array_map($dumper, $arguments)) . ')';
}
} }
return new $class($message, $innerException); return new $class($message, $innerException);
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
namespace Doctrine\ORM; namespace Doctrine\ORM;
use Doctrine\Common\DoctrineException;
/** /**
* Configuration container for all configuration options of Doctrine. * Configuration container for all configuration options of Doctrine.
* It combines all configuration options from DBAL & ORM. * It combines all configuration options from DBAL & ORM.
......
...@@ -32,7 +32,8 @@ use Doctrine\Common\Util\Inflector, ...@@ -32,7 +32,8 @@ use Doctrine\Common\Util\Inflector,
* To include a new Task support, create a task: * To include a new Task support, create a task:
* *
* [php] * [php]
* class MyProject\Tools\Cli\Tasks\MyTask extends Doctrine\ORM\Tools\Cli\AbstractTask { * class MyProject\Tools\Cli\Tasks\MyTask extends Doctrine\ORM\Tools\Cli\AbstractTask
* {
* public function run(); * public function run();
* public function basicHelp(); * public function basicHelp();
* public function extendedHelp(); * public function extendedHelp();
...@@ -47,8 +48,7 @@ use Doctrine\Common\Util\Inflector, ...@@ -47,8 +48,7 @@ use Doctrine\Common\Util\Inflector,
* *
* To execute, just type any classify-able name: * To execute, just type any classify-able name:
* *
* [bash] * $ cli.php my-task
* cli.php my-task
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
...@@ -90,7 +90,9 @@ class Cli ...@@ -90,7 +90,9 @@ class Cli
'run-sql' => $ns . '\RunSqlTask', 'run-sql' => $ns . '\RunSqlTask',
'run-dql' => $ns . '\RunDqlTask', 'run-dql' => $ns . '\RunDqlTask',
'convert-mapping' => $ns . '\ConvertMappingTask', 'convert-mapping' => $ns . '\ConvertMappingTask',
'generate-proxies'=> $ns . '\GenerateProxiesTask' 'generate-proxies' => $ns . '\GenerateProxiesTask',
'clear-cache' => $ns . '\ClearCacheTask',
'ensure-production-settings' => $ns . '\EnsureProductionSettingsTask'
)); ));
} }
......
<?php
/*
* $Id$
*
* 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.doctrine-project.org>.
*/
namespace Doctrine\ORM\Tools\Cli\Tasks;
use Doctrine\Common\Cache\AbstractDriver;
/**
* CLI Task to clear the cache of the various cache drivers
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class ClearCacheTask extends AbstractTask
{
public function basicHelp()
{
$this->_writeSynopsis($this->getPrinter());
}
public function extendedHelp()
{
$printer = $this->getPrinter();
$printer->write('Task: ')->writeln('clear-cache', 'KEYWORD')
->write('Synopsis: ');
$this->_writeSynopsis($printer);
$printer->writeln('Description: Clear cache from configured query, result and metadata drivers.')
->writeln('Options:')
->write('--query', 'OPT_ARG')
->writeln("\t\t\tClear the query cache.")
->write('--result', 'OPT_ARG')
->writeln("\t\tClear the result cache.")
->write('--metadata', 'OPT_ARG')
->writeln("\t\tClear the metadata cache.")
->write('--id=<ID>', 'REQ_ARG')
->writeln("\t\tThe id of the cache entry to delete (accepts * wildcards).")
->write('--regex=<REGEX>', 'REQ_ARG')
->writeln("\t\tDelete cache entries that match the given regular expression.")
->write('--prefix=<PREFIX>', 'REQ_ARG')
->writeln("\tDelete cache entries that have the given prefix.")
->write('--suffix=<SUFFIX>', 'REQ_ARG')
->writeln("\tDelete cache entries that have the given suffix.");
}
private function _writeSynopsis($printer)
{
$printer->write('clear-cache', 'KEYWORD')
->write(' (--query | --result | --metadata)', 'OPT_ARG')
->write(' [--id=<ID>]', 'REQ_ARG')
->write(' [--regex=<REGEX>]', 'REQ_ARG')
->write(' [--prefix=<PREFIX>]', 'REQ_ARG')
->writeln(' [--suffix=<SUFFIX>]', 'REQ_ARG');
}
public function validate()
{
if ( ! parent::validate()) {
return false;
}
$printer = $this->getPrinter();
$args = $this->getArguments();
// When clearing the query cache no need to specify
// id, regex, prefix or suffix.
if ((isset($args['query']) || isset($args['metadata']))
&& (isset($args['id'])
|| isset($args['regex'])
|| isset($args['prefix'])
|| isset($args['suffix']))) {
$printer->writeln('When clearing the query or metadata cache do not specify any --id, --regex, --prefix or --suffix.', 'ERROR');
return false;
}
return true;
}
public function run()
{
$printer = $this->getPrinter();
$args = $this->getArguments();
$query = isset($args['query']);
$result = isset($args['result']);
$metadata = isset($args['metadata']);
$id = isset($args['id']) ? $args['id'] : null;
$regex = isset($args['regex']) ? $args['regex'] : null;
$prefix = isset($args['prefix']) ? $args['prefix'] : null;
$suffix = isset($args['suffix']) ? $args['suffix'] : null;
$all = false;
if ( ! $query && ! $result && ! $metadata) {
$all = true;
}
$configuration = $this->_em->getConfiguration();
if ($query || $all) {
$this->_doDelete(
'query',
$configuration->getQueryCacheImpl(),
$id,
$regex,
$prefix,
$suffix
);
}
if ($result || $all) {
$this->_doDelete(
'result',
$configuration->getResultCacheImpl(),
$id,
$regex,
$prefix,
$suffix
);
}
if ($metadata || $all) {
$this->_doDelete(
'metadata',
$configuration->getMetadataCacheImpl(),
$id,
$regex,
$prefix,
$suffix
);
}
}
private function _doDelete($type, $cacheDriver, $id, $regex, $prefix, $suffix)
{
$printer = $this->getPrinter();
if ( ! $cacheDriver) {
$printer->writeln('No driver has been configured for the ' . $type . ' cache.', 'ERROR');
return false;
}
if ($id) {
$printer->writeln('Clearing ' . $type . ' cache entries that match the id "' . $id . '"', 'INFO');
$deleted = $cacheDriver->delete($id);
if (is_array($deleted)) {
$this->_printDeleted($printer, $type, $deleted);
} else if (is_bool($deleted) && $deleted) {
$this->_printDeleted($printer, $type, array($id));
}
}
if ($regex) {
$printer->writeln('Clearing ' . $type . ' cache entries that match the regular expression "' . $regex . '"', 'INFO');
$this->_printDeleted($printer, $type, $cacheDriver->deleteByRegex('/' . $regex. '/'));
}
if ($prefix) {
$printer->writeln('Clearing ' . $type . ' cache entries that have the prefix "' . $prefix . '"', 'INFO');
$this->_printDeleted($printer, $type, $cacheDriver->deleteByPrefix($prefix));
}
if ($suffix) {
$printer->writeln('Clearing ' . $type . ' cache entries that have the suffix "' . $suffix . '"', 'INFO');
$this->_printDeleted($printer, $type, $cacheDriver->deleteBySuffix($suffix));
}
if ( ! $id && ! $regex && ! $prefix && ! $suffix) {
$printer->writeln('Clearing all ' . $type . ' cache entries', 'INFO');
$this->_printDeleted($printer, $type, $cacheDriver->deleteAll());
}
}
private function _printDeleted($printer, $type, array $ids)
{
if ( ! empty($ids)) {
foreach ($ids as $id) {
$printer->writeln(' - ' . $id);
}
} else {
$printer->writeln('No ' . $type . ' cache entries found', 'ERROR');
}
$printer->writeln("");
}
}
\ No newline at end of file
...@@ -107,7 +107,7 @@ class ConvertMappingTask extends AbstractTask ...@@ -107,7 +107,7 @@ class ConvertMappingTask extends AbstractTask
return false; return false;
} }
if ($args['to'] != 'annotation' && isset($args['extend'])) { if ($args['to'] != 'annotation' && isset($args['extend'])) {
$printer->writeln('You can only use the --extend argument when converting to annoations.'); $printer->writeln('You can only use the --extend argument when converting to annoations.', 'ERROR');
return false; return false;
} }
if ($args['from'][0] == 'database') { if ($args['from'][0] == 'database') {
......
<?php
/*
* $Id$
*
* 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.doctrine-project.org>.
*/
namespace Doctrine\ORM\Tools\Cli\Tasks;
use Doctrine\Common\Cache\AbstractDriver;
/**
* CLI Task to ensure that Doctrine is properly configured for a production environment.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class EnsureProductionSettingsTask extends AbstractTask
{
public function basicHelp()
{
$this->_writeSynopsis($this->getPrinter());
}
public function extendedHelp()
{
$printer = $this->getPrinter();
$printer->write('Task: ')->writeln('ensure-production-settings', 'KEYWORD')
->write('Synopsis: ');
$this->_writeSynopsis($printer);
$printer->writeln('Description: Verify that Doctrine is properly configured for a production environment.');
}
private function _writeSynopsis($printer)
{
$printer->writeln('ensure-production-settings', 'KEYWORD');
}
public function run()
{
$printer = $this->getPrinter();
try {
$this->_em->getConfiguration()->ensureProductionSettings();
} catch (\Doctrine\Common\DoctrineException $e) {
$printer->writeln($e->getMessage(), 'ERROR');
}
}
}
\ No newline at end of file
...@@ -19,9 +19,10 @@ class AllTests ...@@ -19,9 +19,10 @@ class AllTests
{ {
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Common Cache Tests'); $suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Common Cache Tests');
$suite->addTestSuite('Doctrine\Tests\Common\Cache\CacheTest');
$suite->addTestSuite('Doctrine\Tests\Common\Cache\ApcCacheTest'); $suite->addTestSuite('Doctrine\Tests\Common\Cache\ApcCacheTest');
$suite->addTestSuite('Doctrine\Tests\Common\Cache\ArrayCacheTest'); $suite->addTestSuite('Doctrine\Tests\Common\Cache\ArrayCacheTest');
//$suite->addTestSuite('Doctrine\Tests\Common\Cache\MemcacheCacheTest'); $suite->addTestSuite('Doctrine\Tests\Common\Cache\MemcacheCacheTest');
$suite->addTestSuite('Doctrine\Tests\Common\Cache\XcacheCacheTest'); $suite->addTestSuite('Doctrine\Tests\Common\Cache\XcacheCacheTest');
return $suite; return $suite;
......
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\ArrayCache;
require_once __DIR__ . '/../../TestInit.php';
class CacheTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testCount()
{
$cache = new ArrayCache();
$cache->save('test_key1', '1');
$cache->save('test_key2', '2');
$this->assertEquals($cache->count(), 2);
}
public function testDeleteAll()
{
$cache = new ArrayCache();
$cache->save('test_key1', '1');
$cache->save('test_key2', '2');
$cache->deleteAll();
$this->assertEquals($cache->count(), 0);
}
public function testDeleteByRegex()
{
$cache = new ArrayCache();
$cache->save('test_key1', '1');
$cache->save('test_key2', '2');
$cache->deleteByRegex('/test_key[0-9]/');
$this->assertEquals($cache->count(), 0);
}
public function testDeleteByPrefix()
{
$cache = new ArrayCache();
$cache->save('test_key1', '1');
$cache->save('test_key2', '2');
$cache->deleteByPrefix('test_key');
$this->assertEquals($cache->count(), 0);
}
public function testDeleteBySuffix()
{
$cache = new ArrayCache();
$cache->save('1test_key', '1');
$cache->save('2test_key', '2');
$cache->deleteBySuffix('test_key');
$this->assertEquals($cache->count(), 0);
}
public function testDeleteByWildcard()
{
$cache = new ArrayCache();
$cache->save('test_key1', '1');
$cache->save('test_key2', '2');
$cache->delete('test_key*');
$this->assertEquals($cache->count(), 0);
}
public function testNamespace()
{
$cache = new ArrayCache();
$cache->setNamespace('test_');
$cache->save('key1', 'test');
$this->assertTrue($cache->contains('key1'));
$ids = $cache->getIds();
$this->assertTrue(in_array('test_key1', $ids));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment