Skip to content

Commit

Permalink
[DoctrineMongoDBBundle] removed DoctrineMongoDBExtension constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 10, 2010
1 parent 0f30e53 commit f6c8626
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 52 deletions.
Expand Up @@ -21,16 +21,6 @@ class DoctrineMongoDBExtension extends Extension
protected $resources = array(
'mongodb' => 'mongodb.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 MongoDB ODM configuration.
Expand All @@ -44,7 +34,7 @@ public function __construct(array $bundleDirs, array $bundles, $kernelCacheDir)
*/
public function mongodbLoad($config, ContainerBuilder $container)
{
$this->createProxyDirectory();
$this->createProxyDirectory($container->getParameter('kernel.cache_dir'));
$this->loadDefaults($config, $container);
$this->loadConnections($config, $container);
$this->loadDocumentManagers($config, $container);
Expand All @@ -53,10 +43,10 @@ public function mongodbLoad($config, ContainerBuilder $container)
/**
* Create the Doctrine MongoDB ODM Document proxy directory
*/
protected function createProxyDirectory()
protected function createProxyDirectory($tmpDir)
{
// Create document proxy directory
$proxyCacheDir = $this->kernelCacheDir . '/doctrine/odm/mongodb/Proxies';
$proxyCacheDir = $tmpDir.'/doctrine/odm/mongodb/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 @@ -124,7 +114,7 @@ protected function loadDocumentManager(array $documentManager, ContainerBuilder
{
$defaultDocumentManager = $container->getParameter('doctrine.odm.mongodb.default_document_manager');
$defaultDatabase = isset($documentManager['default_database']) ? $documentManager['default_database'] : $container->getParameter('doctrine.odm.mongodb.default_database');
$proxyCacheDir = $this->kernelCacheDir . '/doctrine/odm/mongodb/Proxies';
$proxyCacheDir = $this->container->getParameter('kernel.cache_dir').'/doctrine/odm/mongodb/Proxies';

$odmConfigDef = new Definition('%doctrine.odm.mongodb.configuration_class%');
$container->setDefinition(sprintf('doctrine.odm.mongodb.%s_configuration', $documentManager['name']), $odmConfigDef);
Expand Down Expand Up @@ -197,9 +187,9 @@ protected function loadDocumentManagerBundlesMappingInformation(array $documentM
// configure metadata driver for each bundle based on the type of mapping files found
$mappingDriverDef = new Definition('%doctrine.odm.mongodb.metadata.driver_chain_class%');
$bundleDocumentMappings = 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 @@ -314,7 +304,7 @@ protected function getConnections(array $config, ContainerBuilder $container)
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
Expand Up @@ -25,10 +25,6 @@ class DoctrineMongoDBBundle extends Bundle
*/
public function buildContainer(ParameterBagInterface $parameterBag)
{
ContainerBuilder::registerExtension(new DoctrineMongoDBExtension(
$parameterBag->get('kernel.bundle_dirs'),
$parameterBag->get('kernel.bundles'),
$parameterBag->get('kernel.cache_dir')
));
ContainerBuilder::registerExtension(new DoctrineMongoDBExtension());
}
}
}
Expand Up @@ -23,8 +23,8 @@ abstract protected function loadFromFile(ContainerBuilder $container, $file);

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

$loader->mongodbLoad(array(), $container);

Expand Down Expand Up @@ -73,8 +73,8 @@ public function testDependencyInjectionConfigurationDefaults()

public function testSingleDocumentManagerConfiguration()
{
$container = new ContainerBuilder();
$loader = $this->getMongoDbExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineMongoDBExtension();

$config = array(
'server' => 'mongodb://localhost:27017',
Expand All @@ -99,8 +99,8 @@ public function testSingleDocumentManagerConfiguration()

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

$this->loadFromFile($container, 'mongodb_service_simple_single_connection');
Expand Down Expand Up @@ -130,8 +130,8 @@ public function testLoadSimpleSingleConnection()

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

$this->loadFromFile($container, 'mongodb_service_single_connection');
Expand All @@ -155,8 +155,8 @@ public function testLoadSingleConnection()

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

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

public function testBundleDocumentAliases()
{
$container = new ContainerBuilder();
$loader = $this->getMongoDbExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineMongoDBExtension();

$loader->mongodbLoad(array(), $container);

Expand All @@ -209,8 +209,8 @@ public function testBundleDocumentAliases()

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

$loader->mongodbLoad(array(), $container);

Expand All @@ -226,8 +226,8 @@ public function testYamlBundleMappingDetection()

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

$loader->mongodbLoad(array(), $container);

Expand All @@ -243,8 +243,8 @@ public function testXmlBundleMappingDetection()

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

$loader->mongodbLoad(array(), $container);

Expand All @@ -260,8 +260,8 @@ public function testAnnotationsBundleMappingDetection()

public function testDocumentManagerMetadataCacheDriverConfiguration()
{
$container = new ContainerBuilder();
$loader = $this->getMongoDbExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineMongoDBExtension();
$container->registerExtension($loader);

$this->loadFromFile($container, 'mongodb_service_multiple_connections');
Expand All @@ -277,8 +277,8 @@ public function testDocumentManagerMetadataCacheDriverConfiguration()

public function testDocumentManagerMemcacheMetadataCacheDriverConfiguration()
{
$container = new ContainerBuilder();
$loader = $this->getMongoDbExtensionLoader();
$container = $this->getContainer();
$loader = new DoctrineMongoDBExtension();
$container->registerExtension($loader);

$this->loadFromFile($container, 'mongodb_service_simple_single_connection');
Expand All @@ -303,8 +303,8 @@ public function testDocumentManagerMemcacheMetadataCacheDriverConfiguration()

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

$this->loadFromFile($container, 'odm_imports');
Expand All @@ -315,11 +315,14 @@ public function testDependencyInjectionImportsOverrideDefaults()
$this->assertTrue($container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes'));
}

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

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

0 comments on commit f6c8626

Please sign in to comment.