/** * Initialize generator * * @param sfGeneratorManager * @return void */ public function initialize(sfGeneratorManager $generatorManager) { parent::initialize($generatorManager); $this->getPluginModels(); $this->setGeneratorClass('dinDoctrineFormFilter'); $this->config = dinGeneratorModelConfig::getInstance($generatorManager->getConfiguration()); }
/** * Merges and configure all project and plugin schema files into one * * @param string $yamlSchemaPath Project schema path * @return string Absolute path to the consolidated schema file */ protected function prepareSchemaFile($yamlSchemaPath) { $models = array(); $finder = sfFinder::type('file')->name('*.yml')->sort_by_name()->follow_link(); $config = dinGeneratorModelConfig::getInstance($this->configuration); foreach ($this->configuration->getPlugins() as $name) { $plugin = $this->configuration->getPluginConfiguration($name); foreach ($finder->in($plugin->getRootDir() . '/config/doctrine') as $schema) { $pluginModels = (array) sfYaml::load($schema); $globals = $this->filterSchemaGlobals($pluginModels); foreach ($pluginModels as $model => $definition) { $definition = $this->canonicalizeModelDefinition($model, $definition); $definition = array_merge($globals, $definition); $models[$model] = isset($models[$model]) ? sfToolkit::arrayDeepMerge($models[$model], $definition) : $definition; if (!isset($models[$model]['package'])) { $models[$model]['package'] = $plugin->getName() . '.lib.model.doctrine'; } if (!isset($models[$model]['package_custom_path']) && 0 === strpos($models[$model]['package'], $plugin->getName())) { $models[$model]['package_custom_path'] = $plugin->getRootDir() . '/lib/model/doctrine'; } } } } foreach ($finder->in($yamlSchemaPath) as $schema) { $projectModels = (array) sfYaml::load($schema); $globals = $this->filterSchemaGlobals($projectModels); foreach ($projectModels as $model => $definition) { $definition = $this->canonicalizeModelDefinition($model, $definition); $definition = array_merge($globals, $definition); $models[$model] = isset($models[$model]) ? sfToolkit::arrayDeepMerge($models[$model], $definition) : $definition; } } foreach ($models as $model => $definition) { $models[$model] = $config->prepareModelDefinition($model, $definition); if (!$models[$model]) { unset($models[$model]); } } $file = realpath(sys_get_temp_dir()) . '/doctrine_schema_' . rand(11111, 99999) . '.yml'; $this->logSection('file+', $file); file_put_contents($file, sfYaml::dump($models, 4)); return $file; }