Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/cache-updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jan 3, 2012
3 parents a0560e8 + 4ff045c + ee1b979 commit ac805a6
Show file tree
Hide file tree
Showing 14 changed files with 864 additions and 461 deletions.
33 changes: 33 additions & 0 deletions src/Exception/OutOfCapacityException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Cache
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Cache\Exception;

use Zend\Cache\Exception;

/**
* @category Zend
* @package Zend_Cache
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class OutOfCapacityException extends \OverflowException implements Exception
{
}
43 changes: 32 additions & 11 deletions src/Storage/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ abstract class AbstractAdapter implements Adapter
*/
protected $stmtOptions = null;

/**
* Constructor
*
* @param null|array|Traversable|AdapterOptions $options
* @throws Exception
* @return void
*/
public function __construct($options = null)
{
if ($options) {
$this->setOptions($options);
}
}

/**
* Destructor
*
Expand Down Expand Up @@ -331,13 +345,8 @@ public function removePlugin(Plugin $plugin)
$registry = $this->getPluginRegistry();
if ($registry->contains($plugin)) {
$plugin->detach($this->events());
} else {
throw new Exception\LogicException(sprintf(
'Plugin of type "%s" already removed',
get_class($plugin)
));
$registry->detach($plugin);
}
$registry->detach($plugin);
return $this;
}

Expand Down Expand Up @@ -557,10 +566,10 @@ public function replaceItems(array $keyValuePairs, array $options = array())
/**
* Check and set item
*
* @param string $token
* @param string|int $key
* @param mixed $value
* @param array $options
* @param mixed $token
* @param string $key
* @param mixed $value
* @param array $options
* @return bool
*/
public function checkAndSetItem($token, $key, $value, array $options = array())
Expand Down Expand Up @@ -739,6 +748,19 @@ public function decrementItems(array $keyValuePairs, array $options = array())
/**
* Get delayed
*
* Options:
* - ttl <float> optional
* - The time-to-live (Default: ttl of object)
* - namespace <string> optional
* - The namespace to use (Default: namespace of object)
* - select <array> optional
* - An array of the information the returned item contains
* (Default: array('key', 'value'))
* - callback <callback> optional
* - An result callback will be invoked for each item in the result set.
* - The first argument will be the item array.
* - The callback does not have to return anything.
*
* @param array $keys
* @param array $options
* @return bool
Expand All @@ -758,7 +780,6 @@ public function getDelayed(array $keys, array $options = array())
}

$this->normalizeOptions($options);

if (!isset($options['select'])) {
$options['select'] = array('key', 'value');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/Adapter/AdapterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AdapterOptions extends Options

/**
* Cast to array
*
*
* @return array
*/
public function toArray()
Expand Down Expand Up @@ -178,7 +178,7 @@ public function getKeyPattern()
*/
public function setNamespace($namespace)
{
$nameapace = (string)$namespace;
$namespace = (string)$namespace;
if ($namespace === '') {
throw new Exception\InvalidArgumentException('No namespace given');
}
Expand Down
10 changes: 6 additions & 4 deletions src/Storage/Adapter/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class Apc extends AbstractAdapter
/**
* Constructor
*
* @param array $options Option
* @param null|array|Traversable|ApcOptions $options
* @throws Exception
* @return void
*/
public function __construct()
public function __construct($options = null)
{
if (version_compare('3.1.6', phpversion('apc')) > 0) {
throw new Exception\ExtensionNotLoadedException("Missing ext/apc >= 3.1.6");
Expand Down Expand Up @@ -103,6 +103,8 @@ public function __construct()
'internal_key' => \APC_ITER_KEY,
);
}

parent::__construct($options);
}

/* options */
Expand All @@ -116,8 +118,8 @@ public function __construct()
*/
public function setOptions($options)
{
if (!is_array($options)
&& !$options instanceof Traversable
if (!is_array($options)
&& !$options instanceof Traversable
&& !$options instanceof ApcOptions
) {
throw new Exception\InvalidArgumentException(sprintf(
Expand Down
44 changes: 22 additions & 22 deletions src/Storage/Adapter/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class Filesystem extends AbstractAdapter
* Set options.
*
* @param array|Traversable|FilesystemOptions $options
* @return FilesystemAdapter
* @return Filesystem
* @see getOptions()
*/
public function setOptions($options)
{
if (!is_array($options)
&& !$options instanceof Traversable
if (!is_array($options)
&& !$options instanceof Traversable
&& !$options instanceof FilesystemOptions
) {
throw new Exception\InvalidArgumentException(sprintf(
Expand Down Expand Up @@ -648,10 +648,10 @@ public function addItems(array $keyValuePairs, array $options = array())
/**
* check and set item
*
* @param $token
* @param $key
* @param $value
* @param array $options
* @param string $token
* @param string $key
* @param mixed $value
* @param array $options
* @return bool|mixed
* @throws ItemNotFoundException
*/
Expand Down Expand Up @@ -1320,7 +1320,7 @@ protected function internalHasItem($key, array &$options)
* @return array|bool
* @throws ItemNotFoundException
*/
protected function internalGetMetadata($key, array &$options)
protected function internalGetMetadata($key, array &$options)
{
$keyInfo = $this->getKeyInfo($key, $options['namespace']);
if (!$keyInfo) {
Expand Down Expand Up @@ -1537,23 +1537,23 @@ protected function clearByPrefix($prefix, $mode, array &$opts)

// if MATCH_TAGS mode -> check if all given tags available in current cache
if (($mode & self::MATCH_TAGS) == self::MATCH_TAGS ) {
if (!isset($info['tags'])
if (!isset($info['tags'])
|| count(array_diff($opts['tags'], $info['tags'])) > 0
) {
continue;
}

// if MATCH_NO_TAGS mode -> check if no given tag available in current cache
} elseif(($mode & self::MATCH_NO_TAGS) == self::MATCH_NO_TAGS) {
if (isset($info['tags'])
if (isset($info['tags'])
&& count(array_diff($opts['tags'], $info['tags'])) != count($opts['tags'])
) {
continue;
}

// if MATCH_ANY_TAGS mode -> check if any given tag available in current cache
} elseif ( ($mode & self::MATCH_ANY_TAGS) == self::MATCH_ANY_TAGS ) {
if (!isset($info['tags'])
if (!isset($info['tags'])
|| count(array_diff($opts['tags'], $info['tags'])) == count($opts['tags'])
) {
continue;
Expand Down Expand Up @@ -1686,7 +1686,7 @@ protected function getFileSpec($key, $ns)
* @return array|boolean The info array or false if file wasn't found
* @throws Exception\RuntimeException
*/
protected function readInfoFile($file)
protected function readInfoFile($file)
{
if (!file_exists($file)) {
return false;
Expand Down Expand Up @@ -1718,10 +1718,10 @@ protected function getFileContent($file)
if ($this->getOptions()->getFileLocking()) {
set_error_handler(function($errno, $errstr = '', $errfile = '', $errline = 0) use ($file) {
$message = sprintf(
'Error getting contents from file "%s" (in %s@%d): %s',
$file,
$errfile,
$errline,
'Error getting contents from file "%s" (in %s@%d): %s',
$file,
$errfile,
$errline,
$errstr
);
throw new Exception\RuntimeException($message, $errno);
Expand All @@ -1730,17 +1730,17 @@ protected function getFileContent($file)
restore_error_handler();
if ($fp === false) {
throw new Exception\RuntimeException(sprintf(
'Unknown error getting contents from file "%s"',
'Unknown error getting contents from file "%s"',
$file
));
}

set_error_handler(function($errno, $errstr = '', $errfile = '', $errline = 0) use ($file) {
$message = sprintf(
'Error locking file "%s" (in %s@%d): %s',
$file,
$errfile,
$errline,
'Error locking file "%s" (in %s@%d): %s',
$file,
$errfile,
$errline,
$errstr
);
throw new Exception\RuntimeException($message, $errno);
Expand Down Expand Up @@ -1859,7 +1859,7 @@ protected function putFileContent($file, $data)
* @return void
* @throw RuntimeException
*/
protected function unlink($file)
protected function unlink($file)
{
// If file does not exist, nothing to do
if (!file_exists($file)) {
Expand Down
Loading

0 comments on commit ac805a6

Please sign in to comment.