JobCollection.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Mmoreram\GearmanBundle\Module;
  3. use Mmoreram\GearmanBundle\Module\JobClass as Job;
  4. /**
  5. * Job Collection class
  6. *
  7. * @author Marc Morera <yuhu@mmoreram.com>
  8. */
  9. class JobCollection
  10. {
  11. /**
  12. * @var array
  13. *
  14. * All jobs from worker
  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 toArray()
  45. {
  46. $jobs = array();
  47. foreach ($this->workerJobs as $job) {
  48. $jobs[] = $job->toArray();
  49. }
  50. return $jobs;
  51. }
  52. }