Skip to content

Commit c10bcb8

Browse files
committed
Reverted the loading order of adapters;
Per strict coding standards, made isMeetingRequirements() non abstract - now, it always returns true in the base SHM class. adapters should override this when needed; factory() and registerAdapter() are now "final" methods; registerAdapter() checks for the existence of a class and autoloads it before other checks.
1 parent 0b43d7e commit c10bcb8

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/PEAR2/Cache/SHM.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract class SHM implements \IteratorAggregate
4949
* @return static|SHM A new instance of an SHM adapter (child of this
5050
* class).
5151
*/
52-
public static function factory($persistentId)
52+
final public static function factory($persistentId)
5353
{
5454
foreach (self::$_adapters as $adapter) {
5555
try {
@@ -67,23 +67,27 @@ public static function factory($persistentId)
6767
*
6868
* @return bool TRUE on success, FALSE on failure.
6969
*/
70-
abstract public static function isMeetingRequirements();
70+
public static function isMeetingRequirements()
71+
{
72+
return true;
73+
}
7174

7275
/**
7376
* Registers an adapter.
7477
*
7578
* Registers an SHM adapter, allowing you to call it with {@link factory()}.
7679
*
7780
* @param string $adapter FQCN of adapter. A valid adapter is one that
78-
* extends this class.
81+
* extends this class. The class will be autoloaded if not already present.
7982
* @param bool $prepend Whether to prepend this adapter into the list of
8083
* possible adapters, instead of appending to it.
8184
*
8285
* @return bool TRUE on success, FALSE on failure.
8386
*/
84-
public static function registerAdapter($adapter, $prepend = false)
87+
final public static function registerAdapter($adapter, $prepend = false)
8588
{
86-
if (is_subclass_of($adapter, '\\' . __CLASS__)
89+
if (class_exists($adapter, true)
90+
&& is_subclass_of($adapter, '\\' . __CLASS__)
8791
&& $adapter::isMeetingRequirements()
8892
) {
8993
if ($prepend) {
@@ -325,11 +329,6 @@ abstract public function cas($key, $old, $new);
325329
abstract public function clear();
326330
}
327331

328-
foreach (
329-
array('\Adapter\APC', '\Adapter\Placebo', '\Adapter\Wincache') as $adapter
330-
) {
331-
if (class_exists($adapter = '\\' . __NAMESPACE__ . $adapter, true)) {
332-
SHM::registerAdapter($adapter);
333-
}
334-
}
335-
unset($adapter);
332+
SHM::registerAdapter('\\' . __NAMESPACE__ . '\SHM\Adapter\Placebo');
333+
SHM::registerAdapter('\\' . __NAMESPACE__ . '\SHM\Adapter\Wincache');
334+
SHM::registerAdapter('\\' . __NAMESPACE__ . '\SHM\Adapter\APC');

0 commit comments

Comments
 (0)