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