<?php
namespace Eckinox\CoreBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Eckinox\CoreBundle\Cron\CronInterface;
class EckinoxCoreExtension extends Extension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container)
{
$configs = $this->processConfiguration($this->getConfiguration([], $container), $configs);
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../../config')
);
$loader->load('services.yaml');
if ($configs['crons']) {
trigger_deprecation('eckinox/core-bundle', '1.2', 'Using "%s" configuration is deprecated, use "%s" instead.', 'eckinox_core.crons ', CronInterface::class);
}
$container->setParameter('eckinox_core.crons', $configs['crons']);
$container->registerForAutoconfiguration(CronInterface::class)
->addTag('eckinox_core.cron')
;
}
public function prepend(ContainerBuilder $container): void
{
$bundleList = $container->getParameter('kernel.bundles');
// Set default privileges
if(array_key_exists('EckinoxSecurityBundle',$bundleList)) {
$container->prependExtensionConfig('eckinox_security', [
'privileges' => [
'log' => [ 'LIST', 'VIEW' ]
]
]);
}
// Add migrations path to Doctrine
$doctrineConfig = $container->getExtensionConfig('doctrine_migrations');
$migrationsPath = (array) array_pop($doctrineConfig)['migrations_paths'];
$container->prependExtensionConfig('doctrine_migrations', [
'migrations_paths' => array_merge(
$migrationsPath ?? [],
[
'EckinoxCoreMigrations' => '@EckinoxCoreBundle/migrations',
]
),
]);
$container->prependExtensionConfig('doctrine', [
'orm' => [
'mappings' => [
'EckinoxCoreBundle' => [
'type' => 'annotation',
'dir' => 'src/Entity',
'is_bundle' => true,
'prefix' => 'Eckinox\CoreBundle\Entity',
'alias' => 'EckinoxCoreBundle'
]
]
]
]);
}
}