GearmanBaseBundle.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Mmoreramerino\GearmanBundle\Module;
  3. use Symfony\Component\HttpKernel\Bundle\Bundle;
  4. use Mmoreramerino\GearmanBundle\Sevices\GearmanSettings;
  5. use Symfony\Component\DependencyInjection\ContainerBuilder;
  6. /**
  7. * Gearman Base Bundle
  8. *
  9. * @author Marc Morera <marc@ulabox.com>
  10. */
  11. class GearmanBaseBundle extends Bundle
  12. {
  13. /**
  14. * Settings defined into settings file
  15. *
  16. * @var Array
  17. */
  18. private $settings = null;
  19. /**
  20. * Bundles available to perform search setted in bundles.yml file
  21. *
  22. * @var Array
  23. */
  24. private $bundles = null;
  25. /**
  26. * Return Gearman settings
  27. *
  28. * @return array Settings getted from gearmanSettings service
  29. */
  30. public function getSettings()
  31. {
  32. return $this->loadSettings();
  33. }
  34. /**
  35. * Get yaml file and load all settings for Gearman engine
  36. *
  37. * @return array Settings
  38. */
  39. public function loadSettings()
  40. {
  41. $this->settings = $this->container->get('gearman.settings')->loadSettings();
  42. return $this->settings;
  43. }
  44. /**
  45. * Return Gearman bundle settings, previously loaded by method load()
  46. * If settings are not loaded, a SettingsNotLoadedException Exception is thrown
  47. *
  48. * @return array Bundles that gearman will be able to search annotations
  49. */
  50. public function getParseableBundles()
  51. {
  52. if (null === $this->settings) {
  53. $this->loadSettings();
  54. }
  55. if (null === $this->bundles) {
  56. $this->bundles = array();
  57. foreach ($this->settings['bundles'] as $properties) {
  58. if ( isset($properties['active']) && (true === $properties['active']) ) {
  59. if ('' !== $properties['namespace']) {
  60. $this->bundles[] = $properties['namespace'];
  61. }
  62. }
  63. }
  64. }
  65. return $this->bundles;
  66. }
  67. /**
  68. * Shutdowns the Bundle.
  69. *
  70. * @api
  71. */
  72. public function shutdown()
  73. {
  74. }
  75. /**
  76. * Builds the bundle.
  77. *
  78. * It is only ever called once when the cache is empty.
  79. *
  80. * @param ContainerBuilder $container A ContainerBuilder instance
  81. *
  82. * @api
  83. */
  84. public function build(ContainerBuilder $container)
  85. {
  86. }
  87. }