BatchTransferException.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Guzzle\Batch\Exception;
  3. use Guzzle\Common\Exception\GuzzleException;
  4. use Guzzle\Batch\BatchTransferInterface as TransferStrategy;
  5. use Guzzle\Batch\BatchDivisorInterface as DivisorStrategy;
  6. /**
  7. * Exception thrown during a batch transfer
  8. */
  9. class BatchTransferException extends \Exception implements GuzzleException
  10. {
  11. /** @var array The batch being sent when the exception occurred */
  12. protected $batch;
  13. /** @var TransferStrategy The transfer strategy in use when the exception occurred */
  14. protected $transferStrategy;
  15. /** @var DivisorStrategy The divisor strategy in use when the exception occurred */
  16. protected $divisorStrategy;
  17. /** @var array Items transferred at the point in which the exception was encountered */
  18. protected $transferredItems;
  19. /**
  20. * @param array $batch The batch being sent when the exception occurred
  21. * @param array $transferredItems Items transferred at the point in which the exception was encountered
  22. * @param \Exception $exception Exception encountered
  23. * @param TransferStrategy $transferStrategy The transfer strategy in use when the exception occurred
  24. * @param DivisorStrategy $divisorStrategy The divisor strategy in use when the exception occurred
  25. */
  26. public function __construct(
  27. array $batch,
  28. array $transferredItems,
  29. \Exception $exception,
  30. TransferStrategy $transferStrategy = null,
  31. DivisorStrategy $divisorStrategy = null
  32. ) {
  33. $this->batch = $batch;
  34. $this->transferredItems = $transferredItems;
  35. $this->transferStrategy = $transferStrategy;
  36. $this->divisorStrategy = $divisorStrategy;
  37. parent::__construct(
  38. 'Exception encountered while transferring batch: ' . $exception->getMessage(),
  39. $exception->getCode(),
  40. $exception
  41. );
  42. }
  43. /**
  44. * Get the batch that we being sent when the exception occurred
  45. *
  46. * @return array
  47. */
  48. public function getBatch()
  49. {
  50. return $this->batch;
  51. }
  52. /**
  53. * Get the items transferred at the point in which the exception was encountered
  54. *
  55. * @return array
  56. */
  57. public function getTransferredItems()
  58. {
  59. return $this->transferredItems;
  60. }
  61. /**
  62. * Get the transfer strategy
  63. *
  64. * @return TransferStrategy
  65. */
  66. public function getTransferStrategy()
  67. {
  68. return $this->transferStrategy;
  69. }
  70. /**
  71. * Get the divisor strategy
  72. *
  73. * @return DivisorStrategy
  74. */
  75. public function getDivisorStrategy()
  76. {
  77. return $this->divisorStrategy;
  78. }
  79. }