Skip to content

Commit 4ec9ff2

Browse files
committed
Changed getIterator() to return ArrayObject instead of plain arrays, as required by IteratorAggregate.
1 parent 3c8fa6d commit 4ec9ff2

27 files changed

+259
-261
lines changed

RELEASE-0.1.3

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* Wincache and APC now check their requirements in greater detail:
2+
- APC checks if it's enabled by the apc.enabled INI setting.
3+
- Wincache checks if the user cache is enabled by wincache.ucenabled INI setting.
4+
- Both check if the SAPI is CLI, and if so, whether that's allowed by the respective ini setting.
5+
* The PHAR stub also checks and reports the above.
6+
* SHM::getIterator() now returns ArrayObject instead of a normal array, in order to be compatible with how IteratorAggregate actually works.
7+
* Doc and CS fixes.

extrasetup.php

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,26 @@
1414
* @link http://pear2.php.net/PEAR2_Cache_SHM
1515
*/
1616

17+
$packages = array(
18+
'pear2.php.net' => array(
19+
'PEAR2_Autoload'
20+
)
21+
);
22+
1723
$extrafiles = array();
18-
$phpDir = Pyrus\Config::current()->php_dir . DIRECTORY_SEPARATOR;
19-
$packages = array('PEAR2/Autoload');
24+
$config = Pyrus\Config::current();
25+
$registry = $config->registry;
26+
$phpDir = $config->php_dir;
2027

21-
$oldCwd = getcwd();
22-
chdir($phpDir);
23-
foreach ($packages as $pkg) {
24-
if (is_dir($pkg)) {
25-
foreach (
26-
new RecursiveIteratorIterator(
27-
new RecursiveDirectoryIterator(
28-
$pkg,
29-
RecursiveDirectoryIterator::UNIX_PATHS
30-
| RecursiveDirectoryIterator::SKIP_DOTS
31-
),
32-
RecursiveIteratorIterator::LEAVES_ONLY
33-
) as $path
34-
) {
35-
$extrafiles['src/' . $path->getPathname()] = $path->getRealPath();
28+
foreach ($packages as $channel => $channelPackages) {
29+
foreach ($channelPackages as $package) {
30+
foreach ($registry->toPackage($package, $channel)->installcontents
31+
as $file => $info) {
32+
if (strpos($file, 'php/') === 0) {
33+
$filename = substr($file, 4);
34+
$extrafiles['src/' . $filename]
35+
= realpath($phpDir . DIRECTORY_SEPARATOR . $filename);
36+
}
3637
}
3738
}
38-
39-
if (is_file($pkg . '.php')) {
40-
$extrafiles['src/' . $pkg . '.php']
41-
= $phpDir . DIRECTORY_SEPARATOR . $pkg . '.php';
42-
}
43-
}
44-
chdir($oldCwd);
39+
}

package.xml

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,36 @@
1111
<email>[email protected]</email>
1212
<active>yes</active>
1313
</lead>
14-
<date>2013-08-15</date>
15-
<time>18:18:31</time>
14+
<date>2014-06-14</date>
15+
<time>00:41:37</time>
1616
<version>
17-
<release>0.1.2</release>
17+
<release>0.1.3</release>
1818
<api>0.1.0</api>
1919
</version>
2020
<stability>
2121
<release>alpha</release>
2222
<api>alpha</api>
2323
</stability>
2424
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL License 2.1</license>
25-
<notes>* SHM::isMeetingRequirements() is now not abstract, and always returns TRUE.
26-
* Fixed loading order of adapters.
27-
* Changed the PHAR stub to not fail when reading the hash fails.
25+
<notes>* Wincache and APC now check their requirements in greater detail:
26+
- APC checks if it's enabled by the apc.enabled INI setting.
27+
- Wincache checks if the user cache is enabled by wincache.ucenabled INI setting.
28+
- Both check if the SAPI is CLI, and if so, whether that's allowed by the respective ini setting.
29+
* The PHAR stub also checks and reports the above.
30+
* SHM::getIterator() now returns ArrayObject instead of a normal array, in order to be compatible with how IteratorAggregate actually works.
2831
* Doc and CS fixes.</notes>
2932
<contents>
3033
<dir name="/">
3134
<dir name="docs" baseinstalldir="/">
3235
<file role="doc" name="apigen.neon">
33-
<tasks:replace from="../src" to="php_dir" type="pear-config"/>
36+
<tasks:replace type="pear-config" to="php_dir" from="../src"/>
3437
</file>
3538
<file role="doc" name="doxygen.ini">
36-
<tasks:replace from="../src" to="php_dir" type="pear-config"/>
37-
<tasks:replace from="GIT: $Id$" to="version" type="package-info"/>
39+
<tasks:replace type="pear-config" to="php_dir" from="../src"/>
40+
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
3841
</file>
3942
<file role="doc" name="phpdoc.dist.xml">
40-
<tasks:replace from="../src" to="php_dir" type="pear-config"/>
43+
<tasks:replace type="pear-config" to="php_dir" from="../src"/>
4144
</file>
4245
</dir>
4346
<dir name="src" baseinstalldir="/">
@@ -46,36 +49,24 @@
4649
<dir name="SHM">
4750
<dir name="Adapter">
4851
<file role="php" name="APC.php">
49-
<tasks:replace from="~~summary~~" to="summary" type="package-info"/>
50-
<tasks:replace from="~~description~~" to="description" type="package-info"/>
51-
<tasks:replace from="GIT: $Id$" to="version" type="package-info"/>
52+
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
5253
</file>
5354
<file role="php" name="Placebo.php">
54-
<tasks:replace from="~~summary~~" to="summary" type="package-info"/>
55-
<tasks:replace from="~~description~~" to="description" type="package-info"/>
56-
<tasks:replace from="GIT: $Id$" to="version" type="package-info"/>
55+
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
5756
</file>
5857
<file role="php" name="Wincache.php">
59-
<tasks:replace from="~~summary~~" to="summary" type="package-info"/>
60-
<tasks:replace from="~~description~~" to="description" type="package-info"/>
61-
<tasks:replace from="GIT: $Id$" to="version" type="package-info"/>
58+
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
6259
</file>
6360
</dir>
6461
<file role="php" name="Exception.php">
65-
<tasks:replace from="~~summary~~" to="summary" type="package-info"/>
66-
<tasks:replace from="~~description~~" to="description" type="package-info"/>
67-
<tasks:replace from="GIT: $Id$" to="version" type="package-info"/>
62+
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
6863
</file>
6964
<file role="php" name="InvalidArgumentException.php">
70-
<tasks:replace from="~~summary~~" to="summary" type="package-info"/>
71-
<tasks:replace from="~~description~~" to="description" type="package-info"/>
72-
<tasks:replace from="GIT: $Id$" to="version" type="package-info"/>
65+
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
7366
</file>
7467
</dir>
7568
<file role="php" name="SHM.php">
76-
<tasks:replace from="~~summary~~" to="summary" type="package-info"/>
77-
<tasks:replace from="~~description~~" to="description" type="package-info"/>
78-
<tasks:replace from="GIT: $Id$" to="version" type="package-info"/>
69+
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
7970
</file>
8071
</dir>
8172
</dir>
@@ -91,19 +82,24 @@
9182
<file role="test" name="testSettingAndGettingValue.phpt"/>
9283
<file role="test" name="testSingleFileLockAndUnlock.phpt"/>
9384
</dir>
85+
<dir name="includes">
86+
<file role="test" name="runner.php">
87+
<tasks:replace type="pear-config" to="php_dir" from="../src"/>
88+
</file>
89+
<file role="test" name="SHM-factory.php"/>
90+
</dir>
9491
<file role="test" name="APC.phpt"/>
9592
<file role="test" name="Placebo.phpt"/>
96-
<file role="test" name="SHM-factory.inc"/>
9793
<file role="test" name="SHM-factory_CGI.phpt"/>
9894
<file role="test" name="SHM-factory_CLI.phpt"/>
9995
<file role="test" name="Wincache.phpt"/>
100-
<file role="test" name="_runner.inc"/>
10196
</dir>
10297
<file role="test" name="bootstrap.php">
103-
<tasks:replace from="../src" to="php_dir" type="pear-config"/>
98+
<tasks:replace type="pear-config" to="php_dir" from="../src"/>
99+
</file>
100+
<file role="test" name="phpunit.xml">
101+
<tasks:replace type="pear-config" to="php_dir" from="../src"/>
104102
</file>
105-
<file role="test" name="CliCompatibleTest.php"/>
106-
<file role="test" name="phpunit.xml"/>
107103
</dir>
108104
</dir>
109105
</contents>
@@ -144,7 +140,6 @@
144140
<install name="src/PEAR2/Cache/SHM/Exception.php" as="PEAR2/Cache/SHM/Exception.php"/>
145141
<install name="src/PEAR2/Cache/SHM/InvalidArgumentException.php" as="PEAR2/Cache/SHM/InvalidArgumentException.php"/>
146142
<install name="tests/bootstrap.php" as="bootstrap.php"/>
147-
<install name="tests/CliCompatibleTest.php" as="CliCompatibleTest.php"/>
148143
<install name="tests/PHPT/APC.phpt" as="PHPT/APC.phpt"/>
149144
<install name="tests/PHPT/Common/testAddingTtlValue_part1.phpt" as="PHPT/Common/testAddingTtlValue_part1.phpt"/>
150145
<install name="tests/PHPT/Common/testAddingTtlValue_part2.phpt" as="PHPT/Common/testAddingTtlValue_part2.phpt"/>
@@ -153,12 +148,12 @@
153148
<install name="tests/PHPT/Common/testSettingAndDeletingValue.phpt" as="PHPT/Common/testSettingAndDeletingValue.phpt"/>
154149
<install name="tests/PHPT/Common/testSettingAndGettingValue.phpt" as="PHPT/Common/testSettingAndGettingValue.phpt"/>
155150
<install name="tests/PHPT/Common/testSingleFileLockAndUnlock.phpt" as="PHPT/Common/testSingleFileLockAndUnlock.phpt"/>
151+
<install name="tests/PHPT/includes/runner.php" as="PHPT/includes/runner.php"/>
152+
<install name="tests/PHPT/includes/SHM-factory.php" as="PHPT/includes/SHM-factory.php"/>
156153
<install name="tests/PHPT/Placebo.phpt" as="PHPT/Placebo.phpt"/>
157-
<install name="tests/PHPT/SHM-factory.inc" as="PHPT/SHM-factory.inc"/>
158154
<install name="tests/PHPT/SHM-factory_CGI.phpt" as="PHPT/SHM-factory_CGI.phpt"/>
159155
<install name="tests/PHPT/SHM-factory_CLI.phpt" as="PHPT/SHM-factory_CLI.phpt"/>
160156
<install name="tests/PHPT/Wincache.phpt" as="PHPT/Wincache.phpt"/>
161-
<install name="tests/PHPT/_runner.inc" as="PHPT/_runner.inc"/>
162157
<install name="tests/phpunit.xml" as="phpunit.xml"/>
163158
</filelist>
164159
</phprelease>

src/PEAR2/Cache/SHM.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,28 @@
2626
*/
2727
use Exception as E;
2828

29+
/**
30+
* Implements this class.
31+
*/
32+
use IteratorAggregate;
33+
34+
/**
35+
* Used on failures by this class.
36+
*/
37+
use PEAR2\Cache\SHM\InvalidArgumentException;
38+
2939
/**
3040
* Main class for this package.
3141
*
3242
* Automatically chooses an adapter based on the available extensions.
3343
*
34-
* @category Cache
44+
* @category Caching
3545
* @package PEAR2_Cache_SHM
3646
* @author Vasil Rangelov <[email protected]>
3747
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
3848
* @link http://pear2.php.net/PEAR2_Cache_SHM
3949
*/
40-
abstract class SHM implements \IteratorAggregate
50+
abstract class SHM implements IteratorAggregate
4151
{
4252
/**
4353
* @var array An array of adapter names that meet their requirements.
@@ -64,7 +74,7 @@ final public static function factory($persistentId)
6474
//In case of a runtime error, try to fallback to other adapters.
6575
}
6676
}
67-
throw new SHM\InvalidArgumentException(
77+
throw new InvalidArgumentException(
6878
'No appropriate adapter available',
6979
1
7080
);
@@ -337,6 +347,23 @@ abstract public function cas($key, $old, $new);
337347
* @return void
338348
*/
339349
abstract public function clear();
350+
351+
/**
352+
* Retrieve an external iterator
353+
*
354+
* Returns an external iterator.
355+
*
356+
* @param string|null $filter A PCRE regular expression.
357+
* Only matching keys will be iterated over.
358+
* Setting this to NULL matches all keys of this instance.
359+
* @param bool $keysOnly Whether to return only the keys,
360+
* or return both the keys and values.
361+
*
362+
* @return \Traversable An array with all matching keys as array keys,
363+
* and values as array values. If $keysOnly is TRUE, the array keys are
364+
* numeric, and the array values are key names.
365+
*/
366+
abstract public function getIterator($filter = null, $keysOnly = false);
340367
}
341368

342369
SHM::registerAdapter('\\' . __NAMESPACE__ . '\SHM\Adapter\Placebo');

src/PEAR2/Cache/SHM/Adapter/APC.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@
2525
*/
2626
use PEAR2\Cache\SHM;
2727

28+
/**
29+
* {@link APC::getIterator()} returns this object.
30+
*/
31+
use ArrayObject;
32+
2833
/**
2934
* Shared memory adapter for the APC extension.
3035
*
31-
* @category Cache
36+
* @category Caching
3237
* @package PEAR2_Cache_SHM
3338
* @author Vasil Rangelov <[email protected]>
3439
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
@@ -91,7 +96,9 @@ public function __construct($persistentId)
9196
public static function isMeetingRequirements()
9297
{
9398
return extension_loaded('apc')
94-
&& version_compare(phpversion('apc'), '3.0.13', '>=');
99+
&& version_compare(phpversion('apc'), '3.0.13', '>=')
100+
&& ini_get('apc.enabled')
101+
&& ('cli' !== PHP_SAPI || ini_get('apc.enable_cli'));
95102
}
96103

97104
/**
@@ -365,15 +372,15 @@ public function clear()
365372
*
366373
* Returns an external iterator.
367374
*
368-
* @param string $filter A PCRE regular expression. Only matching keys
369-
* will be iterated over. Setting this to NULL matches all keys of this
370-
* instance.
371-
* @param bool $keysOnly Whether to return only the keys, or return both
372-
* the keys and values.
375+
* @param string|null $filter A PCRE regular expression.
376+
* Only matching keys will be iterated over.
377+
* Setting this to NULL matches all keys of this instance.
378+
* @param bool $keysOnly Whether to return only the keys,
379+
* or return both the keys and values.
373380
*
374-
* @return array An array with all matching keys as array keys, and values
375-
* as array values. If $keysOnly is TRUE, the array keys are numeric,
376-
* and the array values are key names.
381+
* @return ArrayObject An array with all matching keys as array keys,
382+
* and values as array values. If $keysOnly is TRUE, the array keys are
383+
* numeric, and the array values are key names.
377384
*/
378385
public function getIterator($filter = null, $keysOnly = false)
379386
{
@@ -394,6 +401,6 @@ public function getIterator($filter = null, $keysOnly = false)
394401
}
395402
}
396403
}
397-
return $result;
404+
return new ArrayObject($result);
398405
}
399406
}

src/PEAR2/Cache/SHM/Adapter/Placebo.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@
2525
*/
2626
use PEAR2\Cache\SHM;
2727

28+
/**
29+
* {@link Placebo::getIterator()} returns this object.
30+
*/
31+
use ArrayObject;
32+
2833
/**
2934
* This adapter is not truly persistent. It is intended to emulate persistency
3035
* in non persistent environments, so that upper level applications can use a
3136
* single code path for persistent and non persistent code.
3237
*
33-
* @category Cache
38+
* @category Caching
3439
* @package PEAR2_Cache_SHM
3540
* @author Vasil Rangelov <[email protected]>
3641
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
@@ -322,21 +327,24 @@ public function clear()
322327
*
323328
* Returns an external iterator.
324329
*
325-
* @param string $filter A PCRE regular expression. Only matching keys
326-
* will be iterated over. Setting this to NULL matches all keys of this
327-
* instance.
328-
* @param bool $keysOnly Whether to return only the keys, or return both
329-
* the keys and values.
330+
* @param string|null $filter A PCRE regular expression.
331+
* Only matching keys will be iterated over.
332+
* Setting this to NULL matches all keys of this instance.
333+
* @param bool $keysOnly Whether to return only the keys,
334+
* or return both the keys and values.
330335
*
331-
* @return array An array with all matching keys as array keys, and values
332-
* as array values. If $keysOnly is TRUE, the array keys are numeric,
333-
* and the array values are key names.
336+
* @return ArrayObject An array with all matching keys as array keys,
337+
* and values as array values. If $keysOnly is TRUE, the array keys are
338+
* numeric, and the array values are key names.
334339
*/
335340
public function getIterator($filter = null, $keysOnly = false)
336341
{
337342
if (null === $filter) {
338-
return $keysOnly ? array_keys(static::$data[$this->persistentId])
339-
: static::$data[$this->persistentId];
343+
return new ArrayObject(
344+
$keysOnly
345+
? array_keys(static::$data[$this->persistentId])
346+
: static::$data[$this->persistentId]
347+
);
340348
}
341349

342350
$result = array();
@@ -345,6 +353,6 @@ public function getIterator($filter = null, $keysOnly = false)
345353
$result[$key] = $value;
346354
}
347355
}
348-
return $keysOnly ? array_keys($result) : $result;
356+
return new ArrayObject($keysOnly ? array_keys($result) : $result);
349357
}
350358
}

0 commit comments

Comments
 (0)