WorkerCollection.php 965 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Mmoreramerino\GearmanBundle\Module;
  3. use Mmoreramerino\GearmanBundle\Module\WorkerClass as Worker;
  4. /**
  5. * WorkerCollection class
  6. *
  7. * @author Marc Morera <marc@ulabox.com>
  8. */
  9. class WorkerCollection
  10. {
  11. /**
  12. * All Workers
  13. *
  14. * @var array
  15. */
  16. private $workerClasses = array();
  17. /**
  18. * Adds a Worker into $workerClasses
  19. * Return self object
  20. *
  21. * @param Worker $workerClass Worker element to add
  22. *
  23. * @return WorkerCollection
  24. */
  25. public function add(Worker $workerClass)
  26. {
  27. $this->workerClasses[] = $workerClass;
  28. return $this;
  29. }
  30. /**
  31. * Retrieve all workers loaded previously in cache format
  32. *
  33. * @return array
  34. */
  35. public function __toCache()
  36. {
  37. $workersDumped = array();
  38. foreach ($this->workerClasses as $worker) {
  39. $workersDumped[] = $worker->__toCache();
  40. }
  41. return $workersDumped;
  42. }
  43. }