Permalink
Browse files

[DoctrineMongoDBBundle] removed DoctrineMongoDBExtension constructor

  • Loading branch information...
1 parent a50c831 commit 22d95dd0f351cad48c7ee7ee4046291ea7661901 @fabpot fabpot committed Aug 10, 2010
@@ -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.
@@ -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);
@@ -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)));
@@ -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);
@@ -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);
@@ -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;
@@ -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());
}
-}
+}
@@ -23,8 +23,8 @@
public function testDependencyInjectionConfigurationDefaults()
{
- $container = new ContainerBuilder();
- $loader = $this->getMongoDbExtensionLoader();
+ $container = $this->getContainer();
+ $loader = new DoctrineMongoDBExtension();
$loader->mongodbLoad(array(), $container);
@@ -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',
@@ -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');
@@ -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');
@@ -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');
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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');
@@ -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');
@@ -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');
@@ -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 22d95dd

Please sign in to comment.