mirror of
https://github.com/predis/predis.git
synced 2026-08-30 12:15:03 +00:00
Change how we check for required extensions in connection classes.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user