Navigation Menu

Skip to content

Commit

Permalink
[DoctrineBundle] removed DoctrineExtension constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 10, 2010
1 parent ac8e1e2 commit 0f30e53
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 58 deletions.
Expand Up @@ -30,16 +30,6 @@ class DoctrineExtension extends Extension
'dbal' => 'dbal.xml',
'orm' => 'orm.xml',
);
protected $bundleDirs;
protected $bundles;
protected $kernelCacheDir;

public function __construct(array $bundleDirs, array $bundles, $kernelCacheDir)
{
$this->bundleDirs = $bundleDirs;
$this->bundles = $bundles;
$this->kernelCacheDir = $kernelCacheDir;
}

/**
* Loads the DBAL configuration.
Expand Down Expand Up @@ -69,7 +59,7 @@ public function dbalLoad($config, ContainerBuilder $container)
*/
public function ormLoad($config, ContainerBuilder $container)
{
$this->createOrmProxyDirectory();
$this->createOrmProxyDirectory($container->getParameter('kernel.cache_dir'));
$this->loadOrmDefaults($config, $container);
$this->loadOrmEntityManagers($config, $container);
}
Expand Down Expand Up @@ -196,10 +186,10 @@ protected function getDbalConnections(array $config, ContainerBuilder $container
/**
* Create the Doctrine ORM Entity proxy directory
*/
protected function createOrmProxyDirectory()
protected function createOrmProxyDirectory($tmpDir)
{
// Create entity proxy directory
$proxyCacheDir = $this->kernelCacheDir . '/doctrine/orm/Proxies';
$proxyCacheDir = $tmpDir.'/doctrine/orm/Proxies';
if (!is_dir($proxyCacheDir)) {
if (false === @mkdir($proxyCacheDir, 0777, true)) {
die(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir)));
Expand Down Expand Up @@ -265,7 +255,7 @@ protected function loadOrmEntityManagers(array $config, ContainerBuilder $contai
protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $container)
{
$defaultEntityManager = $container->getParameter('doctrine.orm.default_entity_manager');
$proxyCacheDir = $this->kernelCacheDir . '/doctrine/orm/Proxies';
$proxyCacheDir = $container->getParameter('kernel.cache_dir').'/doctrine/orm/Proxies';

$ormConfigDef = new Definition('Doctrine\ORM\Configuration');
$container->setDefinition(sprintf('doctrine.orm.%s_configuration', $entityManager['name']), $ormConfigDef);
Expand Down Expand Up @@ -338,9 +328,9 @@ protected function loadOrmEntityManagerBundlesMappingInformation(array $entityMa
// configure metadata driver for each bundle based on the type of mapping files found
$mappingDriverDef = new Definition('%doctrine.orm.metadata.driver_chain_class%');
$bundleEntityMappings = array();
$bundleDirs = $this->bundleDirs;
$bundleDirs = $container->getParameter('kernel.bundle_dirs');
$aliasMap = array();
foreach ($this->bundles as $className) {
foreach ($container->getParameter('kernel.bundles') as $className) {
$tmp = dirname(str_replace('\\', '/', $className));
$namespace = str_replace('/', '\\', dirname($tmp));
$class = basename($tmp);
Expand Down Expand Up @@ -464,7 +454,7 @@ protected function getEntityManagerCacheDefinition(array $entityManager, $cacheD
protected function findBundleSubpaths($path, ContainerBuilder $container)
{
$dirs = array();
foreach ($this->bundles as $bundle) {
foreach ($container->getParameter('kernel.bundles') as $bundle) {
$reflection = new \ReflectionClass($bundle);
if (is_dir($dir = dirname($reflection->getFilename()).'/'.$path)) {
$dirs[] = $dir;
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php
Expand Up @@ -33,10 +33,6 @@ class DoctrineBundle extends Bundle
*/
public function buildContainer(ParameterBagInterface $parameterBag)
{
ContainerBuilder::registerExtension(new DoctrineExtension(
$parameterBag->get('kernel.bundle_dirs'),
$parameterBag->get('kernel.bundles'),
$parameterBag->get('kernel.cache_dir')
));
ContainerBuilder::registerExtension(new DoctrineExtension());
}
}
Expand Up @@ -14,6 +14,7 @@
use Symfony\Bundle\DoctrineBundle\Tests\TestCase;
use Symfony\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Symfony\Components\DependencyInjection\ContainerBuilder;
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Components\DependencyInjection\Loader\YamlFileLoader;

Expand All @@ -23,8 +24,8 @@ abstract protected function loadFromFile(ContainerBuilder $container, $file);

public function testDbalLoad()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();

$loader->dbalLoad(array(), $container);
$this->assertEquals('Symfony\\Bundle\\DoctrineBundle\\DataCollector\\DoctrineDataCollector', $container->getParameter('doctrine.data_collector.class'), '->dbalLoad() loads the dbal.xml file if not already loaded');
Expand All @@ -36,8 +37,8 @@ public function testDbalLoad()
$loader->dbalLoad(array(), $container);
$this->assertEquals('foo', $container->getParameter('doctrine.dbal.default_connection'), '->dbalLoad() overrides existing configuration options');

$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$loader->dbalLoad(array('password' => 'foo'), $container);

$arguments = $container->getDefinition('doctrine.dbal.default_connection')->getArguments();
Expand All @@ -53,8 +54,8 @@ public function testDbalLoad()

public function testDbalLoadFromXmlMultipleConnections()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$loadXml = new XmlFileLoader($container, __DIR__.'/Fixtures/config/xml');
Expand All @@ -73,8 +74,8 @@ public function testDbalLoadFromXmlMultipleConnections()

// doctrine.dbal.sqlite_connection
$arguments = $container->getDefinition('doctrine.dbal.sqlite_connection')->getArguments();
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$loadXml = new XmlFileLoader($container, __DIR__.'/Fixtures/config/xml');
Expand All @@ -94,8 +95,8 @@ public function testDbalLoadFromXmlMultipleConnections()

public function testDependencyInjectionConfigurationDefaults()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();

$loader->dbalLoad(array(), $container);
$loader->ormLoad(array(), $container);
Expand Down Expand Up @@ -169,8 +170,8 @@ public function testDependencyInjectionConfigurationDefaults()

public function testSingleEntityManagerConfiguration()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();

$loader->dbalLoad(array(), $container);
$loader->ormLoad(array(), $container);
Expand All @@ -191,8 +192,8 @@ public function testSingleEntityManagerConfiguration()

public function testLoadSimpleSingleConnection()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$loader->dbalLoad(array(), $container);
Expand Down Expand Up @@ -225,8 +226,8 @@ public function testLoadSimpleSingleConnection()

public function testLoadSingleConnection()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$this->loadFromFile($container, 'orm_service_single_entity_manager');
Expand Down Expand Up @@ -256,8 +257,8 @@ public function testLoadSingleConnection()

public function testLoadMultipleConnections()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$this->loadFromFile($container, 'orm_service_multiple_entity_managers');
Expand Down Expand Up @@ -318,8 +319,8 @@ public function testLoadMultipleConnections()

public function testBundleEntityAliases()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();

$loader->dbalLoad(array(), $container);
$loader->ormLoad(array(), $container);
Expand All @@ -332,8 +333,8 @@ public function testBundleEntityAliases()

public function testYamlBundleMappingDetection()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader('YamlBundle');
$container = $this->getContainer('YamlBundle');
$loader = new DoctrineExtension();

$loader->dbalLoad(array(), $container);
$loader->ormLoad(array(), $container);
Expand All @@ -350,8 +351,8 @@ public function testYamlBundleMappingDetection()

public function testXmlBundleMappingDetection()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader('XmlBundle');
$container = $this->getContainer('XmlBundle');
$loader = new DoctrineExtension();

$loader->dbalLoad(array(), $container);
$loader->ormLoad(array(), $container);
Expand All @@ -368,8 +369,8 @@ public function testXmlBundleMappingDetection()

public function testAnnotationsBundleMappingDetection()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader('AnnotationsBundle');
$container = $this->getContainer('AnnotationsBundle');
$loader = new DoctrineExtension();

$loader->dbalLoad(array(), $container);
$loader->ormLoad(array(), $container);
Expand All @@ -386,8 +387,8 @@ public function testAnnotationsBundleMappingDetection()

public function testEntityManagerMetadataCacheDriverConfiguration()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$this->loadFromFile($container, 'orm_service_multiple_entity_managers');
Expand All @@ -403,8 +404,8 @@ public function testEntityManagerMetadataCacheDriverConfiguration()

public function testEntityManagerMemcacheMetadataCacheDriverConfiguration()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$this->loadFromFile($container, 'orm_service_simple_single_entity_manager');
Expand All @@ -429,8 +430,8 @@ public function testEntityManagerMemcacheMetadataCacheDriverConfiguration()

public function testDependencyInjectionImportsOverrideDefaults()
{
$container = new ContainerBuilder();
$loader = $this->getDoctrineExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$this->loadFromFile($container, 'orm_imports');
Expand All @@ -441,11 +442,14 @@ public function testDependencyInjectionImportsOverrideDefaults()
$this->assertTrue($container->getParameter('doctrine.orm.auto_generate_proxy_classes'));
}

protected function getDoctrineExtensionLoader($bundle = 'YamlBundle')
protected function getContainer($bundle = 'YamlBundle')
{
require_once __DIR__.'/Fixtures/Bundles/'.$bundle.'/'.$bundle.'.php';
$bundleDirs = array('DoctrineBundle\\Tests\\DependencyInjection\\Fixtures\\Bundles' => __DIR__.'/Fixtures/Bundles');
$bundles = array('DoctrineBundle\\Tests\DependencyInjection\\Fixtures\\Bundles\\'.$bundle.'\\'.$bundle);
return new DoctrineExtension($bundleDirs, $bundles, sys_get_temp_dir());

return new ContainerBuilder(new ParameterBag(array(
'kernel.bundle_dirs' => array('DoctrineBundle\\Tests\\DependencyInjection\\Fixtures\\Bundles' => __DIR__.'/Fixtures/Bundles'),
'kernel.bundles' => array('DoctrineBundle\\Tests\DependencyInjection\\Fixtures\\Bundles\\'.$bundle.'\\'.$bundle),
'kernel.cache_dir' => sys_get_temp_dir(),
)));
}
}

0 comments on commit 0f30e53

Please sign in to comment.