JobCollection.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Mmoreramerino\GearmanBundle\Module;
  3. use Mmoreramerino\GearmanBundle\Module\JobClass as Job;
  4. /**
  5. * Job Collection class
  6. *
  7. * @author Marc Morera <marc@ulabox.com>
  8. */
  9. class JobCollection
  10. {
  11. /**
  12. * All jobs from worker
  13. *
  14. * @var array
  15. */
  16. private $workerJobs = array();
  17. /**
  18. * Adds into $workerJobs a Job instance
  19. * Return self object
  20. *
  21. * @param Job $workJob Class to add into array
  22. *
  23. * @return JobCollection
  24. */
  25. public function add(Job $workJob)
  26. {
  27. $this->workerJobs[] = $workJob;
  28. return $this;
  29. }
  30. /**
  31. * Retrieve all Jobs added previously
  32. *
  33. * @return array
  34. */
  35. public function getJobs()
  36. {
  37. return $this->workerJobs;
  38. }
  39. /**
  40. * Retrieve all jobs loaded previously in cache format
  41. *
  42. * @return array
  43. */
  44. public function __toCache()
  45. {
  46. $jobs = array();
  47. foreach ($this->getJobs() as $job) {
  48. $jobs[] = $job->__toCache();
  49. }
  50. return $jobs;
  51. }
  52. }