GearmanBaseBundle.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, previously loaded by method load()
  27. * If settings are not loaded, a SettingsNotLoadedException Exception is thrown
  28. *
  29. * @return array Settings getted from gearmanSettings service
  30. */
  31. public function getSettings()
  32. {
  33. $this->settings = $this->container->get('gearman.settings')->getSettings();
  34. return $this->settings;
  35. }
  36. /**
  37. * Get yaml file and load all settings for Gearman engine
  38. *
  39. * @param type $settingsPath Resource path to get settings
  40. * @return array Settings
  41. */
  42. public function loadSettings($settingsPath)
  43. {
  44. $this->settings = $this->container->get('gearman.settings')->loadSettings($settingsPath);
  45. return $this->settings;
  46. }
  47. /**
  48. * Return Gearman bundle settings, previously loaded by method load()
  49. * If settings are not loaded, a SettingsNotLoadedException Exception is thrown
  50. *
  51. * @return array Bundles that gearman will be able to search annotations
  52. */
  53. public function getParseableBundles()
  54. {
  55. if (null === $this->settings) {
  56. throw new SettingsNotLoadedException();
  57. }
  58. if (null === $this->bundles) {
  59. $this->bundles = array();
  60. foreach ($this->settings['bundles'] as $properties) {
  61. if ( isset($properties['active']) && (true === $properties['active']) ) {
  62. if('' !== $properties['namespace']) {
  63. $this->bundles[] = $properties['namespace'];
  64. }
  65. }
  66. }
  67. }
  68. return $this->bundles;
  69. }
  70. /**
  71. * Shutdowns the Bundle.
  72. *
  73. * @api
  74. */
  75. function shutdown(){}
  76. /**
  77. * Builds the bundle.
  78. *
  79. * It is only ever called once when the cache is empty.
  80. *
  81. * @param ContainerBuilder $container A ContainerBuilder instance
  82. *
  83. * @api
  84. */
  85. function build(ContainerBuilder $container){}
  86. }