mirror of
https://github.com/predis/predis.git
synced 2026-08-18 15:41:58 +00:00
Implement a class to chain multiple command preprocessors.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Preprocessors;
|
||||
|
||||
interface ICommandPreprocessorChain
|
||||
extends ICommandPreprocessor, \IteratorAggregate, \Countable {
|
||||
|
||||
public function add(ICommandPreprocessor $preprocessor);
|
||||
public function remove(ICommandPreprocessor $preprocessor);
|
||||
public function getPreprocessors();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Preprocessors;
|
||||
|
||||
class PreprocessorChain implements ICommandPreprocessorChain, \ArrayAccess {
|
||||
private $_preprocessors;
|
||||
|
||||
public function __construct($preprocessors = array()) {
|
||||
foreach ($preprocessors as $preprocessor) {
|
||||
$this->add($preprocessor);
|
||||
}
|
||||
}
|
||||
|
||||
public function add(ICommandPreprocessor $preprocessor) {
|
||||
$this->_preprocessors[] = $preprocessor;
|
||||
}
|
||||
|
||||
public function remove(ICommandPreprocessor $preprocessor) {
|
||||
// TODO: find index of value
|
||||
}
|
||||
|
||||
public function process(&$method, &$arguments) {
|
||||
$count = count($this->_preprocessors);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->_preprocessors[$i]->process($method, $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPreprocessors() {
|
||||
return $this->_preprocessors;
|
||||
}
|
||||
|
||||
public function getIterator() {
|
||||
return new \ArrayIterator($this->_preprocessors);
|
||||
}
|
||||
|
||||
public function count() {
|
||||
return count($this->_preprocessors);
|
||||
}
|
||||
|
||||
public function offsetExists($index) {
|
||||
return isset($this->_preprocessors[$index]);
|
||||
}
|
||||
|
||||
public function offsetGet($index) {
|
||||
return $this->_preprocessors[$index];
|
||||
}
|
||||
|
||||
public function offsetSet($index, $preprocessor) {
|
||||
$this->_preprocessors[$index] = $preprocessor;
|
||||
}
|
||||
|
||||
public function offsetUnset($index) {
|
||||
unset($this->_preprocessors[$index]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user