AbstractBatchDecorator.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Guzzle\Batch;
  3. /**
  4. * Abstract decorator used when decorating a BatchInterface
  5. */
  6. abstract class AbstractBatchDecorator implements BatchInterface
  7. {
  8. /** @var BatchInterface Decorated batch object */
  9. protected $decoratedBatch;
  10. /**
  11. * @param BatchInterface $decoratedBatch BatchInterface that is being decorated
  12. */
  13. public function __construct(BatchInterface $decoratedBatch)
  14. {
  15. $this->decoratedBatch = $decoratedBatch;
  16. }
  17. /**
  18. * Allow decorators to implement custom methods
  19. *
  20. * @param string $method Missing method name
  21. * @param array $args Method arguments
  22. *
  23. * @return mixed
  24. * @codeCoverageIgnore
  25. */
  26. public function __call($method, array $args)
  27. {
  28. return call_user_func_array(array($this->decoratedBatch, $method), $args);
  29. }
  30. public function add($item)
  31. {
  32. $this->decoratedBatch->add($item);
  33. return $this;
  34. }
  35. public function flush()
  36. {
  37. return $this->decoratedBatch->flush();
  38. }
  39. public function isEmpty()
  40. {
  41. return $this->decoratedBatch->isEmpty();
  42. }
  43. /**
  44. * Trace the decorators associated with the batch
  45. *
  46. * @return array
  47. */
  48. public function getDecorators()
  49. {
  50. $found = array($this);
  51. if (method_exists($this->decoratedBatch, 'getDecorators')) {
  52. $found = array_merge($found, $this->decoratedBatch->getDecorators());
  53. }
  54. return $found;
  55. }
  56. }