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

  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.     private StorageInterface $storage;
  11.     private string $storageType;
  12.     public function __construct(StorageInterface $storagestring $storageType)
  13.     {
  14.         $this->storage $storage;
  15.         $this->storageType $storageType;
  16.     }
  17.     /**
  18.      * Query the database to get translation resources and set it on the event.
  19.      *
  20.      * @param GetDatabaseResourcesEvent $event
  21.      */
  22.     public function onGetDatabaseResources(GetDatabaseResourcesEvent $event)
  23.     {
  24.         // prevent errors on command such as cache:clear if doctrine schema has not been updated yet
  25.         if (StorageInterface::STORAGE_ORM == $this->storageType && !$this->storage->translationsTablesExist()) {
  26.             $resources = array();
  27.         } else {
  28.             $resources $this->storage->getTransUnitDomainsByLocale();
  29.         }
  30.         $event->setResources($resources);
  31.     }
  32. }