Change how we check for required extensions in connection classes.

This commit is contained in:
Daniele Alessandri
2012-03-18 15:22:24 +01:00
parent 64a84d9020
commit bcba9e1009
2 changed files with 21 additions and 18 deletions
+17 -14
View File
@@ -49,6 +49,8 @@ use Predis\NotSupportedException;
*/
class PhpiredisConnection extends AbstractConnection
{
const ERR_MSG_EXTENSION = 'The %s extension must be loaded in order to be able to use this connection class';
private $reader;
/**
@@ -56,12 +58,7 @@ class PhpiredisConnection extends AbstractConnection
*/
public function __construct(ConnectionParametersInterface $parameters)
{
if (!function_exists('socket_create')) {
throw new NotSupportedException(
'The socket extension must be loaded in order to be able to ' .
'use this connection class'
);
}
$this->checkExtensions();
parent::__construct($parameters);
}
@@ -77,6 +74,19 @@ class PhpiredisConnection extends AbstractConnection
parent::__destruct();
}
/**
* Checks if the cURL and phpiredis extensions are loaded in PHP.
*/
private function checkExtensions()
{
if (!function_exists('socket_create')) {
throw new NotSupportedException(sprintf(self::ERR_MSG_EXTENSION, 'socket'));
}
if (!function_exists('phpiredis_reader_create')) {
throw new NotSupportedException(sprintf(self::ERR_MSG_EXTENSION, 'phpiredis'));
}
}
/**
* {@inheritdoc}
*/
@@ -97,14 +107,7 @@ class PhpiredisConnection extends AbstractConnection
*
* @param Boolean $throw_errors Specify if Redis errors throw exceptions.
*/
private function initializeReader($throw_errors = true)
{
if (!function_exists('phpiredis_reader_create')) {
throw new NotSupportedException(
'The phpiredis extension must be loaded in order to be able to ' .
'use this connection class'
);
}
private function initializeReader($throw_errors = true) {
$reader = phpiredis_reader_create();
+4 -4
View File
@@ -20,8 +20,6 @@ use Predis\NotSupportedException;
use Predis\Protocol\ProtocolException;
use Predis\Connection\ConnectionException;
const ERR_MSG_EXTENSION = 'The %s extension must be loaded in order to be able to use this connection class';
/**
* This class implements a Predis connection that actually talks with Webdis
* instead of connecting directly to Redis. It relies on the cURL extension to
@@ -50,6 +48,8 @@ const ERR_MSG_EXTENSION = 'The %s extension must be loaded in order to be able t
*/
class WebdisConnection implements SingleConnectionInterface
{
const ERR_MSG_EXTENSION = 'The %s extension must be loaded in order to be able to use this connection class';
private $parameters;
private $resource;
private $reader;
@@ -95,10 +95,10 @@ class WebdisConnection implements SingleConnectionInterface
private function checkExtensions()
{
if (!function_exists('curl_init')) {
throw new NotSupportedException(sprintf(ERR_MSG_EXTENSION, 'curl'));
throw new NotSupportedException(sprintf(self::ERR_MSG_EXTENSION, 'curl'));
}
if (!function_exists('phpiredis_reader_create')) {
throw new NotSupportedException(sprintf(ERR_MSG_EXTENSION, 'phpiredis'));
throw new NotSupportedException(sprintf(self::ERR_MSG_EXTENSION, 'phpiredis'));
}
}