diff --git a/DataFixtures/AbstractDataHandler.php b/DataFixtures/AbstractDataHandler.php index 3c40480..333b77a 100644 --- a/DataFixtures/AbstractDataHandler.php +++ b/DataFixtures/AbstractDataHandler.php @@ -64,8 +64,7 @@ abstract class AbstractDataHandler if (0 === count($this->dbMap->getTables())) { $finder = new Finder(); $files = $finder->files()->name('*TableMap.php') - ->in($this->getRootDir() . '/../src/') - ->in($this->getRootDir() . '/../vendor/') + ->in($this->getModelSearchPath($connectionName)) ->exclude('PropelBundle') ->exclude('Tests'); @@ -121,4 +120,24 @@ abstract class AbstractDataHandler return null; } + + /** + * Gets the search path for models out of the configuration. + * + * @param string $connectionName A connection name. + */ + + private function getModelSearchPath($connectionName) { + $configuration = Propel::getConfiguration(); + $searchPath = array(); + if (!empty($configuration['datasources'][$connectionName]['connection']['model_paths'])) { + $modelPaths = $configuration['datasources'][$connectionName]['connection']['model_paths']; + foreach ($modelPaths as $modelPath) { + $searchPath[] = $this->getRootDir() . '/../' . $modelPath; + } + } else { + $searchPath[] = $this->getRootDir() . '/../'; + } + return $searchPath; + } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d2f3bbf..8f3eca4 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -232,6 +232,12 @@ class Configuration implements ConfigurationInterface ->prototype('scalar')->end() ->end() ->end() + ->fixXmlConfig('model_path') + ->children() + ->arrayNode('model_paths') + ->prototype('scalar')->end() + ->end() + ->end() ->fixXmlConfig('attribute') ->children() ->arrayNode('attributes') diff --git a/DependencyInjection/PropelExtension.php b/DependencyInjection/PropelExtension.php index 3daf950..cbd1719 100644 --- a/DependencyInjection/PropelExtension.php +++ b/DependencyInjection/PropelExtension.php @@ -123,7 +123,7 @@ class PropelExtension extends Extension $c['datasources'][$name]['slaves']['connection'] = $conf['slaves']; } - foreach (array('dsn', 'user', 'password', 'classname', 'options', 'attributes', 'settings') as $att) { + foreach (array('dsn', 'user', 'password', 'classname', 'options', 'attributes', 'settings', 'model_paths') as $att) { if (isset($conf[$att])) { $c['datasources'][$name]['connection'][$att] = $conf[$att]; } diff --git a/Resources/doc/configuration.markdown b/Resources/doc/configuration.markdown index ac26fce..91ea7c0 100644 --- a/Resources/doc/configuration.markdown +++ b/Resources/doc/configuration.markdown @@ -110,10 +110,13 @@ propel: settings: charset: { value: UTF8 } queries: { query: 'INSERT INTO BAR ('hey', 'there')' } + model_paths: + - /src/Acme/DemoBundle/Model/ + - /vendor/ ``` `options`, `attributes` and `settings` are parts of the runtime configuration. See [Runtime Configuration File](http://www.propelorm.org/reference/runtime-configuration.html) documentation for more explanation. - +`model_paths` can be defined to speed up searching for model data. By default it searches in the whole project from project root. ## Logging ##