NotifyingBatch.php 957 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Guzzle\Batch;
  3. use Guzzle\Common\Exception\InvalidArgumentException;
  4. /**
  5. * BatchInterface decorator used to call a method each time flush is called
  6. */
  7. class NotifyingBatch extends AbstractBatchDecorator
  8. {
  9. /** @var mixed Callable to call */
  10. protected $callable;
  11. /**
  12. * @param BatchInterface $decoratedBatch Batch object to decorate
  13. * @param mixed $callable Callable to call
  14. *
  15. * @throws InvalidArgumentException
  16. */
  17. public function __construct(BatchInterface $decoratedBatch, $callable)
  18. {
  19. if (!is_callable($callable)) {
  20. throw new InvalidArgumentException('The passed argument is not callable');
  21. }
  22. $this->callable = $callable;
  23. parent::__construct($decoratedBatch);
  24. }
  25. public function flush()
  26. {
  27. $items = $this->decoratedBatch->flush();
  28. call_user_func($this->callable, $items);
  29. return $items;
  30. }
  31. }