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/zendframework/zendframework#7032-fix-undefined-v…
Browse files Browse the repository at this point in the history
…ariable-in-cache-apc-storage' into develop

Close zendframework/zendframework#7032
Close zendframework/zendframework#7031
  • Loading branch information
Ocramius committed Dec 16, 2014
4 parents 6313fe3 + 1ec6c6d + babe345 + 596ae2c commit d7f5f57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Storage/Adapter/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,24 +361,27 @@ protected function internalGetMetadatas(array & $normalizedKeys)

$options = $this->getOptions();
$namespace = $options->getNamespace();
$prefixL = 0;

if ($namespace === '') {
$pattern = '/^(' . implode('|', $keysRegExp) . ')' . '$/';
} else {
$prefix = $namespace . $options->getNamespaceSeparator();
$prefixL = strlen($prefix);
$pattern = '/^' . preg_quote($prefix, '/') . '(' . implode('|', $keysRegExp) . ')' . '$/';
}

$format = APC_ITER_ALL ^ APC_ITER_VALUE ^ APC_ITER_TYPE ^ APC_ITER_REFCOUNT;
$it = new BaseApcIterator('user', $pattern, $format, 100, APC_LIST_ACTIVE);
$result = array();
$prefixL = strlen($prefix);
foreach ($it as $internalKey => $metadata) {
// @see http://pecl.php.net/bugs/bug.php?id=22564
if (!apc_exists($internalKey)) {
continue;
}

$this->normalizeMetadata($metadata);
$result[substr($internalKey, $prefixL)] = & $metadata;
$result[substr($internalKey, $prefixL)] = $metadata;
}

return $result;
Expand Down
12 changes: 11 additions & 1 deletion test/Storage/Adapter/CommonAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public function testGetMetadataReturnsFalseIfNonReadable()

public function testGetMetadatas()
{
$capabilities = $this->_storage->getCapabilities();
$capabilities = $this->_storage->getCapabilities();
$supportedMetadatas = $capabilities->getSupportedMetadata();

$items = array(
Expand All @@ -397,6 +397,16 @@ public function testGetMetadatas()
}
}

/**
* @group 7031
* @group 7032
*/
public function testGetMetadatasWithEmptyNamespace()
{
$this->_options->setNamespace('');
$this->testGetMetadatas();
}

public function testGetMetadatasReturnsEmptyArrayIfNonReadable()
{
$this->_options->setReadable(false);
Expand Down

0 comments on commit d7f5f57

Please sign in to comment.