Sha256: a01bc12bc418695b65183394982b19e08f81733e80a625a6927fc6223b689f1c

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

<?php

namespace Predis\Commands\Processors;

use Predis\Commands\ICommand;

class ProcessorChain implements ICommandProcessorChain, \ArrayAccess {
    private $_processors;

    public function __construct($processors = array()) {
        foreach ($processors as $processor) {
            $this->add($processor);
        }
    }

    public function add(ICommandProcessor $processor) {
        $this->_processors[] = $processor;
    }

    public function remove(ICommandProcessor $processor) {
        $index = array_search($processor, $this->_processors, true);
        if ($index !== false) {
            unset($this->_processors);
        }
    }

    public function process(ICommand $command) {
        $count = count($this->_processors);
        for ($i = 0; $i < $count; $i++) {
            $this->_processors[$i]->process($command);
        }
    }

    public function getProcessors() {
        return $this->_processors;
    }

    public function getIterator() {
        return new \ArrayIterator($this->_processors);
    }

    public function count() {
        return count($this->_processors);
    }

    public function offsetExists($index) {
        return isset($this->_processors[$index]);
    }

    public function offsetGet($index) {
        return $this->_processors[$index];
    }

    public function offsetSet($index, $processor) {
        if (!$processor instanceof ICommandProcessor) {
            throw new \InvalidArgumentException(
                'A processor chain can hold only instances of classes implementing '.
                'the Predis\Commands\Preprocessors\ICommandProcessor interface'
            );
        }
        $this->_processors[$index] = $processor;
    }

    public function offsetUnset($index) {
        unset($this->_processors[$index]);
    }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
appstats-0.25.1 doc/benchmarks/Predis/Commands/Processors/ProcessorChain.php
appstats-0.25.0 doc/benchmarks/Predis/Commands/Processors/ProcessorChain.php
appstats-0.24.0 doc/benchmarks/Predis/Commands/Processors/ProcessorChain.php
appstats-0.23.5 doc/benchmarks/Predis/Commands/Processors/ProcessorChain.php
appstats-0.23.4 doc/benchmarks/Predis/Commands/Processors/ProcessorChain.php
appstats-0.23.3 doc/benchmarks/Predis/Commands/Processors/ProcessorChain.php
appstats-0.23.2 doc/benchmarks/Predis/Commands/Processors/ProcessorChain.php