From 0fee0c6d970ecfdc3367c802759343f51b46c339 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Fri, 25 Nov 2011 12:25:33 +0100 Subject: [PATCH] Remove the underscore prefix for names of private/protected fields. --- bin/createSingleFile.php | 112 +++++++++--------- examples/CustomDistributionStrategy.php | 20 ++-- examples/DispatcherLoop.php | 10 +- examples/SimpleDebuggableConnection.php | 12 +- lib/Predis/Autoloader.php | 14 +-- lib/Predis/Client.php | 54 ++++----- lib/Predis/ClientOptions.php | 36 +++--- lib/Predis/Commands/Command.php | 36 +++--- .../Processors/KeyPrefixProcessor.php | 8 +- .../Commands/Processors/ProcessorChain.php | 24 ++-- lib/Predis/Commands/ServerShutdown.php | 3 +- lib/Predis/CommunicationException.php | 6 +- lib/Predis/ConnectionFactory.php | 20 ++-- lib/Predis/ConnectionParameters.php | 44 +++---- lib/Predis/DispatcherLoop.php | 48 ++++---- lib/Predis/Distribution/HashRing.php | 56 ++++----- lib/Predis/Iterators/MultiBulkResponse.php | 20 ++-- .../Iterators/MultiBulkResponseSimple.php | 16 +-- .../Iterators/MultiBulkResponseTuple.php | 20 ++-- lib/Predis/MonitorContext.php | 26 ++-- .../Network/ComposableStreamConnection.php | 14 +-- lib/Predis/Network/ConnectionBase.php | 40 +++---- lib/Predis/Network/PhpiredisConnection.php | 18 +-- lib/Predis/Network/PredisCluster.php | 32 ++--- lib/Predis/Network/StreamConnection.php | 22 ++-- lib/Predis/Network/WebdisConnection.php | 32 ++--- lib/Predis/Options/CustomOption.php | 16 +-- lib/Predis/Pipeline/PipelineContext.php | 34 +++--- lib/Predis/Profiles/ServerProfile.php | 40 +++---- .../Protocol/Text/ComposableTextProtocol.php | 22 ++-- lib/Predis/Protocol/Text/TextProtocol.php | 22 ++-- .../Protocol/Text/TextResponseReader.php | 14 +-- lib/Predis/PubSubContext.php | 38 +++--- lib/Predis/ResponseError.php | 6 +- .../Transaction/AbortedMultiExecException.php | 6 +- lib/Predis/Transaction/MultiExecContext.php | 64 +++++----- test/PredisShared.php | 14 +-- 37 files changed, 510 insertions(+), 509 deletions(-) diff --git a/bin/createSingleFile.php b/bin/createSingleFile.php index 53713c0a..f9e4b40d 100755 --- a/bin/createSingleFile.php +++ b/bin/createSingleFile.php @@ -76,11 +76,11 @@ class PredisFile { const NS_ROOT = 'Predis'; - private $_namespaces; + private $namespaces; public function __construct() { - $this->_namespaces = array(); + $this->namespaces = array(); } public static function from($libraryPath, Array $exclude = array()) @@ -116,24 +116,24 @@ class PredisFile public function addNamespace(PhpNamespace $namespace) { - if (isset($this->_namespaces[(string)$namespace])) { + if (isset($this->namespaces[(string)$namespace])) { throw new InvalidArgumentException("Duplicated namespace"); } - $this->_namespaces[(string)$namespace] = $namespace; + $this->namespaces[(string)$namespace] = $namespace; } public function getNamespaces() { - return $this->_namespaces; + return $this->namespaces; } public function getNamespace($namespace) { - if (!isset($this->_namespaces[$namespace])) { + if (!isset($this->namespaces[$namespace])) { return false; } - return $this->_namespaces[$namespace]; + return $this->namespaces[$namespace]; } public function getClassByFQN($classFqn) @@ -261,14 +261,14 @@ class PredisFile class PhpNamespace implements IteratorAggregate { - private $_namespace; - private $_classes; + private $namespace; + private $classes; public function __construct($namespace) { - $this->_namespace = $namespace; - $this->_classes = array(); - $this->_useDirectives = new PhpUseDirectives($this); + $this->namespace = $namespace; + $this->classes = array(); + $this->useDirectives = new PhpUseDirectives($this); } public static function extractName($fqn) @@ -284,19 +284,19 @@ class PhpNamespace implements IteratorAggregate public function addClass(PhpClass $class) { - $this->_classes[$class->getName()] = $class; + $this->classes[$class->getName()] = $class; } public function getClass($className) { - if (isset($this->_classes[$className])) { - return $this->_classes[$className]; + if (isset($this->classes[$className])) { + return $this->classes[$className]; } } public function getClasses() { - return array_values($this->_classes); + return array_values($this->classes); } public function getIterator() @@ -306,46 +306,46 @@ class PhpNamespace implements IteratorAggregate public function getUseDirectives() { - return $this->_useDirectives; + return $this->useDirectives; } public function getPhpCode() { - return "namespace $this->_namespace;\n"; + return "namespace $this->namespace;\n"; } public function __toString() { - return $this->_namespace; + return $this->namespace; } } class PhpUseDirectives implements Countable, IteratorAggregate { - private $_use; - private $_aliases; - private $_namespace; + private $use; + private $aliases; + private $namespace; public function __construct(PhpNamespace $namespace) { - $this->_use = array(); - $this->_aliases = array(); - $this->_namespace = $namespace; + $this->use = array(); + $this->aliases = array(); + $this->namespace = $namespace; } public function add($use, $as = null) { - if (in_array($use, $this->_use)) { + if (in_array($use, $this->use)) { return; } - $this->_use[] = $use; - $this->_aliases[$as ?: PhpClass::extractName($use)] = $use; + $this->use[] = $use; + $this->aliases[$as ?: PhpClass::extractName($use)] = $use; } public function getList() { - return $this->_use; + return $this->use; } public function getIterator() @@ -362,14 +362,14 @@ class PhpUseDirectives implements Countable, IteratorAggregate public function getNamespace() { - return $this->_namespace; + return $this->namespace; } public function getFQN($className) { if (($nsSepFirst = strpos($className, '\\')) === false) { - if (isset($this->_aliases[$className])) { - return $this->_aliases[$className]; + if (isset($this->aliases[$className])) { + return $this->aliases[$className]; } return (string)$this->getNamespace() . "\\$className"; @@ -384,7 +384,7 @@ class PhpUseDirectives implements Countable, IteratorAggregate public function count() { - return count($this->_use); + return count($this->use); } } @@ -401,19 +401,19 @@ class PhpClass */ LICENSE; - private $_namespace; - private $_file; - private $_body; - private $_implements; - private $_extends; - private $_name; + private $namespace; + private $file; + private $body; + private $implements; + private $extends; + private $name; public function __construct(PhpNamespace $namespace, SplFileInfo $classFile) { - $this->_namespace = $namespace; - $this->_file = $classFile; - $this->_implements = array(); - $this->_extends = array(); + $this->namespace = $namespace; + $this->file = $classFile; + $this->implements = array(); + $this->extends = array(); $this->extractData(); $namespace->addClass($this); @@ -446,7 +446,7 @@ LICENSE; $classBuffer = preg_replace('/namespace\s+[\w\d_\\\\]+;\s?/', '', $classBuffer); $classBuffer = preg_replace_callback('/use\s+([\w\d_\\\\]+)(\s+as\s+.*)?;\s?\n?/', $useExtractor, $classBuffer); - $this->_body = trim($classBuffer); + $this->body = trim($classBuffer); $this->extractHierarchy(); } @@ -509,7 +509,7 @@ LICENSE; case T_INTERFACE: $iterator->seek($iterator->key() + 2); $tk = $iterator->current(); - $this->_name = $tk[1]; + $this->name = $tk[1]; break; case T_IMPLEMENTS: @@ -528,8 +528,8 @@ LICENSE; $iterator->next(); } - $this->_implements = $this->guessFQN($implements); - $this->_extends = $this->guessFQN($extends); + $this->implements = $this->guessFQN($implements); + $this->extends = $this->guessFQN($extends); } public function guessFQN($classes) @@ -541,11 +541,11 @@ LICENSE; public function getImplementedInterfaces($all = false) { if ($all) { - return $this->_implements; + return $this->implements; } return array_filter( - $this->_implements, + $this->implements, function ($cn) { return strpos($cn, 'Predis\\') === 0; } ); } @@ -553,11 +553,11 @@ LICENSE; public function getExtendedClasses($all = false) { if ($all) { - return $this->_extemds; + return $this->extemds; } return array_filter( - $this->_extends, + $this->extends, function ($cn) { return strpos($cn, 'Predis\\') === 0; } ); } @@ -572,27 +572,27 @@ LICENSE; public function getNamespace() { - return $this->_namespace; + return $this->namespace; } public function getFile() { - return $this->_file; + return $this->file; } public function getName() { - return $this->_name; + return $this->name; } public function getFQN() { - return (string)$this->getNamespace() . '\\' . $this->_name; + return (string)$this->getNamespace() . '\\' . $this->name; } public function getPhpCode() { - return $this->_body; + return $this->body; } public function __toString() diff --git a/examples/CustomDistributionStrategy.php b/examples/CustomDistributionStrategy.php index 41200a45..a261a1c5 100644 --- a/examples/CustomDistributionStrategy.php +++ b/examples/CustomDistributionStrategy.php @@ -20,38 +20,38 @@ use Predis\Network\PredisCluster; class NaiveDistributionStrategy implements IDistributionStrategy { - private $_nodes; - private $_nodesCount; + private $nodes; + private $nodesCount; public function __constructor() { - $this->_nodes = array(); - $this->_nodesCount = 0; + $this->nodes = array(); + $this->nodesCount = 0; } public function add($node, $weight = null) { - $this->_nodes[] = $node; - $this->_nodesCount++; + $this->nodes[] = $node; + $this->nodesCount++; } public function remove($node) { - $this->_nodes = array_filter($this->_nodes, function($n) use($node) { + $this->nodes = array_filter($this->nodes, function($n) use($node) { return $n !== $node; }); - $this->_nodesCount = count($this->_nodes); + $this->nodesCount = count($this->nodes); } public function get($key) { - $count = $this->_nodesCount; + $count = $this->nodesCount; if ($count === 0) { throw new RuntimeException('No connections'); } - return $this->_nodes[$count > 1 ? abs(crc32($key) % $count) : 0]; + return $this->nodes[$count > 1 ? abs(crc32($key) % $count) : 0]; } public function generateKey($value) diff --git a/examples/DispatcherLoop.php b/examples/DispatcherLoop.php index 046475ae..cc480a98 100644 --- a/examples/DispatcherLoop.php +++ b/examples/DispatcherLoop.php @@ -33,26 +33,26 @@ $dispatcher = new Predis\DispatcherLoop($client); // Demonstrate how to use a callable class as a callback for Predis\DispatcherLoop. class EventsListener implements Countable { - private $_events; + private $events; public function __construct() { - $this->_events = array(); + $this->events = array(); } public function count() { - return count($this->_events); + return count($this->events); } public function getEvents() { - return $this->_events; + return $this->events; } public function __invoke($payload) { - $this->_events[] = $payload; + $this->events[] = $payload; } } diff --git a/examples/SimpleDebuggableConnection.php b/examples/SimpleDebuggableConnection.php index a86ca4bb..1823506e 100644 --- a/examples/SimpleDebuggableConnection.php +++ b/examples/SimpleDebuggableConnection.php @@ -17,12 +17,12 @@ use Predis\Network\StreamConnection; class SimpleDebuggableConnection extends StreamConnection { - private $_tstart = 0; - private $_debugBuffer = array(); + private $tstart = 0; + private $debugBuffer = array(); public function connect() { - $this->_tstart = microtime(true); + $this->tstart = microtime(true); parent::connect(); } @@ -30,14 +30,14 @@ class SimpleDebuggableConnection extends StreamConnection private function storeDebug(ICommand $command, $direction) { $firtsArg = $command->getArgument(0); - $timestamp = round(microtime(true) - $this->_tstart, 4); + $timestamp = round(microtime(true) - $this->tstart, 4); $debug = $command->getId(); $debug .= isset($firtsArg) ? " $firtsArg " : ' '; $debug .= "$direction $this"; $debug .= " [{$timestamp}s]"; - $this->_debugBuffer[] = $debug; + $this->debugBuffer[] = $debug; } public function writeCommand(ICommand $command) @@ -57,7 +57,7 @@ class SimpleDebuggableConnection extends StreamConnection public function getDebugBuffer() { - return $this->_debugBuffer; + return $this->debugBuffer; } } diff --git a/lib/Predis/Autoloader.php b/lib/Predis/Autoloader.php index 33ebfd5a..6dc6be74 100644 --- a/lib/Predis/Autoloader.php +++ b/lib/Predis/Autoloader.php @@ -18,16 +18,16 @@ namespace Predis; */ class Autoloader { - private $_baseDir; - private $_prefix; + private $baseDir; + private $prefix; /** * @param string $baseDirectory Base directory where the source files are located. */ public function __construct($baseDirectory = null) { - $this->_baseDir = $baseDirectory ?: dirname(__FILE__); - $this->_prefix = __NAMESPACE__ . '\\'; + $this->baseDir = $baseDirectory ?: dirname(__FILE__); + $this->prefix = __NAMESPACE__ . '\\'; } /** @@ -45,14 +45,14 @@ class Autoloader */ public function autoload($className) { - if (0 !== strpos($className, $this->_prefix)) { + if (0 !== strpos($className, $this->prefix)) { return; } - $relativeClassName = substr($className, strlen($this->_prefix)); + $relativeClassName = substr($className, strlen($this->prefix)); $classNameParts = explode('\\', $relativeClassName); - $path = $this->_baseDir . + $path = $this->baseDir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $classNameParts) . '.php'; diff --git a/lib/Predis/Client.php b/lib/Predis/Client.php index d0bb85c7..7dd79323 100644 --- a/lib/Predis/Client.php +++ b/lib/Predis/Client.php @@ -28,10 +28,10 @@ class Client { const VERSION = '0.7.0-dev'; - private $_options; - private $_profile; - private $_connection; - private $_connectionFactory; + private $options; + private $profile; + private $connection; + private $connectionFactory; /** * Initializes a new client with optional connection parameters and client options. @@ -48,10 +48,10 @@ class Client $profile->setProcessor($options->prefix); } - $this->_options = $options; - $this->_profile = $profile; - $this->_connectionFactory = $options->connections; - $this->_connection = $this->initializeConnection($parameters); + $this->options = $options; + $this->profile = $profile; + $this->connectionFactory = $options->connections; + $this->connection = $this->initializeConnection($parameters); } /** @@ -99,7 +99,7 @@ class Client if (is_array($parameters)) { if (isset($parameters[0])) { - $cluster = $this->_options->cluster; + $cluster = $this->options->cluster; foreach ($parameters as $node) { $connection = $node instanceof IConnectionSingle ? $node : $this->createConnection($node); $cluster->add($connection); @@ -124,7 +124,7 @@ class Client */ protected function createConnection($parameters) { - $connection = $this->_connectionFactory->create($parameters); + $connection = $this->connectionFactory->create($parameters); $parameters = $connection->getParameters(); if (isset($parameters->password)) { @@ -147,7 +147,7 @@ class Client */ public function getProfile() { - return $this->_profile; + return $this->profile; } /** @@ -157,7 +157,7 @@ class Client */ public function getOptions() { - return $this->_options; + return $this->options; } /** @@ -167,7 +167,7 @@ class Client */ public function getConnectionFactory() { - return $this->_connectionFactory; + return $this->connectionFactory; } /** @@ -183,7 +183,7 @@ class Client throw new \InvalidArgumentException("Invalid connection alias: '$connectionAlias'"); } - return new Client($connection, $this->_options); + return new Client($connection, $this->options); } /** @@ -191,7 +191,7 @@ class Client */ public function connect() { - $this->_connection->connect(); + $this->connection->connect(); } /** @@ -199,7 +199,7 @@ class Client */ public function disconnect() { - $this->_connection->disconnect(); + $this->connection->disconnect(); } /** @@ -220,7 +220,7 @@ class Client */ public function isConnected() { - return $this->_connection->isConnected(); + return $this->connection->isConnected(); } /** @@ -233,16 +233,16 @@ class Client public function getConnection($id = null) { if (isset($id)) { - if (!Helpers::isCluster($this->_connection)) { + if (!Helpers::isCluster($this->connection)) { throw new ClientException( 'Retrieving connections by alias is supported only with clustered connections' ); } - return $this->_connection->getConnectionById($id); + return $this->connection->getConnectionById($id); } - return $this->_connection; + return $this->connection; } /** @@ -254,8 +254,8 @@ class Client */ public function __call($method, $arguments) { - $command = $this->_profile->createCommand($method, $arguments); - return $this->_connection->executeCommand($command); + $command = $this->profile->createCommand($method, $arguments); + return $this->connection->executeCommand($command); } /** @@ -267,7 +267,7 @@ class Client */ public function createCommand($method, $arguments = array()) { - return $this->_profile->createCommand($method, $arguments); + return $this->profile->createCommand($method, $arguments); } /** @@ -278,7 +278,7 @@ class Client */ public function executeCommand(ICommand $command) { - return $this->_connection->executeCommand($command); + return $this->connection->executeCommand($command); } /** @@ -289,17 +289,17 @@ class Client */ public function executeCommandOnShards(ICommand $command) { - if (Helpers::isCluster($this->_connection)) { + if (Helpers::isCluster($this->connection)) { $replies = array(); - foreach ($this->_connection as $connection) { + foreach ($this->connection as $connection) { $replies[] = $connection->executeCommand($command); } return $replies; } - return array($this->_connection->executeCommand($command)); + return array($this->connection->executeCommand($command)); } /** diff --git a/lib/Predis/ClientOptions.php b/lib/Predis/ClientOptions.php index a2f11af4..ec8ace71 100644 --- a/lib/Predis/ClientOptions.php +++ b/lib/Predis/ClientOptions.php @@ -24,20 +24,20 @@ use Predis\Options\ClientConnectionFactory; */ class ClientOptions { - private static $_sharedOptions; + private static $sharedOptions; - private $_handlers; - private $_defined; + private $handlers; + private $defined; - private $_options = array(); + private $options = array(); /** * @param array $options Array of client options. */ public function __construct(Array $options = array()) { - $this->_handlers = $this->initialize($options); - $this->_defined = array_keys($options); + $this->handlers = $this->initialize($options); + $this->defined = array_keys($options); } /** @@ -47,18 +47,18 @@ class ClientOptions */ private static function getSharedOptions() { - if (isset(self::$_sharedOptions)) { - return self::$_sharedOptions; + if (isset(self::$sharedOptions)) { + return self::$sharedOptions; } - self::$_sharedOptions = array( + self::$sharedOptions = array( 'profile' => new ClientProfile(), 'connections' => new ClientConnectionFactory(), 'cluster' => new ClientCluster(), 'prefix' => new ClientPrefix(), ); - return self::$_sharedOptions; + return self::$sharedOptions; } /** @@ -70,7 +70,7 @@ class ClientOptions public static function define($option, IOption $handler) { self::getSharedOptions(); - self::$_sharedOptions[$option] = $handler; + self::$sharedOptions[$option] = $handler; } /** @@ -81,7 +81,7 @@ class ClientOptions public static function undefine($option) { self::getSharedOptions(); - unset(self::$_sharedOptions[$option]); + unset(self::$sharedOptions[$option]); } /** @@ -114,7 +114,7 @@ class ClientOptions */ public function __isset($option) { - return in_array($option, $this->_defined); + return in_array($option, $this->defined); } /** @@ -125,14 +125,14 @@ class ClientOptions */ public function __get($option) { - if (isset($this->_options[$option])) { - return $this->_options[$option]; + if (isset($this->options[$option])) { + return $this->options[$option]; } - if (isset($this->_handlers[$option])) { - $handler = $this->_handlers[$option]; + if (isset($this->handlers[$option])) { + $handler = $this->handlers[$option]; $value = $handler instanceof IOption ? $handler->getDefault() : $handler(); - $this->_options[$option] = $value; + $this->options[$option] = $value; return $value; } diff --git a/lib/Predis/Commands/Command.php b/lib/Predis/Commands/Command.php index 7679ac18..79bbe131 100644 --- a/lib/Predis/Commands/Command.php +++ b/lib/Predis/Commands/Command.php @@ -21,8 +21,8 @@ use Predis\Distribution\INodeKeyGenerator; */ abstract class Command implements ICommand { - private $_hash; - private $_arguments = array(); + private $hash; + private $arguments = array(); /** * Returns a filtered array of the arguments. @@ -40,8 +40,8 @@ abstract class Command implements ICommand */ public function setArguments(Array $arguments) { - $this->_arguments = $this->filterArguments($arguments); - unset($this->_hash); + $this->arguments = $this->filterArguments($arguments); + unset($this->hash); } /** @@ -51,8 +51,8 @@ abstract class Command implements ICommand */ public function setRawArguments(Array $arguments) { - $this->_arguments = $arguments; - unset($this->_hash); + $this->arguments = $arguments; + unset($this->hash); } /** @@ -60,7 +60,7 @@ abstract class Command implements ICommand */ public function getArguments() { - return $this->_arguments; + return $this->arguments; } /** @@ -70,8 +70,8 @@ abstract class Command implements ICommand */ public function getArgument($index = 0) { - if (isset($this->_arguments[$index]) === true) { - return $this->_arguments[$index]; + if (isset($this->arguments[$index]) === true) { + return $this->arguments[$index]; } } @@ -94,10 +94,10 @@ abstract class Command implements ICommand */ public function prefixKeys($prefix) { - $arguments = $this->onPrefixKeys($this->_arguments, $prefix); + $arguments = $this->onPrefixKeys($this->arguments, $prefix); if (isset($arguments)) { - $this->_arguments = $arguments; - unset($this->_hash); + $this->arguments = $arguments; + unset($this->hash); } } @@ -108,7 +108,7 @@ abstract class Command implements ICommand */ protected function canBeHashed() { - return isset($this->_arguments[0]); + return isset($this->arguments[0]); } /** @@ -141,15 +141,15 @@ abstract class Command implements ICommand */ public function getHash(INodeKeyGenerator $distributor) { - if (isset($this->_hash)) { - return $this->_hash; + if (isset($this->hash)) { + return $this->hash; } if ($this->canBeHashed()) { - $key = Helpers::getKeyHashablePart($this->_arguments[0]); - $this->_hash = $distributor->generateKey($key); + $key = Helpers::getKeyHashablePart($this->arguments[0]); + $this->hash = $distributor->generateKey($key); - return $this->_hash; + return $this->hash; } return null; diff --git a/lib/Predis/Commands/Processors/KeyPrefixProcessor.php b/lib/Predis/Commands/Processors/KeyPrefixProcessor.php index bb1baebb..211d6c56 100644 --- a/lib/Predis/Commands/Processors/KeyPrefixProcessor.php +++ b/lib/Predis/Commands/Processors/KeyPrefixProcessor.php @@ -21,7 +21,7 @@ use Predis\Commands\ICommand; */ class KeyPrefixProcessor implements ICommandProcessor { - private $_prefix; + private $prefix; /** * @param string $prefix Prefix for the keys. @@ -38,7 +38,7 @@ class KeyPrefixProcessor implements ICommandProcessor */ public function setPrefix($prefix) { - $this->_prefix = $prefix; + $this->prefix = $prefix; } /** @@ -48,7 +48,7 @@ class KeyPrefixProcessor implements ICommandProcessor */ public function getPrefix() { - return $this->_prefix; + return $this->prefix; } /** @@ -56,6 +56,6 @@ class KeyPrefixProcessor implements ICommandProcessor */ public function process(ICommand $command) { - $command->prefixKeys($this->_prefix); + $command->prefixKeys($this->prefix); } } diff --git a/lib/Predis/Commands/Processors/ProcessorChain.php b/lib/Predis/Commands/Processors/ProcessorChain.php index 6377c8c5..6018000f 100644 --- a/lib/Predis/Commands/Processors/ProcessorChain.php +++ b/lib/Predis/Commands/Processors/ProcessorChain.php @@ -20,7 +20,7 @@ use Predis\Commands\ICommand; */ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess { - private $_processors; + private $processors; /** * @param array $processors List of instances of ICommandProcessor. @@ -37,7 +37,7 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function add(ICommandProcessor $processor) { - $this->_processors[] = $processor; + $this->processors[] = $processor; } /** @@ -45,7 +45,7 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function remove(ICommandProcessor $processor) { - $index = array_search($processor, $this->_processors, true); + $index = array_search($processor, $this->processors, true); if ($index !== false) { unset($this[$index]); } @@ -56,9 +56,9 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function process(ICommand $command) { - $count = count($this->_processors); + $count = count($this->processors); for ($i = 0; $i < $count; $i++) { - $this->_processors[$i]->process($command); + $this->processors[$i]->process($command); } } @@ -67,7 +67,7 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function getProcessors() { - return $this->_processors; + return $this->processors; } /** @@ -77,7 +77,7 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function getIterator() { - return new \ArrayIterator($this->_processors); + return new \ArrayIterator($this->processors); } /** @@ -87,7 +87,7 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function count() { - return count($this->_processors); + return count($this->processors); } /** @@ -95,7 +95,7 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function offsetExists($index) { - return isset($this->_processors[$index]); + return isset($this->processors[$index]); } /** @@ -103,7 +103,7 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function offsetGet($index) { - return $this->_processors[$index]; + return $this->processors[$index]; } /** @@ -118,7 +118,7 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess ); } - $this->_processors[$index] = $processor; + $this->processors[$index] = $processor; } /** @@ -126,6 +126,6 @@ class ProcessorChain implements ICommandProcessorChain, \ArrayAccess */ public function offsetUnset($index) { - unset($this->_processors[$index]); + unset($this->processors[$index]); } } diff --git a/lib/Predis/Commands/ServerShutdown.php b/lib/Predis/Commands/ServerShutdown.php index 61e2b0e6..ffe4d0d8 100644 --- a/lib/Predis/Commands/ServerShutdown.php +++ b/lib/Predis/Commands/ServerShutdown.php @@ -20,7 +20,8 @@ class ServerShutdown extends Command /** * {@inheritdoc} */ - public function getId() { + public function getId() + { return 'SHUTDOWN'; } diff --git a/lib/Predis/CommunicationException.php b/lib/Predis/CommunicationException.php index fa09a8a5..47c15c38 100644 --- a/lib/Predis/CommunicationException.php +++ b/lib/Predis/CommunicationException.php @@ -20,7 +20,7 @@ use Predis\Network\IConnectionSingle; */ abstract class CommunicationException extends PredisException { - private $_connection; + private $connection; /** * @param IConnectionSingle $connection Connection that generated the exception. @@ -33,7 +33,7 @@ abstract class CommunicationException extends PredisException { parent::__construct($message, $code, $innerException); - $this->_connection = $connection; + $this->connection = $connection; } /** @@ -43,7 +43,7 @@ abstract class CommunicationException extends PredisException */ public function getConnection() { - return $this->_connection; + return $this->connection; } /** diff --git a/lib/Predis/ConnectionFactory.php b/lib/Predis/ConnectionFactory.php index 040a8cfb..49812392 100644 --- a/lib/Predis/ConnectionFactory.php +++ b/lib/Predis/ConnectionFactory.php @@ -22,16 +22,16 @@ use Predis\Network\IConnectionSingle; */ class ConnectionFactory implements IConnectionFactory { - private static $_globalSchemes; + private static $globalSchemes; - private $_instanceSchemes = array(); + private $instanceSchemes = array(); /** * @param array $schemesMap Map of URI schemes to connection classes. */ public function __construct(Array $schemesMap = null) { - $this->_instanceSchemes = self::ensureDefaultSchemes(); + $this->instanceSchemes = self::ensureDefaultSchemes(); if (isset($schemesMap)) { foreach ($schemesMap as $scheme => $initializer) { @@ -69,14 +69,14 @@ class ConnectionFactory implements IConnectionFactory */ private static function ensureDefaultSchemes() { - if (!isset(self::$_globalSchemes)) { - self::$_globalSchemes = array( + if (!isset(self::$globalSchemes)) { + self::$globalSchemes = array( 'tcp' => '\Predis\Network\StreamConnection', 'unix' => '\Predis\Network\StreamConnection', ); } - return self::$_globalSchemes; + return self::$globalSchemes; } /** @@ -89,7 +89,7 @@ class ConnectionFactory implements IConnectionFactory { self::ensureDefaultSchemes(); self::checkConnectionInitializer($connectionInitializer); - self::$_globalSchemes[$scheme] = $connectionInitializer; + self::$globalSchemes[$scheme] = $connectionInitializer; } /** @@ -101,7 +101,7 @@ class ConnectionFactory implements IConnectionFactory public function defineConnection($scheme, $connectionInitializer) { self::checkConnectionInitializer($connectionInitializer); - $this->_instanceSchemes[$scheme] = $connectionInitializer; + $this->instanceSchemes[$scheme] = $connectionInitializer; } /** @@ -114,11 +114,11 @@ class ConnectionFactory implements IConnectionFactory } $scheme = $parameters->scheme; - if (!isset($this->_instanceSchemes[$scheme])) { + if (!isset($this->instanceSchemes[$scheme])) { throw new \InvalidArgumentException("Unknown connection scheme: $scheme"); } - $initializer = $this->_instanceSchemes[$scheme]; + $initializer = $this->instanceSchemes[$scheme]; if (!is_callable($initializer)) { return new $initializer($parameters); } diff --git a/lib/Predis/ConnectionParameters.php b/lib/Predis/ConnectionParameters.php index 17d20d25..75818f64 100644 --- a/lib/Predis/ConnectionParameters.php +++ b/lib/Predis/ConnectionParameters.php @@ -21,11 +21,11 @@ use Predis\Options\IOption; */ class ConnectionParameters implements IConnectionParameters { - private static $_defaultParameters; - private static $_validators; + private static $defaultParameters; + private static $validators; - private $_parameters; - private $_userDefined; + private $parameters; + private $userDefined; /** * @param string|array Connection parameters in the form of an URI string or a named array. @@ -38,8 +38,8 @@ class ConnectionParameters implements IConnectionParameters $parameters = $this->parseURI($parameters); } - $this->_userDefined = array_keys($parameters); - $this->_parameters = $this->filter($parameters) + self::$_defaultParameters; + $this->userDefined = array_keys($parameters); + $this->parameters = $this->filter($parameters) + self::$defaultParameters; } /** @@ -47,8 +47,8 @@ class ConnectionParameters implements IConnectionParameters */ private static function ensureDefaults() { - if (!isset(self::$_defaultParameters)) { - self::$_defaultParameters = array( + if (!isset(self::$defaultParameters)) { + self::$defaultParameters = array( 'scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379, @@ -66,12 +66,12 @@ class ConnectionParameters implements IConnectionParameters ); } - if (!isset(self::$_validators)) { + if (!isset(self::$validators)) { $bool = function($value) { return (bool) $value; }; $float = function($value) { return (float) $value; }; $int = function($value) { return (int) $value; }; - self::$_validators = array( + self::$validators = array( 'port' => $int, 'connection_async' => $bool, 'connection_persistent' => $bool, @@ -93,15 +93,15 @@ class ConnectionParameters implements IConnectionParameters public static function define($parameter, $default, $callable = null) { self::ensureDefaults(); - self::$_defaultParameters[$parameter] = $default; + self::$defaultParameters[$parameter] = $default; if ($default instanceof IOption) { - self::$_validators[$parameter] = $default; + self::$validators[$parameter] = $default; return; } if (!isset($callable)) { - unset(self::$_validators[$parameter]); + unset(self::$validators[$parameter]); return; } @@ -111,7 +111,7 @@ class ConnectionParameters implements IConnectionParameters ); } - self::$_validators[$parameter] = $callable; + self::$validators[$parameter] = $callable; } /** @@ -122,7 +122,7 @@ class ConnectionParameters implements IConnectionParameters public static function undefine($parameter) { self::ensureDefaults(); - unset(self::$_defaultParameters[$parameter], self::$_validators[$parameter]); + unset(self::$defaultParameters[$parameter], self::$validators[$parameter]); } /** @@ -162,7 +162,7 @@ class ConnectionParameters implements IConnectionParameters private function filter(Array $parameters) { if (count($parameters) > 0) { - $validators = array_intersect_key(self::$_validators, $parameters); + $validators = array_intersect_key(self::$validators, $parameters); foreach ($validators as $parameter => $validator) { $parameters[$parameter] = $validator($parameters[$parameter]); } @@ -176,10 +176,10 @@ class ConnectionParameters implements IConnectionParameters */ public function __get($parameter) { - $value = $this->_parameters[$parameter]; + $value = $this->parameters[$parameter]; if ($value instanceof IOption) { - $this->_parameters[$parameter] = ($value = $value->getDefault()); + $this->parameters[$parameter] = ($value = $value->getDefault()); } return $value; @@ -190,7 +190,7 @@ class ConnectionParameters implements IConnectionParameters */ public function __isset($parameter) { - return isset($this->_parameters[$parameter]); + return isset($this->parameters[$parameter]); } /** @@ -201,7 +201,7 @@ class ConnectionParameters implements IConnectionParameters */ public function isSetByUser($parameter) { - return in_array($parameter, $this->_userDefined); + return in_array($parameter, $this->userDefined); } /** @@ -231,7 +231,7 @@ class ConnectionParameters implements IConnectionParameters */ public function toArray() { - return $this->_parameters; + return $this->parameters; } /** @@ -245,7 +245,7 @@ class ConnectionParameters implements IConnectionParameters $parameters = $this->toArray(); $reject = $this->getDisallowedURIParts(); - foreach ($this->_userDefined as $param) { + foreach ($this->userDefined as $param) { if (in_array($param, $reject) || !isset($parameters[$param])) { continue; } diff --git a/lib/Predis/DispatcherLoop.php b/lib/Predis/DispatcherLoop.php index 3219c27b..4495dbd6 100644 --- a/lib/Predis/DispatcherLoop.php +++ b/lib/Predis/DispatcherLoop.php @@ -19,20 +19,20 @@ namespace Predis; */ class DispatcherLoop { - private $_client; - private $_pubSubContext; - private $_callbacks; - private $_defaultCallback; - private $_subscriptionCallback; + private $client; + private $pubSubContext; + private $callbacks; + private $defaultCallback; + private $subscriptionCallback; /** * @param Client Client instance used by the context. */ public function __construct(Client $client) { - $this->_callbacks = array(); - $this->_client = $client; - $this->_pubSubContext = $client->pubSub(); + $this->callbacks = array(); + $this->client = $client; + $this->pubSubContext = $client->pubSub(); } /** @@ -54,7 +54,7 @@ class DispatcherLoop */ public function getPubSubContext() { - return $this->_pubSubContext; + return $this->pubSubContext; } /** @@ -67,7 +67,7 @@ class DispatcherLoop if (isset($callable)) { $this->validateCallback($callable); } - $this->_subscriptionCallback = $callable; + $this->subscriptionCallback = $callable; } /** @@ -81,7 +81,7 @@ class DispatcherLoop if (isset($callable)) { $this->validateCallback($callable); } - $this->_subscriptionCallback = $callable; + $this->subscriptionCallback = $callable; } /** @@ -93,8 +93,8 @@ class DispatcherLoop public function attachCallback($channel, $callback) { $this->validateCallback($callback); - $this->_callbacks[$channel] = $callback; - $this->_pubSubContext->subscribe($channel); + $this->callbacks[$channel] = $callback; + $this->pubSubContext->subscribe($channel); } /** @@ -104,9 +104,9 @@ class DispatcherLoop */ public function detachCallback($channel) { - if (isset($this->_callbacks[$channel])) { - unset($this->_callbacks[$channel]); - $this->_pubSubContext->unsubscribe($channel); + if (isset($this->callbacks[$channel])) { + unset($this->callbacks[$channel]); + $this->pubSubContext->unsubscribe($channel); } } @@ -115,23 +115,23 @@ class DispatcherLoop */ public function run() { - foreach ($this->_pubSubContext as $message) { + foreach ($this->pubSubContext as $message) { $kind = $message->kind; if ($kind !== PubSubContext::MESSAGE && $kind !== PubSubContext::PMESSAGE) { - if (isset($this->_subscriptionCallback)) { - $callback = $this->_subscriptionCallback; + if (isset($this->subscriptionCallback)) { + $callback = $this->subscriptionCallback; $callback($message); } continue; } - if (isset($this->_callbacks[$message->channel])) { - $callback = $this->_callbacks[$message->channel]; + if (isset($this->callbacks[$message->channel])) { + $callback = $this->callbacks[$message->channel]; $callback($message->payload); } - else if (isset($this->_defaultCallback)) { - $callback = $this->_defaultCallback; + else if (isset($this->defaultCallback)) { + $callback = $this->defaultCallback; $callback($message); } } @@ -142,6 +142,6 @@ class DispatcherLoop */ public function stop() { - $this->_pubSubContext->closeContext(); + $this->pubSubContext->closeContext(); } } diff --git a/lib/Predis/Distribution/HashRing.php b/lib/Predis/Distribution/HashRing.php index 51dd8e48..12eff18e 100644 --- a/lib/Predis/Distribution/HashRing.php +++ b/lib/Predis/Distribution/HashRing.php @@ -24,19 +24,19 @@ class HashRing implements IDistributionStrategy const DEFAULT_REPLICAS = 128; const DEFAULT_WEIGHT = 100; - private $_nodes; - private $_ring; - private $_ringKeys; - private $_ringKeysCount; - private $_replicas; + private $nodes; + private $ring; + private $ringKeys; + private $ringKeysCount; + private $replicas; /** * @param int $replicas Number of replicas in the ring. */ public function __construct($replicas = self::DEFAULT_REPLICAS) { - $this->_replicas = $replicas; - $this->_nodes = array(); + $this->replicas = $replicas; + $this->nodes = array(); } /** @@ -49,7 +49,7 @@ class HashRing implements IDistributionStrategy { // In case of collisions in the hashes of the nodes, the node added // last wins, thus the order in which nodes are added is significant. - $this->_nodes[] = array('object' => $node, 'weight' => (int) $weight ?: $this::DEFAULT_WEIGHT); + $this->nodes[] = array('object' => $node, 'weight' => (int) $weight ?: $this::DEFAULT_WEIGHT); $this->reset(); } @@ -62,9 +62,9 @@ class HashRing implements IDistributionStrategy // scratch, in order to reassign possible hashes with collisions to the // right node according to the order in which they were added in the // first place. - for ($i = 0; $i < count($this->_nodes); ++$i) { - if ($this->_nodes[$i]['object'] === $node) { - array_splice($this->_nodes, $i, 1); + for ($i = 0; $i < count($this->nodes); ++$i) { + if ($this->nodes[$i]['object'] === $node) { + array_splice($this->nodes, $i, 1); $this->reset(); break; } @@ -77,9 +77,9 @@ class HashRing implements IDistributionStrategy private function reset() { unset( - $this->_ring, - $this->_ringKeys, - $this->_ringKeysCount + $this->ring, + $this->ringKeys, + $this->ringKeysCount ); } @@ -90,7 +90,7 @@ class HashRing implements IDistributionStrategy */ private function isInitialized() { - return isset($this->_ringKeys); + return isset($this->ringKeys); } /** @@ -101,7 +101,7 @@ class HashRing implements IDistributionStrategy private function computeTotalWeight() { $totalWeight = 0; - foreach ($this->_nodes as $node) { + foreach ($this->nodes as $node) { $totalWeight += $node['weight']; } @@ -117,22 +117,22 @@ class HashRing implements IDistributionStrategy return; } - if (count($this->_nodes) === 0) { + if (count($this->nodes) === 0) { throw new EmptyRingException('Cannot initialize empty hashring'); } - $this->_ring = array(); + $this->ring = array(); $totalWeight = $this->computeTotalWeight(); - $nodesCount = count($this->_nodes); + $nodesCount = count($this->nodes); - foreach ($this->_nodes as $node) { + foreach ($this->nodes as $node) { $weightRatio = $node['weight'] / $totalWeight; - $this->addNodeToRing($this->_ring, $node, $nodesCount, $this->_replicas, $weightRatio); + $this->addNodeToRing($this->ring, $node, $nodesCount, $this->replicas, $weightRatio); } - ksort($this->_ring, SORT_NUMERIC); + ksort($this->ring, SORT_NUMERIC); - $this->_ringKeys = array_keys($this->_ring); - $this->_ringKeysCount = count($this->_ringKeys); + $this->ringKeys = array_keys($this->ring); + $this->ringKeysCount = count($this->ringKeys); } /** @@ -180,7 +180,7 @@ class HashRing implements IDistributionStrategy */ public function get($key) { - return $this->_ring[$this->getNodeKey($key)]; + return $this->ring[$this->getNodeKey($key)]; } /** @@ -192,8 +192,8 @@ class HashRing implements IDistributionStrategy private function getNodeKey($key) { $this->initialize(); - $ringKeys = $this->_ringKeys; - $upper = $this->_ringKeysCount - 1; + $ringKeys = $this->ringKeys; + $upper = $this->ringKeysCount - 1; $lower = 0; while ($lower <= $upper) { @@ -210,7 +210,7 @@ class HashRing implements IDistributionStrategy } } - return $ringKeys[$this->wrapAroundStrategy($upper, $lower, $this->_ringKeysCount)]; + return $ringKeys[$this->wrapAroundStrategy($upper, $lower, $this->ringKeysCount)]; } /** diff --git a/lib/Predis/Iterators/MultiBulkResponse.php b/lib/Predis/Iterators/MultiBulkResponse.php index 3bd9dfe1..8ceb59b5 100644 --- a/lib/Predis/Iterators/MultiBulkResponse.php +++ b/lib/Predis/Iterators/MultiBulkResponse.php @@ -19,9 +19,9 @@ namespace Predis\Iterators; */ abstract class MultiBulkResponse implements \Iterator, \Countable { - protected $_position; - protected $_current; - protected $_replySize; + protected $position; + protected $current; + protected $replySize; /** * {@inheritdoc} @@ -36,7 +36,7 @@ abstract class MultiBulkResponse implements \Iterator, \Countable */ public function current() { - return $this->_current; + return $this->current; } /** @@ -44,7 +44,7 @@ abstract class MultiBulkResponse implements \Iterator, \Countable */ public function key() { - return $this->_position; + return $this->position; } /** @@ -52,11 +52,11 @@ abstract class MultiBulkResponse implements \Iterator, \Countable */ public function next() { - if (++$this->_position < $this->_replySize) { - $this->_current = $this->getValue(); + if (++$this->position < $this->replySize) { + $this->current = $this->getValue(); } - return $this->_position; + return $this->position; } /** @@ -64,7 +64,7 @@ abstract class MultiBulkResponse implements \Iterator, \Countable */ public function valid() { - return $this->_position < $this->_replySize; + return $this->position < $this->replySize; } /** @@ -78,7 +78,7 @@ abstract class MultiBulkResponse implements \Iterator, \Countable */ public function count() { - return $this->_replySize; + return $this->replySize; } /** diff --git a/lib/Predis/Iterators/MultiBulkResponseSimple.php b/lib/Predis/Iterators/MultiBulkResponseSimple.php index f1a106c8..943c8e44 100644 --- a/lib/Predis/Iterators/MultiBulkResponseSimple.php +++ b/lib/Predis/Iterators/MultiBulkResponseSimple.php @@ -21,7 +21,7 @@ use Predis\Network\IConnectionSingle; */ class MultiBulkResponseSimple extends MultiBulkResponse { - private $_connection; + private $connection; /** * @param IConnectionSingle $connection Connection to Redis. @@ -29,10 +29,10 @@ class MultiBulkResponseSimple extends MultiBulkResponse */ public function __construct(IConnectionSingle $connection, $size) { - $this->_connection = $connection; - $this->_position = 0; - $this->_current = $size > 0 ? $this->getValue() : null; - $this->_replySize = $size; + $this->connection = $connection; + $this->position = 0; + $this->current = $size > 0 ? $this->getValue() : null; + $this->replySize = $size; } /** @@ -57,8 +57,8 @@ class MultiBulkResponseSimple extends MultiBulkResponse { if ($drop == true) { if ($this->valid()) { - $this->_position = $this->_replySize; - $this->_connection->disconnect(); + $this->position = $this->replySize; + $this->connection->disconnect(); } } else { @@ -75,6 +75,6 @@ class MultiBulkResponseSimple extends MultiBulkResponse */ protected function getValue() { - return $this->_connection->read(); + return $this->connection->read(); } } diff --git a/lib/Predis/Iterators/MultiBulkResponseTuple.php b/lib/Predis/Iterators/MultiBulkResponseTuple.php index 472c02b4..a84fdba1 100644 --- a/lib/Predis/Iterators/MultiBulkResponseTuple.php +++ b/lib/Predis/Iterators/MultiBulkResponseTuple.php @@ -19,7 +19,7 @@ namespace Predis\Iterators; */ class MultiBulkResponseTuple extends MultiBulkResponse { - private $_iterator; + private $iterator; /** * @param MultiBulkResponseSimple $iterator Multibulk reply iterator. @@ -27,10 +27,10 @@ class MultiBulkResponseTuple extends MultiBulkResponse public function __construct(MultiBulkResponseSimple $iterator) { $virtualSize = count($iterator) / 2; - $this->_iterator = $iterator; - $this->_position = 0; - $this->_current = $virtualSize > 0 ? $this->getValue() : null; - $this->_replySize = $virtualSize; + $this->iterator = $iterator; + $this->position = 0; + $this->current = $virtualSize > 0 ? $this->getValue() : null; + $this->replySize = $virtualSize; } /** @@ -38,7 +38,7 @@ class MultiBulkResponseTuple extends MultiBulkResponse */ public function __destruct() { - $this->_iterator->sync(); + $this->iterator->sync(); } /** @@ -46,11 +46,11 @@ class MultiBulkResponseTuple extends MultiBulkResponse */ protected function getValue() { - $k = $this->_iterator->current(); - $this->_iterator->next(); + $k = $this->iterator->current(); + $this->iterator->next(); - $v = $this->_iterator->current(); - $this->_iterator->next(); + $v = $this->iterator->current(); + $this->iterator->next(); return array($k, $v); } diff --git a/lib/Predis/MonitorContext.php b/lib/Predis/MonitorContext.php index 65b1cb23..eb3fdc91 100644 --- a/lib/Predis/MonitorContext.php +++ b/lib/Predis/MonitorContext.php @@ -18,9 +18,9 @@ namespace Predis; */ class MonitorContext implements \Iterator { - private $_client; - private $_isValid; - private $_position; + private $client; + private $isValid; + private $position; /** * @param Client Client instance used by the context. @@ -28,7 +28,7 @@ class MonitorContext implements \Iterator public function __construct(Client $client) { $this->checkCapabilities($client); - $this->_client = $client; + $this->client = $client; $this->openContext(); } @@ -68,9 +68,9 @@ class MonitorContext implements \Iterator */ protected function openContext() { - $this->_isValid = true; - $monitor = $this->_client->createCommand('monitor'); - $this->_client->executeCommand($monitor); + $this->isValid = true; + $monitor = $this->client->createCommand('monitor'); + $this->client->executeCommand($monitor); } /** @@ -79,8 +79,8 @@ class MonitorContext implements \Iterator */ public function closeContext() { - $this->_client->disconnect(); - $this->_isValid = false; + $this->client->disconnect(); + $this->isValid = false; } /** @@ -106,7 +106,7 @@ class MonitorContext implements \Iterator */ public function key() { - return $this->_position; + return $this->position; } /** @@ -114,7 +114,7 @@ class MonitorContext implements \Iterator */ public function next() { - $this->_position++; + $this->position++; } /** @@ -124,7 +124,7 @@ class MonitorContext implements \Iterator */ public function valid() { - return $this->_isValid; + return $this->isValid; } /** @@ -136,7 +136,7 @@ class MonitorContext implements \Iterator private function getValue() { $database = 0; - $event = $this->_client->getConnection()->read(); + $event = $this->client->getConnection()->read(); $callback = function($matches) use (&$database) { if (isset($matches[1])) { diff --git a/lib/Predis/Network/ComposableStreamConnection.php b/lib/Predis/Network/ComposableStreamConnection.php index 08fa63be..df889c4f 100644 --- a/lib/Predis/Network/ComposableStreamConnection.php +++ b/lib/Predis/Network/ComposableStreamConnection.php @@ -24,7 +24,7 @@ use Predis\Protocol\Text\TextProtocol; */ class ComposableStreamConnection extends StreamConnection implements IConnectionComposable { - private $_protocol; + private $protocol; /** * @param IConnectionParameters $parameters Parameters used to initialize the connection. @@ -42,8 +42,8 @@ class ComposableStreamConnection extends StreamConnection implements IConnection */ protected function initializeProtocol(IConnectionParameters $parameters) { - $this->_protocol->setOption('throw_errors', $parameters->throw_errors); - $this->_protocol->setOption('iterable_multibulk', $parameters->iterable_multibulk); + $this->protocol->setOption('throw_errors', $parameters->throw_errors); + $this->protocol->setOption('iterable_multibulk', $parameters->iterable_multibulk); } /** @@ -54,7 +54,7 @@ class ComposableStreamConnection extends StreamConnection implements IConnection if ($protocol === null) { throw new \InvalidArgumentException("The protocol instance cannot be a null value"); } - $this->_protocol = $protocol; + $this->protocol = $protocol; } /** @@ -62,7 +62,7 @@ class ComposableStreamConnection extends StreamConnection implements IConnection */ public function getProtocol() { - return $this->_protocol; + return $this->protocol; } /** @@ -122,7 +122,7 @@ class ComposableStreamConnection extends StreamConnection implements IConnection */ public function writeCommand(ICommand $command) { - $this->_protocol->write($this, $command); + $this->protocol->write($this, $command); } /** @@ -130,6 +130,6 @@ class ComposableStreamConnection extends StreamConnection implements IConnection */ public function read() { - return $this->_protocol->read($this); + return $this->protocol->read($this); } } diff --git a/lib/Predis/Network/ConnectionBase.php b/lib/Predis/Network/ConnectionBase.php index 310a4523..2af7933c 100644 --- a/lib/Predis/Network/ConnectionBase.php +++ b/lib/Predis/Network/ConnectionBase.php @@ -26,19 +26,19 @@ use Predis\Protocol\ProtocolException; */ abstract class ConnectionBase implements IConnectionSingle { - private $_resource; - private $_cachedId; + private $resource; + private $cachedId; - protected $_params; - protected $_initCmds; + protected $params; + protected $initCmds; /** * @param IConnectionParameters $parameters Parameters used to initialize the connection. */ public function __construct(IConnectionParameters $parameters) { - $this->_initCmds = array(); - $this->_params = $this->checkParameters($parameters); + $this->initCmds = array(); + $this->params = $this->checkParameters($parameters); $this->initializeProtocol($parameters); } @@ -95,7 +95,7 @@ abstract class ConnectionBase implements IConnectionSingle */ public function isConnected() { - return isset($this->_resource); + return isset($this->resource); } /** @@ -106,7 +106,7 @@ abstract class ConnectionBase implements IConnectionSingle if ($this->isConnected()) { throw new ClientException('Connection already estabilished'); } - $this->_resource = $this->createResource(); + $this->resource = $this->createResource(); } /** @@ -114,7 +114,7 @@ abstract class ConnectionBase implements IConnectionSingle */ public function disconnect() { - unset($this->_resource); + unset($this->resource); } /** @@ -122,7 +122,7 @@ abstract class ConnectionBase implements IConnectionSingle */ public function pushInitCommand(ICommand $command) { - $this->_initCmds[] = $command; + $this->initCmds[] = $command; } /** @@ -190,13 +190,13 @@ abstract class ConnectionBase implements IConnectionSingle */ public function getResource() { - if (isset($this->_resource)) { - return $this->_resource; + if (isset($this->resource)) { + return $this->resource; } $this->connect(); - return $this->_resource; + return $this->resource; } /** @@ -204,7 +204,7 @@ abstract class ConnectionBase implements IConnectionSingle */ public function getParameters() { - return $this->_params; + return $this->params; } /** @@ -214,11 +214,11 @@ abstract class ConnectionBase implements IConnectionSingle */ protected function getIdentifier() { - if ($this->_params->scheme === 'unix') { - return $this->_params->path; + if ($this->params->scheme === 'unix') { + return $this->params->path; } - return "{$this->_params->host}:{$this->_params->port}"; + return "{$this->params->host}:{$this->params->port}"; } /** @@ -226,10 +226,10 @@ abstract class ConnectionBase implements IConnectionSingle */ public function __toString() { - if (!isset($this->_cachedId)) { - $this->_cachedId = $this->getIdentifier(); + if (!isset($this->cachedId)) { + $this->cachedId = $this->getIdentifier(); } - return $this->_cachedId; + return $this->cachedId; } } diff --git a/lib/Predis/Network/PhpiredisConnection.php b/lib/Predis/Network/PhpiredisConnection.php index 524c5bbb..9058b131 100644 --- a/lib/Predis/Network/PhpiredisConnection.php +++ b/lib/Predis/Network/PhpiredisConnection.php @@ -39,7 +39,7 @@ use Predis\Commands\ICommand; */ class PhpiredisConnection extends ConnectionBase { - private $_reader; + private $reader; /** * {@inheritdoc} @@ -62,7 +62,7 @@ class PhpiredisConnection extends ConnectionBase */ public function __destruct() { - phpiredis_reader_destroy($this->_reader); + phpiredis_reader_destroy($this->reader); parent::__destruct(); } @@ -101,7 +101,7 @@ class PhpiredisConnection extends ConnectionBase phpiredis_reader_set_status_handler($reader, $this->getStatusHandler()); phpiredis_reader_set_error_handler($reader, $this->getErrorHandler($throw_errors)); - $this->_reader = $reader; + $this->reader = $reader; } /** @@ -170,7 +170,7 @@ class PhpiredisConnection extends ConnectionBase */ protected function createResource() { - $parameters = $this->_params; + $parameters = $this->params; $initializer = array($this, "{$parameters->scheme}SocketInitializer"); $socket = call_user_func($initializer, $parameters); @@ -325,8 +325,8 @@ class PhpiredisConnection extends ConnectionBase { parent::connect(); - $this->connectWithTimeout($this->_params); - if (count($this->_initCmds) > 0) { + $this->connectWithTimeout($this->params); + if (count($this->initCmds) > 0) { $this->sendInitializationCommands(); } } @@ -348,10 +348,10 @@ class PhpiredisConnection extends ConnectionBase */ private function sendInitializationCommands() { - foreach ($this->_initCmds as $command) { + foreach ($this->initCmds as $command) { $this->writeCommand($command); } - foreach ($this->_initCmds as $command) { + foreach ($this->initCmds as $command) { $this->readResponse($command); } } @@ -383,7 +383,7 @@ class PhpiredisConnection extends ConnectionBase public function read() { $socket = $this->getResource(); - $reader = $this->_reader; + $reader = $this->reader; while (($state = phpiredis_reader_get_state($reader)) === PHPIREDIS_READER_STATE_INCOMPLETE) { if (@socket_recv($socket, $buffer, 4096, 0) === false || $buffer === '') { diff --git a/lib/Predis/Network/PredisCluster.php b/lib/Predis/Network/PredisCluster.php index 3531b674..c82f44f8 100644 --- a/lib/Predis/Network/PredisCluster.php +++ b/lib/Predis/Network/PredisCluster.php @@ -25,16 +25,16 @@ use Predis\Distribution\HashRing; */ class PredisCluster implements IConnectionCluster, \IteratorAggregate { - private $_pool; - private $_distributor; + private $pool; + private $distributor; /** * @param IDistributionStrategy $distributor Distribution strategy used by the cluster. */ public function __construct(IDistributionStrategy $distributor = null) { - $this->_pool = array(); - $this->_distributor = $distributor ?: new HashRing(); + $this->pool = array(); + $this->distributor = $distributor ?: new HashRing(); } /** @@ -42,7 +42,7 @@ class PredisCluster implements IConnectionCluster, \IteratorAggregate */ public function isConnected() { - foreach ($this->_pool as $connection) { + foreach ($this->pool as $connection) { if ($connection->isConnected()) { return true; } @@ -56,7 +56,7 @@ class PredisCluster implements IConnectionCluster, \IteratorAggregate */ public function connect() { - foreach ($this->_pool as $connection) { + foreach ($this->pool as $connection) { $connection->connect(); } } @@ -66,7 +66,7 @@ class PredisCluster implements IConnectionCluster, \IteratorAggregate */ public function disconnect() { - foreach ($this->_pool as $connection) { + foreach ($this->pool as $connection) { $connection->disconnect(); } } @@ -79,13 +79,13 @@ class PredisCluster implements IConnectionCluster, \IteratorAggregate $parameters = $connection->getParameters(); if (isset($parameters->alias)) { - $this->_pool[$parameters->alias] = $connection; + $this->pool[$parameters->alias] = $connection; } else { - $this->_pool[] = $connection; + $this->pool[] = $connection; } - $this->_distributor->add($connection, $parameters->weight); + $this->distributor->add($connection, $parameters->weight); } /** @@ -93,10 +93,10 @@ class PredisCluster implements IConnectionCluster, \IteratorAggregate */ public function getConnection(ICommand $command) { - $cmdHash = $command->getHash($this->_distributor); + $cmdHash = $command->getHash($this->distributor); if (isset($cmdHash)) { - return $this->_distributor->get($cmdHash); + return $this->distributor->get($cmdHash); } throw new ClientException( @@ -111,7 +111,7 @@ class PredisCluster implements IConnectionCluster, \IteratorAggregate { $alias = $id ?: 0; - return isset($this->_pool[$alias]) ? $this->_pool[$alias] : null; + return isset($this->pool[$alias]) ? $this->pool[$alias] : null; } @@ -124,9 +124,9 @@ class PredisCluster implements IConnectionCluster, \IteratorAggregate public function getConnectionByKey($key) { $hashablePart = Helpers::getKeyHashablePart($key); - $keyHash = $this->_distributor->generateKey($hashablePart); + $keyHash = $this->distributor->generateKey($hashablePart); - return $this->_distributor->get($keyHash); + return $this->distributor->get($keyHash); } /** @@ -134,7 +134,7 @@ class PredisCluster implements IConnectionCluster, \IteratorAggregate */ public function getIterator() { - return new \ArrayIterator($this->_pool); + return new \ArrayIterator($this->pool); } /** diff --git a/lib/Predis/Network/StreamConnection.php b/lib/Predis/Network/StreamConnection.php index c3ca56fb..ab0bc9d1 100644 --- a/lib/Predis/Network/StreamConnection.php +++ b/lib/Predis/Network/StreamConnection.php @@ -25,8 +25,8 @@ use Predis\Iterators\MultiBulkResponseSimple; */ class StreamConnection extends ConnectionBase { - private $_mbiterable; - private $_throwErrors; + private $mbiterable; + private $throwErrors; /** * Disconnects from the server and destroys the underlying resource when @@ -35,7 +35,7 @@ class StreamConnection extends ConnectionBase */ public function __destruct() { - if (!$this->_params->connection_persistent) { + if (!$this->params->connection_persistent) { $this->disconnect(); } } @@ -45,8 +45,8 @@ class StreamConnection extends ConnectionBase */ protected function initializeProtocol(IConnectionParameters $parameters) { - $this->_throwErrors = $parameters->throw_errors; - $this->_mbiterable = $parameters->iterable_multibulk; + $this->throwErrors = $parameters->throw_errors; + $this->mbiterable = $parameters->iterable_multibulk; } /** @@ -54,7 +54,7 @@ class StreamConnection extends ConnectionBase */ protected function createResource() { - $parameters = $this->_params; + $parameters = $this->params; $initializer = "{$parameters->scheme}StreamInitializer"; return $this->$initializer($parameters); @@ -130,7 +130,7 @@ class StreamConnection extends ConnectionBase { parent::connect(); - if (count($this->_initCmds) > 0){ + if (count($this->initCmds) > 0){ $this->sendInitializationCommands(); } } @@ -152,10 +152,10 @@ class StreamConnection extends ConnectionBase */ private function sendInitializationCommands() { - foreach ($this->_initCmds as $command) { + foreach ($this->initCmds as $command) { $this->writeCommand($command); } - foreach ($this->_initCmds as $command) { + foreach ($this->initCmds as $command) { $this->readResponse($command); } } @@ -237,7 +237,7 @@ class StreamConnection extends ConnectionBase return null; } - if ($this->_mbiterable === true) { + if ($this->mbiterable === true) { return new MultiBulkResponseSimple($this, $count); } @@ -252,7 +252,7 @@ class StreamConnection extends ConnectionBase return (int) $payload; case '-': // error - if ($this->_throwErrors) { + if ($this->throwErrors) { throw new ServerException($payload); } return new ResponseError($payload); diff --git a/lib/Predis/Network/WebdisConnection.php b/lib/Predis/Network/WebdisConnection.php index 35ef92d4..ec071850 100644 --- a/lib/Predis/Network/WebdisConnection.php +++ b/lib/Predis/Network/WebdisConnection.php @@ -38,24 +38,24 @@ const ERR_MSG_EXTENSION = 'The %s extension must be loaded in order to be able t */ class WebdisConnection implements IConnectionSingle { - private $_parameters; - private $_resource; - private $_reader; + private $parameters; + private $resource; + private $reader; /** * @param IConnectionParameters $parameters Parameters used to initialize the connection. */ public function __construct(IConnectionParameters $parameters) { - $this->_parameters = $parameters; + $this->parameters = $parameters; if ($parameters->scheme !== 'http') { throw new \InvalidArgumentException("Invalid scheme: {$parameters->scheme}"); } $this->checkExtensions(); - $this->_resource = $this->initializeCurl($parameters); - $this->_reader = $this->initializeReader($parameters); + $this->resource = $this->initializeCurl($parameters); + $this->reader = $this->initializeReader($parameters); } /** @@ -64,8 +64,8 @@ class WebdisConnection implements IConnectionSingle */ public function __destruct() { - curl_close($this->_resource); - phpiredis_reader_destroy($this->_reader); + curl_close($this->resource); + phpiredis_reader_destroy($this->reader); } /** @@ -173,7 +173,7 @@ class WebdisConnection implements IConnectionSingle */ protected function feedReader($resource, $buffer) { - phpiredis_reader_feed($this->_reader, $buffer); + phpiredis_reader_feed($this->reader, $buffer); return strlen($buffer); } @@ -246,7 +246,7 @@ class WebdisConnection implements IConnectionSingle */ public function executeCommand(ICommand $command) { - $resource = $this->_resource; + $resource = $this->resource; $commandId = $this->getCommandId($command); if ($arguments = $command->getArguments()) { @@ -265,17 +265,17 @@ class WebdisConnection implements IConnectionSingle throw new ConnectionException($this, trim($error), $errno); } - $readerState = phpiredis_reader_get_state($this->_reader); + $readerState = phpiredis_reader_get_state($this->reader); if ($readerState === PHPIREDIS_READER_STATE_COMPLETE) { - $reply = phpiredis_reader_get_reply($this->_reader); + $reply = phpiredis_reader_get_reply($this->reader); if ($reply instanceof IReplyObject) { return $reply; } return $command->parseResponse($reply); } else { - $error = phpiredis_reader_get_error($this->_reader); + $error = phpiredis_reader_get_error($this->reader); throw new ProtocolException($this, $error); } } @@ -285,7 +285,7 @@ class WebdisConnection implements IConnectionSingle */ public function getResource() { - return $this->_resource; + return $this->resource; } /** @@ -293,7 +293,7 @@ class WebdisConnection implements IConnectionSingle */ public function getParameters() { - return $this->_parameters; + return $this->parameters; } /** @@ -317,6 +317,6 @@ class WebdisConnection implements IConnectionSingle */ public function __toString() { - return "{$this->_parameters->host}:{$this->_parameters->port}"; + return "{$this->parameters->host}:{$this->parameters->port}"; } } diff --git a/lib/Predis/Options/CustomOption.php b/lib/Predis/Options/CustomOption.php index a5ada736..7b8686d6 100644 --- a/lib/Predis/Options/CustomOption.php +++ b/lib/Predis/Options/CustomOption.php @@ -18,16 +18,16 @@ namespace Predis\Options; */ class CustomOption implements IOption { - private $_validate; - private $_default; + private $validate; + private $default; /** * @param array $options List of options */ public function __construct(Array $options) { - $this->_validate = $this->filterCallable($options, 'validate'); - $this->_default = $this->filterCallable($options, 'default'); + $this->validate = $this->filterCallable($options, 'validate'); + $this->default = $this->filterCallable($options, 'default'); } /** @@ -56,10 +56,10 @@ class CustomOption implements IOption public function validate($value) { if (isset($value)) { - if ($this->_validate === null) { + if ($this->validate === null) { return $value; } - $validator = $this->_validate; + $validator = $this->validate; return $validator($value); } @@ -70,10 +70,10 @@ class CustomOption implements IOption */ public function getDefault() { - if (!isset($this->_default)) { + if (!isset($this->default)) { return; } - $default = $this->_default; + $default = $this->default; return $default(); } diff --git a/lib/Predis/Pipeline/PipelineContext.php b/lib/Predis/Pipeline/PipelineContext.php index 41293453..51f10e6f 100644 --- a/lib/Predis/Pipeline/PipelineContext.php +++ b/lib/Predis/Pipeline/PipelineContext.php @@ -24,12 +24,12 @@ use Predis\Commands\ICommand; */ class PipelineContext { - private $_client; - private $_executor; + private $client; + private $executor; - private $_pipeline = array(); - private $_replies = array(); - private $_running = false; + private $pipeline = array(); + private $replies = array(); + private $running = false; /** * @param Client Client instance used by the context. @@ -37,8 +37,8 @@ class PipelineContext */ public function __construct(Client $client, Array $options = null) { - $this->_client = $client; - $this->_executor = $this->getExecutor($client, $options ?: array()); + $this->client = $client; + $this->executor = $this->getExecutor($client, $options ?: array()); } /** @@ -83,7 +83,7 @@ class PipelineContext */ public function __call($method, $arguments) { - $command = $this->_client->createCommand($method, $arguments); + $command = $this->client->createCommand($method, $arguments); $this->recordCommand($command); return $this; @@ -94,7 +94,7 @@ class PipelineContext */ protected function recordCommand(ICommand $command) { - $this->_pipeline[] = $command; + $this->pipeline[] = $command; } /** @@ -113,11 +113,11 @@ class PipelineContext */ public function flushPipeline() { - if (count($this->_pipeline) > 0) { - $connection = $this->_client->getConnection(); - $replies = $this->_executor->execute($connection, $this->_pipeline); - $this->_replies = array_merge($this->_replies, $replies); - $this->_pipeline = array(); + if (count($this->pipeline) > 0) { + $connection = $this->client->getConnection(); + $replies = $this->executor->execute($connection, $this->pipeline); + $this->replies = array_merge($this->replies, $replies); + $this->pipeline = array(); } return $this; @@ -131,10 +131,10 @@ class PipelineContext */ private function setRunning($bool) { - if ($bool === true && $this->_running === true) { + if ($bool === true && $this->running === true) { throw new ClientException("This pipeline is already opened"); } - $this->_running = $bool; + $this->running = $bool; } /** @@ -168,6 +168,6 @@ class PipelineContext throw $pipelineBlockException; } - return $this->_replies; + return $this->replies; } } diff --git a/lib/Predis/Profiles/ServerProfile.php b/lib/Predis/Profiles/ServerProfile.php index 3e5c0ebb..8e9e8ab3 100644 --- a/lib/Predis/Profiles/ServerProfile.php +++ b/lib/Predis/Profiles/ServerProfile.php @@ -22,17 +22,17 @@ use Predis\Commands\Processors\IProcessingSupport; */ abstract class ServerProfile implements IServerProfile, IProcessingSupport { - private static $_profiles; + private static $profiles; - private $_registeredCommands; - private $_processor; + private $registeredCommands; + private $processor; /** * */ public function __construct() { - $this->_registeredCommands = $this->getSupportedCommands(); + $this->registeredCommands = $this->getSupportedCommands(); } /** @@ -89,8 +89,8 @@ abstract class ServerProfile implements IServerProfile, IProcessingSupport */ public static function define($alias, $profileClass) { - if (!isset(self::$_profiles)) { - self::$_profiles = self::getDefaultProfiles(); + if (!isset(self::$profiles)) { + self::$profiles = self::getDefaultProfiles(); } $profileReflection = new \ReflectionClass($profileClass); @@ -101,7 +101,7 @@ abstract class ServerProfile implements IServerProfile, IProcessingSupport ); } - self::$_profiles[$alias] = $profileClass; + self::$profiles[$alias] = $profileClass; } /** @@ -112,14 +112,14 @@ abstract class ServerProfile implements IServerProfile, IProcessingSupport */ public static function get($version) { - if (!isset(self::$_profiles)) { - self::$_profiles = self::getDefaultProfiles(); + if (!isset(self::$profiles)) { + self::$profiles = self::getDefaultProfiles(); } - if (!isset(self::$_profiles[$version])) { + if (!isset(self::$profiles[$version])) { throw new ClientException("Unknown server profile: $version"); } - $profile = self::$_profiles[$version]; + $profile = self::$profiles[$version]; return new $profile(); } @@ -143,7 +143,7 @@ abstract class ServerProfile implements IServerProfile, IProcessingSupport */ public function supportsCommand($command) { - return isset($this->_registeredCommands[strtolower($command)]); + return isset($this->registeredCommands[strtolower($command)]); } /** @@ -152,16 +152,16 @@ abstract class ServerProfile implements IServerProfile, IProcessingSupport public function createCommand($method, $arguments = array()) { $method = strtolower($method); - if (!isset($this->_registeredCommands[$method])) { + if (!isset($this->registeredCommands[$method])) { throw new ClientException("'$method' is not a registered Redis command"); } - $commandClass = $this->_registeredCommands[$method]; + $commandClass = $this->registeredCommands[$method]; $command = new $commandClass(); $command->setArguments($arguments); - if (isset($this->_processor)) { - $this->_processor->process($command); + if (isset($this->processor)) { + $this->processor->process($command); } return $command; @@ -191,7 +191,7 @@ abstract class ServerProfile implements IServerProfile, IProcessingSupport if (!$commandReflection->isSubclassOf('\Predis\Commands\ICommand')) { throw new ClientException("Cannot register '$command' as it is not a valid Redis command"); } - $this->_registeredCommands[strtolower($alias)] = $command; + $this->registeredCommands[strtolower($alias)] = $command; } /** @@ -200,10 +200,10 @@ abstract class ServerProfile implements IServerProfile, IProcessingSupport public function setProcessor(ICommandProcessor $processor) { if (!isset($processor)) { - unset($this->_processor); + unset($this->processor); return; } - $this->_processor = $processor; + $this->processor = $processor; } /** @@ -211,7 +211,7 @@ abstract class ServerProfile implements IServerProfile, IProcessingSupport */ public function getProcessor() { - return $this->_processor; + return $this->processor; } /** diff --git a/lib/Predis/Protocol/Text/ComposableTextProtocol.php b/lib/Predis/Protocol/Text/ComposableTextProtocol.php index f3446263..68f5ee5d 100644 --- a/lib/Predis/Protocol/Text/ComposableTextProtocol.php +++ b/lib/Predis/Protocol/Text/ComposableTextProtocol.php @@ -27,8 +27,8 @@ use Predis\Network\IConnectionComposable; */ class ComposableTextProtocol implements IComposableProtocolProcessor { - private $_serializer; - private $_reader; + private $serializer; + private $reader; /** * @param array $options Set of options used to initialize the protocol processor. @@ -63,12 +63,12 @@ class ComposableTextProtocol implements IComposableProtocolProcessor switch ($option) { case 'iterable_multibulk': $handler = $value ? new ResponseMultiBulkStreamHandler() : new ResponseMultiBulkHandler(); - $this->_reader->setHandler(TextProtocol::PREFIX_MULTI_BULK, $handler); + $this->reader->setHandler(TextProtocol::PREFIX_MULTI_BULK, $handler); break; case 'throw_errors': $handler = $value ? new ResponseErrorHandler() : new ResponseErrorSilentHandler(); - $this->_reader->setHandler(TextProtocol::PREFIX_ERROR, $handler); + $this->reader->setHandler(TextProtocol::PREFIX_ERROR, $handler); break; default: @@ -81,7 +81,7 @@ class ComposableTextProtocol implements IComposableProtocolProcessor */ public function serialize(ICommand $command) { - return $this->_serializer->serialize($command); + return $this->serializer->serialize($command); } /** @@ -89,7 +89,7 @@ class ComposableTextProtocol implements IComposableProtocolProcessor */ public function write(IConnectionComposable $connection, ICommand $command) { - $connection->writeBytes($this->_serializer->serialize($command)); + $connection->writeBytes($this->serializer->serialize($command)); } /** @@ -97,7 +97,7 @@ class ComposableTextProtocol implements IComposableProtocolProcessor */ public function read(IConnectionComposable $connection) { - return $this->_reader->read($connection); + return $this->reader->read($connection); } /** @@ -105,7 +105,7 @@ class ComposableTextProtocol implements IComposableProtocolProcessor */ public function setSerializer(ICommandSerializer $serializer) { - $this->_serializer = $serializer; + $this->serializer = $serializer; } /** @@ -113,7 +113,7 @@ class ComposableTextProtocol implements IComposableProtocolProcessor */ public function getSerializer() { - return $this->_serializer; + return $this->serializer; } /** @@ -121,7 +121,7 @@ class ComposableTextProtocol implements IComposableProtocolProcessor */ public function setReader(IResponseReader $reader) { - $this->_reader = $reader; + $this->reader = $reader; } /** @@ -129,6 +129,6 @@ class ComposableTextProtocol implements IComposableProtocolProcessor */ public function getReader() { - return $this->_reader; + return $this->reader; } } diff --git a/lib/Predis/Protocol/Text/TextProtocol.php b/lib/Predis/Protocol/Text/TextProtocol.php index b9349bde..068f9912 100644 --- a/lib/Predis/Protocol/Text/TextProtocol.php +++ b/lib/Predis/Protocol/Text/TextProtocol.php @@ -43,18 +43,18 @@ class TextProtocol implements IProtocolProcessor const BUFFER_SIZE = 4096; - private $_mbiterable; - private $_throwErrors; - private $_serializer; + private $mbiterable; + private $throwErrors; + private $serializer; /** * */ public function __construct() { - $this->_mbiterable = false; - $this->_throwErrors = true; - $this->_serializer = new TextCommandSerializer(); + $this->mbiterable = false; + $this->throwErrors = true; + $this->serializer = new TextCommandSerializer(); } /** @@ -62,7 +62,7 @@ class TextProtocol implements IProtocolProcessor */ public function write(IConnectionComposable $connection, ICommand $command) { - $connection->writeBytes($this->_serializer->serialize($command)); + $connection->writeBytes($this->serializer->serialize($command)); } /** @@ -100,7 +100,7 @@ class TextProtocol implements IProtocolProcessor if ($count === -1) { return null; } - if ($this->_mbiterable == true) { + if ($this->mbiterable == true) { return new MultiBulkResponseSimple($connection, $count); } @@ -115,7 +115,7 @@ class TextProtocol implements IProtocolProcessor return (int) $payload; case '-': // error - if ($this->_throwErrors) { + if ($this->throwErrors) { throw new ServerException($payload); } return new ResponseError($payload); @@ -134,11 +134,11 @@ class TextProtocol implements IProtocolProcessor { switch ($option) { case 'iterable_multibulk': - $this->_mbiterable = (bool) $value; + $this->mbiterable = (bool) $value; break; case 'throw_errors': - $this->_throwErrors = (bool) $value; + $this->throwErrors = (bool) $value; break; } } diff --git a/lib/Predis/Protocol/Text/TextResponseReader.php b/lib/Predis/Protocol/Text/TextResponseReader.php index 81f8a005..c43ef46a 100644 --- a/lib/Predis/Protocol/Text/TextResponseReader.php +++ b/lib/Predis/Protocol/Text/TextResponseReader.php @@ -26,14 +26,14 @@ use Predis\Network\IConnectionComposable; */ class TextResponseReader implements IResponseReader { - private $_prefixHandlers; + private $prefixHandlers; /** * */ public function __construct() { - $this->_prefixHandlers = $this->getDefaultHandlers(); + $this->prefixHandlers = $this->getDefaultHandlers(); } /** @@ -60,7 +60,7 @@ class TextResponseReader implements IResponseReader */ public function setHandler($prefix, IResponseHandler $handler) { - $this->_prefixHandlers[$prefix] = $handler; + $this->prefixHandlers[$prefix] = $handler; } /** @@ -72,8 +72,8 @@ class TextResponseReader implements IResponseReader */ public function getHandler($prefix) { - if (isset($this->_prefixHandlers[$prefix])) { - return $this->_prefixHandlers[$prefix]; + if (isset($this->prefixHandlers[$prefix])) { + return $this->prefixHandlers[$prefix]; } } @@ -88,11 +88,11 @@ class TextResponseReader implements IResponseReader } $prefix = $header[0]; - if (!isset($this->_prefixHandlers[$prefix])) { + if (!isset($this->prefixHandlers[$prefix])) { $this->protocolError($connection, "Unknown prefix '$prefix'"); } - $handler = $this->_prefixHandlers[$prefix]; + $handler = $this->prefixHandlers[$prefix]; return $handler->handle($connection, substr($header, 1)); } diff --git a/lib/Predis/PubSubContext.php b/lib/Predis/PubSubContext.php index 9c0bb188..07fdde27 100644 --- a/lib/Predis/PubSubContext.php +++ b/lib/Predis/PubSubContext.php @@ -29,9 +29,9 @@ class PubSubContext implements \Iterator const STATUS_SUBSCRIBED = 0x0010; const STATUS_PSUBSCRIBED = 0x0100; - private $_client; - private $_position; - private $_options; + private $client; + private $position; + private $options; /** * @param Client Client instance used by the context. @@ -40,9 +40,9 @@ class PubSubContext implements \Iterator public function __construct(Client $client, Array $options = null) { $this->checkCapabilities($client); - $this->_options = $options ?: array(); - $this->_client = $client; - $this->_statusFlags = self::STATUS_VALID; + $this->options = $options ?: array(); + $this->client = $client; + $this->statusFlags = self::STATUS_VALID; $this->genericSubscribeInit('subscribe'); $this->genericSubscribeInit('psubscribe'); @@ -86,8 +86,8 @@ class PubSubContext implements \Iterator */ private function genericSubscribeInit($subscribeAction) { - if (isset($this->_options[$subscribeAction])) { - $this->$subscribeAction($this->_options[$subscribeAction]); + if (isset($this->options[$subscribeAction])) { + $this->$subscribeAction($this->options[$subscribeAction]); } } @@ -99,7 +99,7 @@ class PubSubContext implements \Iterator */ private function isFlagSet($value) { - return ($this->_statusFlags & $value) === $value; + return ($this->statusFlags & $value) === $value; } /** @@ -110,7 +110,7 @@ class PubSubContext implements \Iterator public function subscribe(/* arguments */) { $this->writeCommand(self::SUBSCRIBE, func_get_args()); - $this->_statusFlags |= self::STATUS_SUBSCRIBED; + $this->statusFlags |= self::STATUS_SUBSCRIBED; } /** @@ -131,7 +131,7 @@ class PubSubContext implements \Iterator public function psubscribe(/* arguments */) { $this->writeCommand(self::PSUBSCRIBE, func_get_args()); - $this->_statusFlags |= self::STATUS_PSUBSCRIBED; + $this->statusFlags |= self::STATUS_PSUBSCRIBED; } /** @@ -168,8 +168,8 @@ class PubSubContext implements \Iterator private function writeCommand($method, $arguments) { $arguments = Helpers::filterArrayArguments($arguments); - $command = $this->_client->createCommand($method, $arguments); - $this->_client->getConnection()->writeCommand($command); + $command = $this->client->createCommand($method, $arguments); + $this->client->getConnection()->writeCommand($command); } /** @@ -196,7 +196,7 @@ class PubSubContext implements \Iterator */ public function key() { - return $this->_position; + return $this->position; } /** @@ -205,10 +205,10 @@ class PubSubContext implements \Iterator public function next() { if ($this->isFlagSet(self::STATUS_VALID)) { - $this->_position++; + $this->position++; } - return $this->_position; + return $this->position; } /** @@ -220,7 +220,7 @@ class PubSubContext implements \Iterator { $isValid = $this->isFlagSet(self::STATUS_VALID); $subscriptionFlags = self::STATUS_SUBSCRIBED | self::STATUS_PSUBSCRIBED; - $hasSubscriptions = ($this->_statusFlags & $subscriptionFlags) > 0; + $hasSubscriptions = ($this->statusFlags & $subscriptionFlags) > 0; return $isValid && $hasSubscriptions; } @@ -230,7 +230,7 @@ class PubSubContext implements \Iterator */ private function invalidate() { - $this->_statusFlags = 0x0000; + $this->statusFlags = 0x0000; } /** @@ -241,7 +241,7 @@ class PubSubContext implements \Iterator */ private function getValue() { - $response = $this->_client->getConnection()->read(); + $response = $this->client->getConnection()->read(); switch ($response[0]) { case self::SUBSCRIBE: diff --git a/lib/Predis/ResponseError.php b/lib/Predis/ResponseError.php index 78df43ca..d67400b5 100644 --- a/lib/Predis/ResponseError.php +++ b/lib/Predis/ResponseError.php @@ -19,14 +19,14 @@ namespace Predis; */ class ResponseError implements IRedisServerError { - private $_message; + private $message; /** * @param string $message Error message returned by Redis */ public function __construct($message) { - $this->_message = $message; + $this->message = $message; } /** @@ -34,7 +34,7 @@ class ResponseError implements IRedisServerError */ public function getMessage() { - return $this->_message; + return $this->message; } /** diff --git a/lib/Predis/Transaction/AbortedMultiExecException.php b/lib/Predis/Transaction/AbortedMultiExecException.php index 9be48387..58e46845 100644 --- a/lib/Predis/Transaction/AbortedMultiExecException.php +++ b/lib/Predis/Transaction/AbortedMultiExecException.php @@ -20,7 +20,7 @@ use Predis\PredisException; */ class AbortedMultiExecException extends PredisException { - private $_transaction; + private $transaction; /** * @param MultiExecContext $transaction Transaction that generated the exception. @@ -31,7 +31,7 @@ class AbortedMultiExecException extends PredisException { parent::__construct($message, $code); - $this->_transaction = $transaction; + $this->transaction = $transaction; } /** @@ -41,6 +41,6 @@ class AbortedMultiExecException extends PredisException */ public function getTransaction() { - return $this->_transaction; + return $this->transaction; } } diff --git a/lib/Predis/Transaction/MultiExecContext.php b/lib/Predis/Transaction/MultiExecContext.php index d00f7629..077e468e 100644 --- a/lib/Predis/Transaction/MultiExecContext.php +++ b/lib/Predis/Transaction/MultiExecContext.php @@ -33,12 +33,12 @@ class MultiExecContext const STATE_CAS = 0x01000; const STATE_WATCH = 0x10000; - private $_state; - private $_canWatch; + private $state; + private $canWatch; - protected $_client; - protected $_options; - protected $_commands; + protected $client; + protected $options; + protected $commands; /** * @param Client Client instance used by the context. @@ -47,8 +47,8 @@ class MultiExecContext public function __construct(Client $client, Array $options = null) { $this->checkCapabilities($client); - $this->_options = $options ?: array(); - $this->_client = $client; + $this->options = $options ?: array(); + $this->client = $client; $this->reset(); } @@ -59,7 +59,7 @@ class MultiExecContext */ protected function setState($flags) { - $this->_state = $flags; + $this->state = $flags; } /** @@ -69,7 +69,7 @@ class MultiExecContext */ protected function getState() { - return $this->_state; + return $this->state; } /** @@ -79,7 +79,7 @@ class MultiExecContext */ protected function flagState($flags) { - $this->_state |= $flags; + $this->state |= $flags; } /** @@ -89,7 +89,7 @@ class MultiExecContext */ protected function unflagState($flags) { - $this->_state &= ~$flags; + $this->state &= ~$flags; } /** @@ -100,7 +100,7 @@ class MultiExecContext */ protected function checkState($flags) { - return ($this->_state & $flags) === $flags; + return ($this->state & $flags) === $flags; } /** @@ -125,7 +125,7 @@ class MultiExecContext ); } - $this->_canWatch = $profile->supportsCommands(array('watch', 'unwatch')); + $this->canWatch = $profile->supportsCommands(array('watch', 'unwatch')); } /** @@ -133,7 +133,7 @@ class MultiExecContext */ private function isWatchSupported() { - if ($this->_canWatch === false) { + if ($this->canWatch === false) { throw new ClientException( 'The current profile does not support WATCH and UNWATCH' ); @@ -146,7 +146,7 @@ class MultiExecContext protected function reset() { $this->setState(self::STATE_RESET); - $this->_commands = array(); + $this->commands = array(); } /** @@ -158,7 +158,7 @@ class MultiExecContext return; } - $options = $this->_options; + $options = $this->options; if (isset($options['cas']) && $options['cas']) { $this->flagState(self::STATE_CAS); @@ -171,7 +171,7 @@ class MultiExecContext $discarded = $this->checkState(self::STATE_DISCARDED); if (!$cas || ($cas && $discarded)) { - $this->_client->multi(); + $this->client->multi(); if ($discarded) { $this->unflagState(self::STATE_CAS); } @@ -191,7 +191,7 @@ class MultiExecContext public function __call($method, $arguments) { $this->initialize(); - $client = $this->_client; + $client = $this->client; if ($this->checkState(self::STATE_CAS)) { return call_user_func_array(array($client, $method), $arguments); @@ -204,7 +204,7 @@ class MultiExecContext $this->onProtocolError('The server did not respond with a QUEUED status reply'); } - $this->_commands[] = $command; + $this->commands[] = $command; return $this; } @@ -223,7 +223,7 @@ class MultiExecContext throw new ClientException('WATCH after MULTI is not allowed'); } - $watchReply = $this->_client->watch($keys); + $watchReply = $this->client->watch($keys); $this->flagState(self::STATE_WATCH); return $watchReply; @@ -238,7 +238,7 @@ class MultiExecContext { if ($this->checkState(self::STATE_INITIALIZED | self::STATE_CAS)) { $this->unflagState(self::STATE_CAS); - $this->_client->multi(); + $this->client->multi(); } else { $this->initialize(); @@ -256,7 +256,7 @@ class MultiExecContext { $this->isWatchSupported(); $this->unflagState(self::STATE_WATCH); - $this->_client->unwatch(); + $this->client->unwatch(); return $this; } @@ -271,7 +271,7 @@ class MultiExecContext { if ($this->checkState(self::STATE_INITIALIZED)) { $command = $this->checkState(self::STATE_CAS) ? 'unwatch' : 'discard'; - $this->_client->$command(); + $this->client->$command(); $this->reset(); $this->flagState(self::STATE_DISCARDED); } @@ -309,7 +309,7 @@ class MultiExecContext ); } - if (count($this->_commands) > 0) { + if (count($this->commands) > 0) { $this->discard(); throw new ClientException( 'Cannot execute a transaction block after using fluent interface' @@ -317,7 +317,7 @@ class MultiExecContext } } - if (isset($this->_options['retry']) && !isset($callable)) { + if (isset($this->options['retry']) && !isset($callable)) { $this->discard(); throw new \InvalidArgumentException( 'Automatic retries can be used only when a transaction block is provided' @@ -337,21 +337,21 @@ class MultiExecContext $reply = null; $returnValues = array(); - $attemptsLeft = isset($this->_options['retry']) ? (int)$this->_options['retry'] : 0; + $attemptsLeft = isset($this->options['retry']) ? (int)$this->options['retry'] : 0; do { if ($callable !== null) { $this->executeTransactionBlock($callable); } - if (count($this->_commands) === 0) { + if (count($this->commands) === 0) { if ($this->checkState(self::STATE_WATCH)) { $this->discard(); } return; } - $reply = $this->_client->exec(); + $reply = $this->client->exec(); if ($reply === null) { if ($attemptsLeft === 0) { @@ -361,8 +361,8 @@ class MultiExecContext $this->reset(); - if (isset($this->_options['on_retry']) && is_callable($this->_options['on_retry'])) { - call_user_func($this->_options['on_retry'], $this, $attemptsLeft); + if (isset($this->options['on_retry']) && is_callable($this->options['on_retry'])) { + call_user_func($this->options['on_retry'], $this, $attemptsLeft); } continue; @@ -373,7 +373,7 @@ class MultiExecContext $execReply = $reply instanceof \Iterator ? iterator_to_array($reply) : $reply; $sizeofReplies = count($execReply); - $commands = $this->_commands; + $commands = $this->commands; if ($sizeofReplies !== count($commands)) { $this->onProtocolError("EXEC returned an unexpected number of replies"); @@ -435,7 +435,7 @@ class MultiExecContext // connection, we can safely assume that Predis\Client::getConnection() // will always return an instance of Predis\Network\IConnectionSingle. Helpers::onCommunicationException(new ProtocolException( - $this->_client->getConnection(), $message + $this->client->getConnection(), $message )); } } diff --git a/test/PredisShared.php b/test/PredisShared.php index ec5377eb..1647a788 100644 --- a/test/PredisShared.php +++ b/test/PredisShared.php @@ -44,7 +44,7 @@ class RC const EXCEPTION_BIT_VALUE = 'ERR bit is not an integer or out of range'; const EXCEPTION_BIT_OFFSET = 'ERR bit offset is not an integer or out of range'; - private static $_connection; + private static $connection; public static function getConnectionArguments(Array $additional = array()) { @@ -73,18 +73,18 @@ class RC return self::createConnection(); } - if (self::$_connection === null || !self::$_connection->isConnected()) { - self::$_connection = self::createConnection(); + if (self::$connection === null || !self::$connection->isConnected()) { + self::$connection = self::createConnection(); } - return self::$_connection; + return self::$connection; } public static function resetConnection() { - if (self::$_connection !== null && self::$_connection->isConnected()) { - self::$_connection->disconnect(); - self::$_connection = self::createConnection(); + if (self::$connection !== null && self::$connection->isConnected()) { + self::$connection->disconnect(); + self::$connection = self::createConnection(); } }