JobCollection.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Gearman Bundle for Symfony2
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * Feel free to edit as you please, and have fun.
  9. *
  10. * @author Marc Morera <yuhu@mmoreram.com>
  11. */
  12. namespace Mmoreram\GearmanBundle\Module;
  13. use Mmoreram\GearmanBundle\Module\JobClass as Job;
  14. /**
  15. * Job Collection class
  16. *
  17. * @since 2.3.1
  18. */
  19. class JobCollection
  20. {
  21. /**
  22. * @var array
  23. *
  24. * All jobs from worker
  25. */
  26. private $workerJobs = array();
  27. /**
  28. * Adds into $workerJobs a Job instance
  29. * Return self object
  30. *
  31. * @param Job $workJob Class to add into array
  32. *
  33. * @return JobCollection
  34. */
  35. public function add(Job $workJob)
  36. {
  37. $this->workerJobs[] = $workJob;
  38. return $this;
  39. }
  40. /**
  41. * Retrieve all Jobs added previously
  42. *
  43. * @return array
  44. */
  45. public function getJobs()
  46. {
  47. return $this->workerJobs;
  48. }
  49. /**
  50. * Retrieve all jobs loaded previously in cache format
  51. *
  52. * @return array
  53. */
  54. public function toArray()
  55. {
  56. $jobs = array();
  57. foreach ($this->workerJobs as $job) {
  58. $jobs[] = $job->toArray();
  59. }
  60. return $jobs;
  61. }
  62. }