vendor/pimcore/translations-provider-interfaces/src/PimcoreTranslationsProviderInterfaceBundle.php line 28

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\TranslationsProviderInterfaceBundle;
  12. use Pimcore\Bundle\EnterpriseSubscriptionToolsBundle\Bundle\EnterpriseBundleInterface;
  13. use Pimcore\Bundle\EnterpriseSubscriptionToolsBundle\PimcoreEnterpriseSubscriptionToolsBundle;
  14. use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
  15. use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;
  16. use Pimcore\HttpKernel\Bundle\DependentBundleInterface;
  17. use Pimcore\HttpKernel\BundleCollection\BundleCollection;
  18. use Pimcore\TranslationsProviderInterfaceBundle\DataChangedHandler\DataChangedHandlerInterface;
  19. use Pimcore\TranslationsProviderInterfaceBundle\DependencyInjection\Compiler\ContentSecurityPolicyUrlsPass;
  20. use Pimcore\TranslationsProviderInterfaceBundle\DependencyInjection\Compiler\DataChangedHandlerPass;
  21. use Pimcore\TranslationsProviderInterfaceBundle\DependencyInjection\Compiler\TranslationsProviderPass;
  22. use Pimcore\TranslationsProviderInterfaceBundle\TranslationsProvider\TranslationsProviderInterface;
  23. use Symfony\Component\DependencyInjection\ContainerBuilder;
  24. class PimcoreTranslationsProviderInterfaceBundle extends AbstractPimcoreBundle implements EnterpriseBundleInterfaceDependentBundleInterface
  25. {
  26.     use PackageVersionTrait;
  27.     const PERMISSION_KEY_JOB_LIST 'translations_job_list';
  28.     const PERMISSION_KEY_JOB_CREATION 'translations_job_creation';
  29.     const PERMISSION_KEY_CONFIGURATION 'translations_job_config';
  30.     const PERMISSIONS = [
  31.         self::PERMISSION_KEY_JOB_LIST,
  32.         self::PERMISSION_KEY_JOB_CREATION,
  33.         self::PERMISSION_KEY_CONFIGURATION
  34.     ];
  35.     protected function getComposerPackageName(): string
  36.     {
  37.         return 'pimcore/translations-provider-interfaces';
  38.     }
  39.     /**
  40.      * @inheritDoc
  41.      */
  42.     public function build(ContainerBuilder $container)
  43.     {
  44.         $container
  45.             ->registerForAutoconfiguration(TranslationsProviderInterface::class)
  46.             ->addTag('translations-provider-interface-bundle.translations-provider');
  47.         $container->addCompilerPass(new TranslationsProviderPass());
  48.         $container
  49.             ->registerForAutoconfiguration(DataChangedHandlerInterface::class)
  50.             ->addTag('translations-provider-interface-bundle.data-changed-handler');
  51.         $container->addCompilerPass(new DataChangedHandlerPass());
  52.         $container->addCompilerPass(new ContentSecurityPolicyUrlsPass());
  53.     }
  54.     /**
  55.      * @return string[]
  56.      */
  57.     public function getJsPaths()
  58.     {
  59.         return [
  60.             '/bundles/pimcoretranslationsproviderinterface/js/ext_extensions.js',
  61.             '/bundles/pimcoretranslationsproviderinterface/js/pimcore/startup.js',
  62.             '/bundles/pimcoretranslationsproviderinterface/js/pimcore/configPanel.js',
  63.             '/bundles/pimcoretranslationsproviderinterface/js/pimcore/translationsettings.js'
  64.         ];
  65.     }
  66.     /**
  67.      * @return string[]
  68.      */
  69.     public function getCssPaths()
  70.     {
  71.         return [
  72.             '/bundles/pimcoretranslationsproviderinterface/css/admin.css',
  73.         ];
  74.     }
  75.     /**
  76.      * @return string
  77.      */
  78.     public static function getErrorSimulationFile()
  79.     {
  80.         return PIMCORE_PRIVATE_VAR '/config/translation-error-simulation.php';
  81.     }
  82.     /**
  83.      * @param bool|int $enabled
  84.      */
  85.     public static function setErrorSimulation($enabled)
  86.     {
  87.         $file self::getErrorSimulationFile();
  88.         if ($enabled) {
  89.             file_put_contents($file'Simulated communication error');
  90.         } else {
  91.             @unlink($file);
  92.         }
  93.     }
  94.     /**
  95.      * @return false|string|void
  96.      */
  97.     public static function getSimulatedError()
  98.     {
  99.         $file self::getErrorSimulationFile();
  100.         if (file_exists($file)) {
  101.             return file_get_contents($file);
  102.         }
  103.     }
  104.     public function getBundleLicenseId(): string
  105.     {
  106.         return 'TPI';
  107.     }
  108.     /**
  109.      * Register bundles to collection.
  110.      *
  111.      * WARNING: this method will be called as soon as this bundle is added to the collection, independent if
  112.      * it will finally be included due to environment restrictions. If you need to load your dependencies conditionally,
  113.      * specify the environments to use on the collection item.
  114.      */
  115.     public static function registerDependentBundles(BundleCollection $collection)
  116.     {
  117.         $collection->addBundle(new PimcoreEnterpriseSubscriptionToolsBundle());
  118.     }
  119.     /**
  120.      * @return Installer
  121.      */
  122.     public function getInstaller()
  123.     {
  124.         return $this->container->get(Installer::class);
  125.     }
  126. }