PreprocessorChain.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Predis\Commands\Preprocessors;
  3. class PreprocessorChain implements ICommandPreprocessorChain, \ArrayAccess {
  4. private $_preprocessors;
  5. public function __construct($preprocessors = array()) {
  6. foreach ($preprocessors as $preprocessor) {
  7. $this->add($preprocessor);
  8. }
  9. }
  10. public function add(ICommandPreprocessor $preprocessor) {
  11. $this->_preprocessors[] = $preprocessor;
  12. }
  13. public function remove(ICommandPreprocessor $preprocessor) {
  14. // TODO: find index of value
  15. }
  16. public function process(&$method, &$arguments) {
  17. $count = count($this->_preprocessors);
  18. for ($i = 0; $i < $count; $i++) {
  19. $this->_preprocessors[$i]->process($method, $arguments);
  20. }
  21. }
  22. public function getPreprocessors() {
  23. return $this->_preprocessors;
  24. }
  25. public function getIterator() {
  26. return new \ArrayIterator($this->_preprocessors);
  27. }
  28. public function count() {
  29. return count($this->_preprocessors);
  30. }
  31. public function offsetExists($index) {
  32. return isset($this->_preprocessors[$index]);
  33. }
  34. public function offsetGet($index) {
  35. return $this->_preprocessors[$index];
  36. }
  37. public function offsetSet($index, $preprocessor) {
  38. $this->_preprocessors[$index] = $preprocessor;
  39. }
  40. public function offsetUnset($index) {
  41. unset($this->_preprocessors[$index]);
  42. }
  43. }