joomla/joomla-framework — pull request #333 by garyamort (2014-01-21 21:01:16+00:00)
Title: [RFC] decoupling hard to test methods

A first pass on setting up a Runtime Registry to be used to retrieve settings from the runtime environment in the same manner that Registry retrieves settings from an application environment.

As such, the Runtime Registry is a subclass of Registry with added functional logic to check for the existence of PHP Classes, Functions, and Extensions.

Committing early for feedback on naming convention, documentation, etc.

If other packages make Registry a required dependency, then current calls such as:

static public function isSupported()
{
return extension_loaded('someextension');
}

Can be written as
static public function isSupported($runtime = null)
{
if ($runtime === null)
{
$runtime = self::getRuntime(__CLASS__);
}
return $runtime->extensionExists('someextension');
}

If instead it is a recommended package, then such a test would be written as:

Can be written as
static public function isSupported($runtime = null)
{

if class_exists('Joomla\\Registry\\Runtime', true)
{
if ($runtime === null)
{
$runtime = self::getRuntime(__CLASS__);
}
return $runtime->extensionExists('someextension');
}
}

return self::isSuportedFallback();
}

static public function isSupportedFallback()
{
// Log a warning message that the Runtime Registry did not exist
return extension_loaded('someextension');
}