vendor/lexik/translation-bundle/EventDispatcher/GetDatabaseResourcesListener.php line 38

Open in your IDE?
  1. <?php
  2. namespace Lexik\Bundle\TranslationBundle\EventDispatcher;
  3. use Lexik\Bundle\TranslationBundle\EventDispatcher\Event\GetDatabaseResourcesEvent;
  4. use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
  5. /**
  6.  * @author Cédric Girard <c.girard@lexik.fr>
  7.  */
  8. class GetDatabaseResourcesListener
  9. {
  10.     /**
  11.      * @var \Lexik\Bundle\TranslationBundle\Storage\StorageInterface
  12.      */
  13.     private $storage;
  14.     /**
  15.      * @var string
  16.      */
  17.     private $storageType;
  18.     /**
  19.      * @param StorageInterface $storage
  20.      * @param $storageType
  21.      */
  22.     public function __construct(StorageInterface $storage$storageType)
  23.     {
  24.         $this->storage $storage;
  25.         $this->storageType $storageType;
  26.     }
  27.     /**
  28.      * Query the database to get translation resources and set it on the event.
  29.      *
  30.      * @param GetDatabaseResourcesEvent $event
  31.      */
  32.     public function onGetDatabaseResources(GetDatabaseResourcesEvent $event)
  33.     {
  34.         // prevent errors on command such as cache:clear if doctrine schema has not been updated yet
  35.         if (StorageInterface::STORAGE_ORM == $this->storageType && !$this->storage->translationsTablesExist()) {
  36.             $resources = array();
  37.         } else {
  38.             $resources $this->storage->getTransUnitDomainsByLocale();
  39.         }
  40.         $event->setResources($resources);
  41.     }
  42. }