<?php
/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/
namespace Pimcore\TranslationsProviderInterfaceBundle;
use Pimcore\Bundle\EnterpriseSubscriptionToolsBundle\Bundle\EnterpriseBundleInterface;
use Pimcore\Bundle\EnterpriseSubscriptionToolsBundle\PimcoreEnterpriseSubscriptionToolsBundle;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;
use Pimcore\HttpKernel\Bundle\DependentBundleInterface;
use Pimcore\HttpKernel\BundleCollection\BundleCollection;
use Pimcore\TranslationsProviderInterfaceBundle\DataChangedHandler\DataChangedHandlerInterface;
use Pimcore\TranslationsProviderInterfaceBundle\DependencyInjection\Compiler\ContentSecurityPolicyUrlsPass;
use Pimcore\TranslationsProviderInterfaceBundle\DependencyInjection\Compiler\DataChangedHandlerPass;
use Pimcore\TranslationsProviderInterfaceBundle\DependencyInjection\Compiler\TranslationsProviderPass;
use Pimcore\TranslationsProviderInterfaceBundle\TranslationsProvider\TranslationsProviderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class PimcoreTranslationsProviderInterfaceBundle extends AbstractPimcoreBundle implements EnterpriseBundleInterface, DependentBundleInterface
{
use PackageVersionTrait;
const PERMISSION_KEY_JOB_LIST = 'translations_job_list';
const PERMISSION_KEY_JOB_CREATION = 'translations_job_creation';
const PERMISSION_KEY_CONFIGURATION = 'translations_job_config';
const PERMISSIONS = [
self::PERMISSION_KEY_JOB_LIST,
self::PERMISSION_KEY_JOB_CREATION,
self::PERMISSION_KEY_CONFIGURATION
];
protected function getComposerPackageName(): string
{
return 'pimcore/translations-provider-interfaces';
}
/**
* @inheritDoc
*/
public function build(ContainerBuilder $container)
{
$container
->registerForAutoconfiguration(TranslationsProviderInterface::class)
->addTag('translations-provider-interface-bundle.translations-provider');
$container->addCompilerPass(new TranslationsProviderPass());
$container
->registerForAutoconfiguration(DataChangedHandlerInterface::class)
->addTag('translations-provider-interface-bundle.data-changed-handler');
$container->addCompilerPass(new DataChangedHandlerPass());
$container->addCompilerPass(new ContentSecurityPolicyUrlsPass());
}
/**
* @return string[]
*/
public function getJsPaths()
{
return [
'/bundles/pimcoretranslationsproviderinterface/js/ext_extensions.js',
'/bundles/pimcoretranslationsproviderinterface/js/pimcore/startup.js',
'/bundles/pimcoretranslationsproviderinterface/js/pimcore/configPanel.js',
'/bundles/pimcoretranslationsproviderinterface/js/pimcore/translationsettings.js'
];
}
/**
* @return string[]
*/
public function getCssPaths()
{
return [
'/bundles/pimcoretranslationsproviderinterface/css/admin.css',
];
}
/**
* @return string
*/
public static function getErrorSimulationFile()
{
return PIMCORE_PRIVATE_VAR . '/config/translation-error-simulation.php';
}
/**
* @param bool|int $enabled
*/
public static function setErrorSimulation($enabled)
{
$file = self::getErrorSimulationFile();
if ($enabled) {
file_put_contents($file, 'Simulated communication error');
} else {
@unlink($file);
}
}
/**
* @return false|string|void
*/
public static function getSimulatedError()
{
$file = self::getErrorSimulationFile();
if (file_exists($file)) {
return file_get_contents($file);
}
}
public function getBundleLicenseId(): string
{
return 'TPI';
}
/**
* Register bundles to collection.
*
* WARNING: this method will be called as soon as this bundle is added to the collection, independent if
* it will finally be included due to environment restrictions. If you need to load your dependencies conditionally,
* specify the environments to use on the collection item.
*/
public static function registerDependentBundles(BundleCollection $collection)
{
$collection->addBundle(new PimcoreEnterpriseSubscriptionToolsBundle());
}
/**
* @return Installer
*/
public function getInstaller()
{
return $this->container->get(Installer::class);
}
}