Skip to content

Commit

Permalink
added to customize the model dir and to add extra config classes dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodip committed May 6, 2011
1 parent b467528 commit 9eedca2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
38 changes: 22 additions & 16 deletions Command/GenerateCommand.php
Expand Up @@ -42,25 +42,31 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('processing config classes');

$modelDir = $this->container->getParameter('kernel.root_dir').'/../src/Model';
$modelDir = $this->container->getParameter('mandango.model_dir');

$configClasses = array();
// application
if (is_dir($dir = $this->container->getParameter('kernel.root_dir').'/config/mandango')) {
$finder = new Finder();
foreach ($finder->files()->name('*.yml')->followLinks()->in($dir) as $file) {
foreach ((array) Yaml::load($file) as $class => $configClass) {
// class
if (0 !== strpos($class, 'Model\\')) {
throw new \RuntimeException('The Mandango documents must been in the "Model\" namespace.');
}
// application + extra
foreach (array_merge(
array($this->container->getParameter('kernel.root_dir').'/config/mandango'),
$this->container->getParameter('mandango.extra_config_classes_dirs')
) as $dir) {
if (is_dir($dir)) {
$finder = new Finder();
foreach ($finder->files()->name('*.yml')->followLinks()->in($dir) as $file) {
foreach ((array) Yaml::load($file) as $class => $configClass) {
// class
if (0 !== strpos($class, 'Model\\')) {
throw new \RuntimeException('The Mandango documents must been in the "Model\" namespace.');
}

// config class
$configClass['output'] = $modelDir.'/'.str_replace('\\', '/', substr(substr($class, 0, strrpos($class, '\\')), 6));
$configClass['bundle_name'] = null;
$configClass['bundle_namespace'] = null;
$configClass['bundle_dir'] = null;
// config class
$configClass['output'] = $modelDir.'/'.str_replace('\\', '/', substr(substr($class, 0, strrpos($class, '\\')), 6));
$configClass['bundle_name'] = null;
$configClass['bundle_namespace'] = null;
$configClass['bundle_dir'] = null;

$configClasses[$class] = $configClass;
$configClasses[$class] = $configClass;
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions DependencyInjection/Configuration.php
Expand Up @@ -33,15 +33,22 @@ public function getConfigTree()
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('mandango', 'array');

$this->addConnectionsSection($rootNode);

$rootNode
->children()
->scalarNode('model_dir')->end()
->booleanNode('logging')->end()
->scalarNode('default_connection')->end()
->end()

->fixXmlConfig('extra_config_classes_dir')
->children()
->arrayNode('extra_config_classes_dirs')
->prototype('scalar')->end()
->end()
;

$this->addConnectionsSection($rootNode);

return $treeBuilder->buildTree();
}

Expand Down
28 changes: 18 additions & 10 deletions DependencyInjection/MandangoExtension.php
Expand Up @@ -41,6 +41,24 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration($container->getParameter('kernel.debug'));
$config = $processor->process($configuration->getConfigTree(), $configs);

// model_dir
if (isset($config['model_dir'])) {
$container->setParameter('mandango.model_dir', $config['model_dir']);
}

// logging
if (isset($config['logging']) && $config['logging']) {
$container->getDefinition('mandango')->addArgument(array(new Reference('mandango.logger'), 'logQuery'));
}

// default_connection
if (isset($config['default_connection'])) {
$container->getDefinition('mandango')->addMethodCall('setDefaultConnectionName', array($config['default_connection']));
}

// extra config classes dirs
$container->setParameter('mandango.extra_config_classes_dirs', $config['extra_config_classes_dirs']);

// connections
foreach ($config['connections'] as $name => $connection) {
$definition = new Definition($connection['class'], array(
Expand All @@ -58,15 +76,5 @@ public function load(array $configs, ContainerBuilder $container)
new Reference($connectionDefinitionName),
));
}

// default_connection
if (isset($config['default_connection'])) {
$container->getDefinition('mandango')->addMethodCall('setDefaultConnectionName', array($config['default_connection']));
}

// logging
if (isset($config['logging']) && $config['logging']) {
$container->getDefinition('mandango')->addArgument(array(new Reference('mandango.logger'), 'logQuery'));
}
}
}
4 changes: 3 additions & 1 deletion Resources/config/mandango.xml
Expand Up @@ -8,7 +8,9 @@
<!-- mandango -->
<parameter key="mandango.class">Mandango\Mandango</parameter>
<parameter key="mandango.metadata.class">Model\Mapping\Metadata</parameter>
<parameter key="mandango.metadata.output">%kernel.root_dir%/../src/Model/Mapping</parameter>

<parameter key="mandango.model_dir">%kernel.root_dir%/../src/Model</parameter>
<parameter key="mandango.metadata.output">%mandango.model_dir%/Mapping</parameter>

<!-- cache -->
<parameter key="mandango.cache.filesystem_cache.class">Mandango\Cache\FilesystemCache</parameter>
Expand Down

0 comments on commit 9eedca2

Please sign in to comment.