Commit a5313d6a authored by catch's avatar catch

Issue #1808112 by sun: Fixed Missing method visibility, bogus phpDoc and...

Issue #1808112 by sun: Fixed Missing method visibility, bogus phpDoc and coding style in Cache backend classes.
parent 716e8a83
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
* To access your custom cache bin, specify the name of the bin when storing * To access your custom cache bin, specify the name of the bin when storing
* or retrieving cached data: * or retrieving cached data:
* @code * @code
* cache_set($cid, $data, 'custom_bin', $expire); * cache('custom_bin')->set($cid, $data, $expire);
* cache_get($cid, 'custom_bin'); * cache('custom_bin')->get($cid);
* @endcode * @endcode
* *
* @see cache() * @see cache()
...@@ -60,7 +60,7 @@ interface CacheBackendInterface { ...@@ -60,7 +60,7 @@ interface CacheBackendInterface {
* @param $bin * @param $bin
* The cache bin for which the object is created. * The cache bin for which the object is created.
*/ */
function __construct($bin); public function __construct($bin);
/** /**
* Returns data from the persistent cache. * Returns data from the persistent cache.
...@@ -74,7 +74,7 @@ function __construct($bin); ...@@ -74,7 +74,7 @@ function __construct($bin);
* @return * @return
* The cache or FALSE on failure. * The cache or FALSE on failure.
*/ */
function get($cid); public function get($cid);
/** /**
* Returns data from the persistent cache when given an array of cache IDs. * Returns data from the persistent cache when given an array of cache IDs.
...@@ -87,7 +87,7 @@ function get($cid); ...@@ -87,7 +87,7 @@ function get($cid);
* @return * @return
* An array of the items successfully returned from cache indexed by cid. * An array of the items successfully returned from cache indexed by cid.
*/ */
function getMultiple(&$cids); public function getMultiple(&$cids);
/** /**
* Stores data in the persistent cache. * Stores data in the persistent cache.
...@@ -111,7 +111,7 @@ function getMultiple(&$cids); ...@@ -111,7 +111,7 @@ function getMultiple(&$cids);
* a node, both the node ID and the author's user ID might be passed in as * a node, both the node ID and the author's user ID might be passed in as
* tags. For example array('node' => array(123), 'user' => array(92)). * tags. For example array('node' => array(123), 'user' => array(92)).
*/ */
function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()); public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array());
/** /**
* Deletes an item from the cache. * Deletes an item from the cache.
...@@ -119,7 +119,7 @@ function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, arra ...@@ -119,7 +119,7 @@ function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, arra
* @param $cid * @param $cid
* The cache ID to delete. * The cache ID to delete.
*/ */
function delete($cid); public function delete($cid);
/** /**
* Deletes multiple items from the cache. * Deletes multiple items from the cache.
...@@ -127,17 +127,17 @@ function delete($cid); ...@@ -127,17 +127,17 @@ function delete($cid);
* @param $cids * @param $cids
* An array of $cids to delete. * An array of $cids to delete.
*/ */
function deleteMultiple(Array $cids); public function deleteMultiple(Array $cids);
/** /**
* Flushes all cache items in a bin. * Flushes all cache items in a bin.
*/ */
function flush(); public function flush();
/** /**
* Expires temporary items from the cache. * Expires temporary items from the cache.
*/ */
function expire(); public function expire();
/** /**
* Invalidates each tag in the $tags array. * Invalidates each tag in the $tags array.
...@@ -148,12 +148,12 @@ function expire(); ...@@ -148,12 +148,12 @@ function expire();
* *
* @see CacheBackendInterface::set() * @see CacheBackendInterface::set()
*/ */
function invalidateTags(array $tags); public function invalidateTags(array $tags);
/** /**
* Performs garbage collection on a cache bin. * Performs garbage collection on a cache bin.
*/ */
function garbageCollection(); public function garbageCollection();
/** /**
* Checks if a cache bin is empty. * Checks if a cache bin is empty.
...@@ -164,5 +164,5 @@ function garbageCollection(); ...@@ -164,5 +164,5 @@ function garbageCollection();
* @return * @return
* TRUE if the cache bin specified is empty. * TRUE if the cache bin specified is empty.
*/ */
function isEmpty(); public function isEmpty();
} }
...@@ -31,7 +31,7 @@ class DatabaseBackend implements CacheBackendInterface { ...@@ -31,7 +31,7 @@ class DatabaseBackend implements CacheBackendInterface {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::__construct(). * Implements Drupal\Core\Cache\CacheBackendInterface::__construct().
*/ */
function __construct($bin) { public function __construct($bin) {
// All cache tables should be prefixed with 'cache_', except for the // All cache tables should be prefixed with 'cache_', except for the
// default 'cache' bin. // default 'cache' bin.
if ($bin != 'cache') { if ($bin != 'cache') {
...@@ -43,7 +43,7 @@ function __construct($bin) { ...@@ -43,7 +43,7 @@ function __construct($bin) {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::get(). * Implements Drupal\Core\Cache\CacheBackendInterface::get().
*/ */
function get($cid) { public function get($cid) {
$cids = array($cid); $cids = array($cid);
$cache = $this->getMultiple($cids); $cache = $this->getMultiple($cids);
return reset($cache); return reset($cache);
...@@ -52,7 +52,7 @@ function get($cid) { ...@@ -52,7 +52,7 @@ function get($cid) {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple(). * Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().
*/ */
function getMultiple(&$cids) { public function getMultiple(&$cids) {
try { try {
// When serving cached pages, the overhead of using ::select() was found // When serving cached pages, the overhead of using ::select() was found
// to add around 30% overhead to the request. Since $this->bin is a // to add around 30% overhead to the request. Since $this->bin is a
...@@ -93,8 +93,6 @@ function getMultiple(&$cids) { ...@@ -93,8 +93,6 @@ function getMultiple(&$cids) {
* valid item to load. * valid item to load.
*/ */
protected function prepareItem($cache) { protected function prepareItem($cache) {
global $user;
if (!isset($cache->data)) { if (!isset($cache->data)) {
return FALSE; return FALSE;
} }
...@@ -118,7 +116,7 @@ protected function prepareItem($cache) { ...@@ -118,7 +116,7 @@ protected function prepareItem($cache) {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::set(). * Implements Drupal\Core\Cache\CacheBackendInterface::set().
*/ */
function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) { public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {
$fields = array( $fields = array(
'serialized' => 0, 'serialized' => 0,
'created' => REQUEST_TIME, 'created' => REQUEST_TIME,
...@@ -149,7 +147,7 @@ function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, arra ...@@ -149,7 +147,7 @@ function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, arra
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::delete(). * Implements Drupal\Core\Cache\CacheBackendInterface::delete().
*/ */
function delete($cid) { public function delete($cid) {
Database::getConnection()->delete($this->bin) Database::getConnection()->delete($this->bin)
->condition('cid', $cid) ->condition('cid', $cid)
->execute(); ->execute();
...@@ -158,7 +156,7 @@ function delete($cid) { ...@@ -158,7 +156,7 @@ function delete($cid) {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple(). * Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
*/ */
function deleteMultiple(array $cids) { public function deleteMultiple(array $cids) {
// Delete in chunks when a large array is passed. // Delete in chunks when a large array is passed.
do { do {
Database::getConnection()->delete($this->bin) Database::getConnection()->delete($this->bin)
...@@ -171,14 +169,14 @@ function deleteMultiple(array $cids) { ...@@ -171,14 +169,14 @@ function deleteMultiple(array $cids) {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::flush(). * Implements Drupal\Core\Cache\CacheBackendInterface::flush().
*/ */
function flush() { public function flush() {
Database::getConnection()->truncate($this->bin)->execute(); Database::getConnection()->truncate($this->bin)->execute();
} }
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::expire(). * Implements Drupal\Core\Cache\CacheBackendInterface::expire().
*/ */
function expire() { public function expire() {
Database::getConnection()->delete($this->bin) Database::getConnection()->delete($this->bin)
->condition('expire', CacheBackendInterface::CACHE_PERMANENT, '<>') ->condition('expire', CacheBackendInterface::CACHE_PERMANENT, '<>')
->condition('expire', REQUEST_TIME, '<') ->condition('expire', REQUEST_TIME, '<')
...@@ -188,7 +186,7 @@ function expire() { ...@@ -188,7 +186,7 @@ function expire() {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection(). * Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection().
*/ */
function garbageCollection() { public function garbageCollection() {
$this->expire(); $this->expire();
} }
...@@ -196,9 +194,9 @@ function garbageCollection() { ...@@ -196,9 +194,9 @@ function garbageCollection() {
* Compares two checksums of tags. Used to determine whether to serve a cached * Compares two checksums of tags. Used to determine whether to serve a cached
* item or treat it as invalidated. * item or treat it as invalidated.
* *
* @param integer @checksum * @param integer $checksum
* The initial checksum to compare against. * The initial checksum to compare against.
* @param array @tags * @param array $tags
* An array of tags to calculate a checksum for. * An array of tags to calculate a checksum for.
* *
* @return boolean * @return boolean
...@@ -214,7 +212,7 @@ protected function validTags($checksum, array $tags) { ...@@ -214,7 +212,7 @@ protected function validTags($checksum, array $tags) {
* @param array $tags * @param array $tags
* Associative array of tags to flatten. * Associative array of tags to flatten.
* *
* @return * @return array
* Numeric array of flattened tag identifiers. * Numeric array of flattened tag identifiers.
*/ */
protected function flattenTags(array $tags) { protected function flattenTags(array $tags) {
...@@ -288,7 +286,7 @@ protected function checksumTags($tags) { ...@@ -288,7 +286,7 @@ protected function checksumTags($tags) {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::isEmpty(). * Implements Drupal\Core\Cache\CacheBackendInterface::isEmpty().
*/ */
function isEmpty() { public function isEmpty() {
$this->garbageCollection(); $this->garbageCollection();
$query = Database::getConnection()->select($this->bin); $query = Database::getConnection()->select($this->bin);
$query->addExpression('1'); $query->addExpression('1');
......
...@@ -36,26 +36,26 @@ class InstallBackend extends DatabaseBackend { ...@@ -36,26 +36,26 @@ class InstallBackend extends DatabaseBackend {
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::get(). * Overrides Drupal\Core\Cache\DatabaseBackend::get().
*/ */
function get($cid) { public function get($cid) {
return FALSE; return FALSE;
} }
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::getMultiple(). * Overrides Drupal\Core\Cache\DatabaseBackend::getMultiple().
*/ */
function getMultiple(&$cids) { public function getMultiple(&$cids) {
return array(); return array();
} }
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::set(). * Overrides Drupal\Core\Cache\DatabaseBackend::set().
*/ */
function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {} public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {}
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::delete(). * Overrides Drupal\Core\Cache\DatabaseBackend::delete().
*/ */
function delete($cid) { public function delete($cid) {
try { try {
if (class_exists('Drupal\Core\Database\Database')) { if (class_exists('Drupal\Core\Database\Database')) {
parent::delete($cid); parent::delete($cid);
...@@ -67,7 +67,7 @@ function delete($cid) { ...@@ -67,7 +67,7 @@ function delete($cid) {
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::deleteMultiple(). * Overrides Drupal\Core\Cache\DatabaseBackend::deleteMultiple().
*/ */
function deleteMultiple(array $cids) { public function deleteMultiple(array $cids) {
try { try {
if (class_exists('Drupal\Core\Database\Database')) { if (class_exists('Drupal\Core\Database\Database')) {
parent::deleteMultiple($cids); parent::deleteMultiple($cids);
...@@ -79,7 +79,7 @@ function deleteMultiple(array $cids) { ...@@ -79,7 +79,7 @@ function deleteMultiple(array $cids) {
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::invalidateTags(). * Overrides Drupal\Core\Cache\DatabaseBackend::invalidateTags().
*/ */
function invalidateTags(array $tags) { public function invalidateTags(array $tags) {
try { try {
if (class_exists('Drupal\Core\Database\Database')) { if (class_exists('Drupal\Core\Database\Database')) {
parent::invalidateTags($tags); parent::invalidateTags($tags);
...@@ -91,7 +91,7 @@ function invalidateTags(array $tags) { ...@@ -91,7 +91,7 @@ function invalidateTags(array $tags) {
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::flush(). * Overrides Drupal\Core\Cache\DatabaseBackend::flush().
*/ */
function flush() { public function flush() {
try { try {
if (class_exists('Drupal\Core\Database\Database')) { if (class_exists('Drupal\Core\Database\Database')) {
parent::flush(); parent::flush();
...@@ -103,7 +103,7 @@ function flush() { ...@@ -103,7 +103,7 @@ function flush() {
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::expire(). * Overrides Drupal\Core\Cache\DatabaseBackend::expire().
*/ */
function expire() { public function expire() {
try { try {
if (class_exists('Drupal\Core\Database\Database')) { if (class_exists('Drupal\Core\Database\Database')) {
parent::expire(); parent::expire();
...@@ -115,7 +115,7 @@ function expire() { ...@@ -115,7 +115,7 @@ function expire() {
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::garbageCollection(). * Overrides Drupal\Core\Cache\DatabaseBackend::garbageCollection().
*/ */
function garbageCollection() { public function garbageCollection() {
try { try {
if (class_exists('Drupal\Core\Database\Database')) { if (class_exists('Drupal\Core\Database\Database')) {
parent::garbageCollection(); parent::garbageCollection();
...@@ -127,7 +127,7 @@ function garbageCollection() { ...@@ -127,7 +127,7 @@ function garbageCollection() {
/** /**
* Overrides Drupal\Core\Cache\DatabaseBackend::isEmpty(). * Overrides Drupal\Core\Cache\DatabaseBackend::isEmpty().
*/ */
function isEmpty() { public function isEmpty() {
try { try {
if (class_exists('Drupal\Core\Database\Database')) { if (class_exists('Drupal\Core\Database\Database')) {
return parent::isEmpty(); return parent::isEmpty();
......
...@@ -105,13 +105,13 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN ...@@ -105,13 +105,13 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN
); );
} }
/* /**
* Calculates a checksum so data can be invalidated using tags. * Calculates a checksum so data can be invalidated using tags.
*/ */
function checksum($tags) { public function checksum($tags) {
$checksum = ""; $checksum = '';
foreach($tags as $tag) { foreach ($tags as $tag) {
// Has the tag already been invalidated. // Has the tag already been invalidated.
if (isset($this->invalidatedTags[$tag])) { if (isset($this->invalidatedTags[$tag])) {
$checksum = $checksum . $tag . ':' . $this->invalidatedTags[$tag]; $checksum = $checksum . $tag . ':' . $this->invalidatedTags[$tag];
...@@ -201,8 +201,7 @@ protected function flattenTags(array $tags) { ...@@ -201,8 +201,7 @@ protected function flattenTags(array $tags) {
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags().
*/ */
public function invalidateTags(array $tags) { public function invalidateTags(array $tags) {
$flat_tags = $this->flattenTags($tags); foreach ($this->flattenTags($tags) as $tag) {
foreach($flat_tags as $tag) {
if (isset($this->invalidatedTags[$tag])) { if (isset($this->invalidatedTags[$tag])) {
$this->invalidatedTags[$tag] = $this->invalidatedTags[$tag] + 1; $this->invalidatedTags[$tag] = $this->invalidatedTags[$tag] + 1;
} }
......
...@@ -23,51 +23,51 @@ class NullBackend implements CacheBackendInterface { ...@@ -23,51 +23,51 @@ class NullBackend implements CacheBackendInterface {
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::__construct(). * Implements Drupal\Core\Cache\CacheBackendInterface::__construct().
*/ */
function __construct($bin) {} public function __construct($bin) {}
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::get(). * Implements Drupal\Core\Cache\CacheBackendInterface::get().
*/ */
function get($cid) { public function get($cid) {
return FALSE; return FALSE;
} }
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple(). * Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().
*/ */
function getMultiple(&$cids) { public function getMultiple(&$cids) {
return array(); return array();
} }
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::set(). * Implements Drupal\Core\Cache\CacheBackendInterface::set().
*/ */
function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {} public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {}
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::delete(). * Implements Drupal\Core\Cache\CacheBackendInterface::delete().
*/ */
function delete($cid) {} public function delete($cid) {}
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple(). * Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
*/ */
function deleteMultiple(array $cids) {} public function deleteMultiple(array $cids) {}
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::flush(). * Implements Drupal\Core\Cache\CacheBackendInterface::flush().
*/ */
function flush() {} public function flush() {}
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::expire(). * Implements Drupal\Core\Cache\CacheBackendInterface::expire().
*/ */
function expire() {} public function expire() {}
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection(). * Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection().
*/ */
function garbageCollection() {} public function garbageCollection() {}
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags().
...@@ -77,7 +77,7 @@ public function invalidateTags(array $tags) {} ...@@ -77,7 +77,7 @@ public function invalidateTags(array $tags) {}
/** /**
* Implements Drupal\Core\Cache\CacheBackendInterface::isEmpty(). * Implements Drupal\Core\Cache\CacheBackendInterface::isEmpty().
*/ */
function isEmpty() { public function isEmpty() {
return TRUE; return TRUE;
} }
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\system\Tests\Cache\ArrayBackendUnitTest. * Definition of Drupal\system\Tests\Cache\MemoryBackendUnitTest.
*/ */
namespace Drupal\system\Tests\Cache; namespace Drupal\system\Tests\Cache;
......
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