Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit a74e85e

Browse files
reyostallenbergniels-nijens
authored andcommitted
Make bundle name configurable (#42)
1 parent be677fd commit a74e85e

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

Command/GenerateMappingCommand.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
3434
{
3535
$io = new SymfonyStyle($input, $output);
3636

37-
$flexModel = $this->getContainer()->get('flexmodel');
37+
$container = $this->getContainer();
38+
39+
$flexModel = $container->get('flexmodel');
3840
$domDocument = $flexModel->getDOMDocument();
3941

42+
$bundleName = $container->getParameter('flex_model.bundle_name');
43+
$bundle = $this->getApplication()->getKernel()->getBundle($bundleName);
44+
4045
$xslDocument = new DOMDocument('1.0', 'UTF-8');
4146
$xslDocument->load(__DIR__.'/../Resources/xsl/doctrine-mapping.xsl');
4247

4348
$processor = new XSLTProcessor();
44-
$processor->setParameter('', 'objectNamespace', 'AppBundle\\Entity\\'); // @todo Make configurable
49+
$processor->setParameter('', 'objectNamespace', sprintf('%s\\Entity\\', $bundle->getNamespace()));
4550
$processor->importStyleSheet($xslDocument);
4651

47-
$bundle = $this->getApplication()->getKernel()->getBundle('AppBundle'); // @todo Make configurable
48-
49-
$ormMappingDirectory = $bundle->getPath().'/Resources/config/doctrine'; // @todo Make configurable
52+
$ormMappingDirectory = $bundle->getPath().'/Resources/config/doctrine';
5053
if (is_dir(dirname($ormMappingDirectory)) === false) {
5154
mkdir($ormMappingDirectory, 0755, true);
5255
}
@@ -63,6 +66,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
6366
$io->success('Generated Doctrine mapping from FlexModel configuration.');
6467

6568
$command = $this->getApplication()->find('generate:doctrine:entities');
66-
$command->run(new ArrayInput(array('name' => 'AppBundle')), $output);
69+
$command->run(new ArrayInput(array('name' => $bundleName)), $output);
6770
}
6871
}

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function getConfigTreeBuilder()
2323
$rootNode
2424
->children()
2525
->scalarNode('resource')->isRequired()->end()
26+
->scalarNode('bundle_name')->defaultValue('AppBundle')->end()
2627
->scalarNode('file_upload_path')->end()
2728
->end();
2829

DependencyInjection/FlexModelExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function load(array $configs, ContainerBuilder $container)
2323
$config = $this->processConfiguration($configuration, $configs);
2424

2525
$container->setParameter('flex_model.resource', $config['resource']);
26+
$container->setParameter('flex_model.bundle_name', $config['bundle_name']);
2627

2728
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2829
$loader->load('services.xml');

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Add the following configuration to your `config.yml` file:
3434
# app/config/config.yml
3535

3636
flex_model:
37+
bundle_name: AppBundle # optional, defaults to 'AppBundle'
3738
resource: "%kernel.root_dir%/../src/AppBundle/Resources/config/flexmodel.xml"
3839
```
3940

0 commit comments

Comments
 (0)