MmoreramerinoGearmanBundle.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Mmoreramerino\GearmanBundle;
  3. use Mmoreramerino\GearmanBundle\Service\GearmanCache;
  4. use Mmoreramerino\GearmanBundle\Module\GearmanBaseBundle;
  5. use Mmoreramerino\GearmanBundle\Service\GearmanCacheLoader;
  6. use Mmoreramerino\GearmanBundle\Exceptions\GearmanNotInstalledException;
  7. /**
  8. * Gearman Bundle
  9. *
  10. * @author Marc Morera <marc@ulabox.com>
  11. */
  12. class MmoreramerinoGearmanBundle extends GearmanBaseBundle
  13. {
  14. /**
  15. * Boots the Bundle.
  16. * This method load all data and saves all annotations into cache.
  17. * Also, it load all settings from Yaml file format
  18. *
  19. * @api
  20. */
  21. public function boot()
  22. {
  23. if (!in_array('gearman', get_loaded_extensions())) {
  24. throw new GearmanNotInstalledException;
  25. }
  26. $gearmanCache = $this->container->get('gearman.cache');
  27. $existsCache = $gearmanCache->existsCacheFile();
  28. $cacheclearEnvs = array(
  29. 'back_dev', 'back_test', 'dev', 'test',
  30. );
  31. if (in_array($this->container->get('kernel')->getEnvironment(), $cacheclearEnvs) || !$existsCache) {
  32. if ($existsCache) {
  33. $gearmanCache->emptyCache();
  34. }
  35. $gearmanCacheLoader = $this->container->get('gearman.cache.loader');
  36. $gearmanCacheLoader->load($gearmanCache);
  37. }
  38. }
  39. }