mirror of
https://github.com/predis/predis.git
synced 2026-08-24 16:09:33 +00:00
dc14c29676
Now we follow a Symfony2-like naming convention for namespaces, interfaces and classes sticking with one clear rule. - Renamed namespaces: - Predis\Network - Predis\Profiles - Predis\Iterators - Predis\Options - Predis\Commands - Predis\Commands\Processors - Renamed interfaces: - Predis\IReplyObject - Predis\IRedisServerError - Predis\IConnectionFactory - Predis\IConnectionParameters - Predis\Options\IOption - Predis\Options\IClientOptions - Predis\Profile\IServerProfile - Predis\Pipeline\IPipelineExecutor - Predis\Distribution\INodeKeyGenerator - Predis\Distribution\IDistributionStrategy - Predis\Protocol\IProtocolProcessor - Predis\Protocol\IResponseReader - Predis\Protocol\IResponseHandler - Predis\Protocol\ICommandSerializer - Predis\Protocol\IComposableProtocolProcessor - Predis\Network\IConnection - Predis\Network\IConnectionSingle - Predis\Network\IConnectionComposable - Predis\Network\IConnectionCluster - Predis\Network\IConnectionReplication - Predis\Commands\ICommand - Predis\Commands\IPrefixable - Predis\Command\Processor\ICommandProcessor - Predis\Command\Processor\ICommandProcessorChain - Predis\Command\Processor\IProcessingSupport - Renamed Classes: - Predis\Commands\Command - Predis\Network\ConnectionBase - Classes moved to different namespaces: - Predis\MonitorContext Meh
133 lines
2.9 KiB
PHP
133 lines
2.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Predis package.
|
|
*
|
|
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Predis\Command\Processor;
|
|
|
|
use Predis\Command\CommandInterface;
|
|
|
|
/**
|
|
* Default implementation of a command processors chain.
|
|
*
|
|
* @author Daniele Alessandri <suppakilla@gmail.com>
|
|
*/
|
|
class ProcessorChain implements CommandProcessorChainInterface, \ArrayAccess
|
|
{
|
|
private $processors = array();
|
|
|
|
/**
|
|
* @param array $processors List of instances of CommandProcessorInterface.
|
|
*/
|
|
public function __construct($processors = array())
|
|
{
|
|
foreach ($processors as $processor) {
|
|
$this->add($processor);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function add(CommandProcessorInterface $processor)
|
|
{
|
|
$this->processors[] = $processor;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function remove(CommandProcessorInterface $processor)
|
|
{
|
|
$index = array_search($processor, $this->processors, true);
|
|
if ($index !== false) {
|
|
unset($this[$index]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function process(CommandInterface $command)
|
|
{
|
|
$count = count($this->processors);
|
|
for ($i = 0; $i < $count; $i++) {
|
|
$this->processors[$i]->process($command);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getProcessors()
|
|
{
|
|
return $this->processors;
|
|
}
|
|
|
|
/**
|
|
* Returns an iterator over the list of command processor in the chain.
|
|
*
|
|
* @return \ArrayIterator
|
|
*/
|
|
public function getIterator()
|
|
{
|
|
return new \ArrayIterator($this->processors);
|
|
}
|
|
|
|
/**
|
|
* Returns the number of command processors in the chain.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function count()
|
|
{
|
|
return count($this->processors);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function offsetExists($index)
|
|
{
|
|
return isset($this->processors[$index]);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function offsetGet($index)
|
|
{
|
|
return $this->processors[$index];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function offsetSet($index, $processor)
|
|
{
|
|
if (!$processor instanceof CommandProcessorInterface) {
|
|
throw new \InvalidArgumentException(
|
|
'A processor chain can hold only instances of classes implementing '.
|
|
'the Predis\Command\Processor\CommandProcessorInterface interface'
|
|
);
|
|
}
|
|
|
|
$this->processors[$index] = $processor;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function offsetUnset($index)
|
|
{
|
|
unset($this->processors[$index]);
|
|
$this->processors = array_values($this->processors);
|
|
}
|
|
}
|