JobCollection.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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
  22. * @return JobCollection
  23. */
  24. public function add(Job $workJob)
  25. {
  26. $this->workerJobs[] = $workJob;
  27. return $this;
  28. }
  29. /**
  30. * Retrieve all Jobs added previously
  31. *
  32. * @return array
  33. */
  34. public function getJobs()
  35. {
  36. return $this->workerJobs;
  37. }
  38. /**
  39. * Retrieve all jobs loaded previously in cache format
  40. *
  41. * @return array
  42. */
  43. public function __toCache()
  44. {
  45. $jobs = array();
  46. foreach ($this->getJobs() as $job) {
  47. $jobs[] = $job->__toCache();
  48. }
  49. return $jobs;
  50. }
  51. }