diff --git a/Command/GenerateMappingCommand.php b/Command/GenerateMappingCommand.php index b3e07eb..63c8c92 100644 --- a/Command/GenerateMappingCommand.php +++ b/Command/GenerateMappingCommand.php @@ -34,19 +34,22 @@ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); - $flexModel = $this->getContainer()->get('flexmodel'); + $container = $this->getContainer(); + + $flexModel = $container->get('flexmodel'); $domDocument = $flexModel->getDOMDocument(); + $bundleName = $container->getParameter('flex_model.bundle_name'); + $bundle = $this->getApplication()->getKernel()->getBundle($bundleName); + $xslDocument = new DOMDocument('1.0', 'UTF-8'); $xslDocument->load(__DIR__.'/../Resources/xsl/doctrine-mapping.xsl'); $processor = new XSLTProcessor(); - $processor->setParameter('', 'objectNamespace', 'AppBundle\\Entity\\'); // @todo Make configurable + $processor->setParameter('', 'objectNamespace', sprintf('%s\\Entity\\', $bundle->getNamespace())); $processor->importStyleSheet($xslDocument); - $bundle = $this->getApplication()->getKernel()->getBundle('AppBundle'); // @todo Make configurable - - $ormMappingDirectory = $bundle->getPath().'/Resources/config/doctrine'; // @todo Make configurable + $ormMappingDirectory = $bundle->getPath().'/Resources/config/doctrine'; if (is_dir(dirname($ormMappingDirectory)) === false) { mkdir($ormMappingDirectory, 0755, true); } @@ -63,6 +66,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->success('Generated Doctrine mapping from FlexModel configuration.'); $command = $this->getApplication()->find('generate:doctrine:entities'); - $command->run(new ArrayInput(array('name' => 'AppBundle')), $output); + $command->run(new ArrayInput(array('name' => $bundleName)), $output); } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index c4fd892..201dc0d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,6 +23,7 @@ public function getConfigTreeBuilder() $rootNode ->children() ->scalarNode('resource')->isRequired()->end() + ->scalarNode('bundle_name')->defaultValue('AppBundle')->end() ->scalarNode('file_upload_path')->end() ->end(); diff --git a/DependencyInjection/FlexModelExtension.php b/DependencyInjection/FlexModelExtension.php index eaa131b..a0209d5 100644 --- a/DependencyInjection/FlexModelExtension.php +++ b/DependencyInjection/FlexModelExtension.php @@ -23,6 +23,7 @@ public function load(array $configs, ContainerBuilder $container) $config = $this->processConfiguration($configuration, $configs); $container->setParameter('flex_model.resource', $config['resource']); + $container->setParameter('flex_model.bundle_name', $config['bundle_name']); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); diff --git a/README.md b/README.md index de44047..e2e627c 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Add the following configuration to your `config.yml` file: # app/config/config.yml flex_model: + bundle_name: AppBundle # optional, defaults to 'AppBundle' resource: "%kernel.root_dir%/../src/AppBundle/Resources/config/flexmodel.xml" ```