JobCollection.php 1014 B

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