我们可以在Prepend Configuration中使用Doctrine吗?? ??
<?php
namespace Test\FrontBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Yaml\Parser;
use Lexik\Bundle\TranslationBundle\DependencyInjection\LexikTranslationExtension;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Doctrine\ORM\EntityManager;
class TestFrontExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
public function prepend(ContainerBuilder $container)
{
$processor = new Processor();
$configuration = new Configuration();
$extension = new LexikTranslationExtension();
$container->registerExtension($extension);
$container->loadFromExtension($extension->getAlias());
$configs = $container->getExtensionConfig($extension->getAlias());
$em = new EntityManager();
// $em = $container->get('doctrine.orm.default_entity_manager');
$language_params = $em->getRepository('AdminBundle:Language')->findAll();
$language_data = array();
foreach($language_params as $code)
{
$language_code = $code->getCode();
if(!empty($language_code)):
$lcode = strtolower($language_code);
$language_data[] = $lcode;
endif;
}
echo "<pre>";
print_r($language_data);
die();
$container->prependExtensionConfig('lexik_translation', $configss);
}
}
?>