[DoctrineMongoDBBundle] removed DoctrineMongoDBExtension constructor
This commit is contained in:
parent
0f30e539b1
commit
f6c862667f
@ -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 @@ class DoctrineMongoDBExtension extends Extension
|
||||
*/
|
||||
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 @@ class DoctrineMongoDBExtension extends Extension
|
||||
/**
|
||||
* 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 @@ class DoctrineMongoDBExtension extends Extension
|
||||
{
|
||||
$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 @@ class DoctrineMongoDBExtension extends Extension
|
||||
// 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 @@ class DoctrineMongoDBExtension extends Extension
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
public function testDependencyInjectionConfigurationDefaults()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = $this->getMongoDbExtensionLoader();
|
||||
$container = $this->getContainer();
|
||||
$loader = new DoctrineMongoDBExtension();
|
||||
|
||||
$loader->mongodbLoad(array(), $container);
|
||||
|
||||
@ -73,8 +73,8 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
public function testBundleDocumentAliases()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = $this->getMongoDbExtensionLoader();
|
||||
$container = $this->getContainer();
|
||||
$loader = new DoctrineMongoDBExtension();
|
||||
|
||||
$loader->mongodbLoad(array(), $container);
|
||||
|
||||
@ -209,8 +209,8 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
|
||||
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 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
|
||||
$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(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user