ExceptionBufferingBatch.php 1.2 KB

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