WorkerCollection.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\WorkerClass as Worker;
  14. /**
  15. * WorkerCollection class
  16. *
  17. * @since 2.3.1
  18. */
  19. class WorkerCollection
  20. {
  21. /**
  22. * All Workers
  23. *
  24. * @var array
  25. */
  26. private $workerClasses = array();
  27. /**
  28. * Adds a Worker into $workerClasses
  29. * Return self object
  30. *
  31. * @param Worker $workerClass Worker element to add
  32. *
  33. * @return WorkerCollection
  34. */
  35. public function add(Worker $workerClass)
  36. {
  37. $this->workerClasses[] = $workerClass;
  38. return $this;
  39. }
  40. /**
  41. * Retrieve all workers loaded previously in cache format
  42. *
  43. * @return array
  44. */
  45. public function toArray()
  46. {
  47. $workersDumped = array();
  48. foreach ($this->workerClasses as $worker) {
  49. $workersDumped[] = $worker->toArray();
  50. }
  51. return $workersDumped;
  52. }
  53. }