1: <?php
2:
3: namespace Guzzle\Batch;
4:
5: use Guzzle\Batch\Exception\BatchTransferException;
6:
7: /**
8: * BatchInterface decorator used to buffer exceptions encountered during a transfer. The exceptions can then later be
9: * processed after a batch flush has completed.
10: */
11: class ExceptionBufferingBatch extends AbstractBatchDecorator
12: {
13: /**
14: * @var array Array of BatchTransferException exceptions
15: */
16: protected $exceptions = array();
17:
18: /**
19: * {@inheritdoc}
20: */
21: public function flush()
22: {
23: $items = array();
24:
25: while (!$this->decoratedBatch->isEmpty()) {
26: try {
27: $transferredItems = $this->decoratedBatch->flush();
28: } catch (BatchTransferException $e) {
29: $this->exceptions[] = $e;
30: $transferredItems = $e->getTransferredItems();
31: }
32: $items = array_merge($items, $transferredItems);
33: }
34:
35: return $items;
36: }
37:
38: /**
39: * Get the buffered exceptions
40: *
41: * @return array Array of BatchTransferException objects
42: */
43: public function getExceptions()
44: {
45: return $this->exceptions;
46: }
47:
48: /**
49: * Clear the buffered exceptions
50: */
51: public function clearExceptions()
52: {
53: $this->exceptions = array();
54: }
55: }
56: