protected function execute($arguments = array(), $options = array()) { $params = array('decorated_class' => $arguments['classToDecorate'], 'generated_class' => null === $arguments['classToCreate'] ? $arguments['classToDecorate'] . 'Decorator' : $arguments['classToCreate'], 'path' => $arguments['path']); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate('sfDecoratorGenerator', $params); $this->logSection('generate', sprintf('%s created as a decorator to %s in %s', $params['generated_class'], $params['decorated_class'], $params['path'])); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { if (false === $options['connection'] && false === $options['all-connections']) { $options['connection'] = 'propel'; } elseif (false !== $options['connection']) { $options['all-connections'] = false; } $this->logSection('propel', 'generating filter form classes'); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate($options['generator-class'], array( 'connection' => $options['connection'], 'model_dir_name' => $options['model-dir-name'], 'filter_dir_name' => $options['filter-dir-name'], 'all_connections' => $options['all-connections'], )); $properties = parse_ini_file(sfConfig::get('sf_config_dir').'/properties.ini', true); $constants = array( 'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here' ); // customize php and yml files $finder = sfFinder::type('file')->name('*.php'); $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir').'/filter/'), '##', '##', $constants); $this->reloadAutoload(); }
protected function executeGenerate($arguments = array(), $options = array()) { // generate module $tmpDir = sfConfig::get('sf_cache_dir') . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); sfConfig::set('sf_module_cache_dir', $tmpDir); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate('sfDoctrineCrudGenerator', array('model_class' => $arguments['model'], 'moduleName' => $arguments['module'], 'theme' => $options['theme'], 'non_atomic_actions' => $options['non-atomic-actions'], 'non_verbose_templates' => $options['non-verbose-templates'], 'with_show' => $options['with-show'])); $moduleDir = sfConfig::get('sf_app_module_dir') . '/' . $arguments['module']; // copy our generated module $this->getFilesystem()->mirror($tmpDir . '/auto' . ucfirst($arguments['module']), $moduleDir, sfFinder::type('any')); if (!$options['with-show']) { $this->getFilesystem()->remove($moduleDir . '/templates/showSuccess.php'); } // change module name $this->getFilesystem()->replaceTokens($moduleDir . '/actions/actions.class.php', '', '', array('auto' . ucfirst($arguments['module']) => $arguments['module'])); // customize php and yml files $finder = sfFinder::type('file')->name('*.php', '*.yml'); $this->getFilesystem()->replaceTokens($finder->in($moduleDir), '##', '##', $this->constants); // create basic test $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir') . '/task/generator/skeleton/module/test/actionsTest.php', sfConfig::get('sf_test_dir') . '/functional/' . $arguments['application'] . '/' . $arguments['module'] . 'ActionsTest.php'); // customize test file $this->getFilesystem()->replaceTokens(sfConfig::get('sf_test_dir') . '/functional/' . $arguments['application'] . DIRECTORY_SEPARATOR . $arguments['module'] . 'ActionsTest.php', '##', '##', $this->constants); // delete temp files $this->getFilesystem()->remove(sfFinder::type('any')->in($tmpDir)); }
/** * Executes this configuration handler. * * @param array An array of absolute filesystem path to a configuration file * * @return string Data to be written to a cache file * * @throws sfConfigurationException If a requested configuration file does not exist or is not readable * @throws sfParseException If a requested configuration file is improperly formatted * @throws sfInitializationException If a generator.yml key check fails */ public function execute($configFiles) { // parse the yaml $config = $this->parseYamls($configFiles); if (!$config) { return ''; } if (!isset($config['generator'])) { throw new sfParseException(sprintf('Configuration file "%s" must specify a generator section', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0])); } $config = $config['generator']; if (!isset($config['class'])) { throw new sfParseException(sprintf('Configuration file "%s" must specify a generator class section under the generator section', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0])); } foreach (array('fields', 'list', 'edit') as $section) { if (isset($config[$section])) { throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0], $section)); } } // generate class and add a reference to it $generatorManager = new sfGeneratorManager(); $generatorManager->initialize(); // generator parameters $generatorParam = isset($config['param']) ? $config['param'] : array(); // hack to find the module name (look for the last /modules/ in path) preg_match('#.*/' . sfConfig::get('sf_app_module_dir_name') . '/([^/]+)/#', $configFiles[0], $match); if (0 < count($match) && 0 < strlen($match[1])) { $generatorParam['moduleName'] = $match[1]; } $data = $generatorManager->generate($config['class'], $generatorParam); // compile data $retval = "<?php\n" . "// auto-generated by sfGeneratorConfigHandler\n" . "// date: %s\n%s\n"; $retval = sprintf($retval, date('Y/m/d H:i:s'), $data); return $retval; }
public function executeTableManager() { $class = $this->getRequestParameter('class'); $generator_configuration = array( 'model_class' => $class, 'theme' => 'sfControlPanel', 'moduleName' => $class.'ControlPanel', 'list' => array( 'title' => $class.' list', ), 'edit' => array( 'title' => 'edit '.$class, ), ); if(file_exists(SF_ROOT_DIR.'/config/sfControlPanel_generator.yml')) { $custom_configuration = sfYaml::load(SF_ROOT_DIR.'/config/sfControlPanel_generator.yml'); if(isset($custom_configuration[$class])) { $generator_configuration = sfToolkit::arrayDeepMerge($generator_configuration, $custom_configuration[$class]); } } $generatorManager = new sfGeneratorManager(); $generatorManager->initialize(); $data = $generatorManager->generate('sfControlPanelGenerator', $generator_configuration); $this->redirect('auto'.$class.'ControlPanel/list'); }
protected function executeGenerate($arguments = array(), $options = array()) { // generate module $tmpDir = sfConfig::get('sf_cache_dir') . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); $generatorManager = new sfGeneratorManager($this->configuration, $tmpDir); $generatorManager->generate('sfPropelGenerator', array('model_class' => $arguments['model'], 'moduleName' => $arguments['module'], 'theme' => $options['theme'], 'non_verbose_templates' => $options['non-verbose-templates'], 'with_show' => $options['with-show'], 'singular' => $options['singular'], 'plural' => $options['plural'], 'route_prefix' => $options['route-prefix'], 'with_propel_route' => $options['with-propel-route'], 'actions_base_class' => $options['actions-base-class'])); $moduleDir = sfConfig::get('sf_app_module_dir') . '/' . $arguments['module']; // copy our generated module $this->getFilesystem()->mirror($tmpDir . DIRECTORY_SEPARATOR . 'auto' . ucfirst($arguments['module']), $moduleDir, sfFinder::type('any')); if (!$options['with-show']) { $this->getFilesystem()->remove($moduleDir . '/templates/showSuccess.php'); } // change module name $finder = sfFinder::type('file')->name('*.php'); $this->getFilesystem()->replaceTokens($finder->in($moduleDir), '', '', array('auto' . ucfirst($arguments['module']) => $arguments['module'])); // customize php and yml files $finder = sfFinder::type('file')->name('*.php', '*.yml'); $this->getFilesystem()->replaceTokens($finder->in($moduleDir), '##', '##', $this->constants); // create basic test $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir') . DIRECTORY_SEPARATOR . 'task' . DIRECTORY_SEPARATOR . 'generator' . DIRECTORY_SEPARATOR . 'skeleton' . DIRECTORY_SEPARATOR . 'module' . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'actionsTest.php', sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . $arguments['application'] . DIRECTORY_SEPARATOR . $arguments['module'] . 'ActionsTest.php'); // customize test file $this->getFilesystem()->replaceTokens(sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . $arguments['application'] . DIRECTORY_SEPARATOR . $arguments['module'] . 'ActionsTest.php', '##', '##', $this->constants); // delete temp files $this->getFilesystem()->remove(sfFinder::type('any')->in($tmpDir)); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('doctrine', 'generating form classes'); $databaseManager = new sfDatabaseManager($this->configuration); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate($options['generator-class'], array( 'model_dir_name' => $options['model-dir-name'], 'form_dir_name' => $options['form-dir-name'], )); $properties = parse_ini_file(sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'properties.ini', true); $constants = array( 'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here' ); // customize php and yml files $finder = sfFinder::type('file')->name('*.php'); $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir').'/form/'), '##', '##', $constants); // check for base form class if (!class_exists('BaseForm')) { $file = sfConfig::get('sf_lib_dir').'/'.$options['form-dir-name'].'/BaseForm.class.php'; $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir').'/task/generator/skeleton/project/lib/form/BaseForm.class.php', $file); $this->getFilesystem()->replaceTokens($file, '##', '##', $constants); } $this->reloadAutoload(); }
public function setUp() { // generate this form $generatorManager = new sfGeneratorManager(ProjectConfiguration::getApplicationConfiguration('backend', 'dev', true)); $generatorManager->generate('sfDoctrineFormGenerator', array('connection' => 'doctrine', 'model_dir_name' => 'model', 'form_dir_name' => 'form')); $generator = new CommentFormGenerator($generatorManager); $generator->generate(array('connection' => 'doctrine')); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $buildModel = new sfDoctrineBuildModelTask($this->dispatcher, $this->formatter); $buildModel->setCommandApplication($this->commandApplication); $buildModel->run(); $this->logSection('doctrine', 'generating form classes'); $databaseManager = new sfDatabaseManager($this->configuration); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate('sfDoctrineFormGenerator', array('connection' => $options['connection'], 'model_dir_name' => $options['model-dir-name'], 'form_dir_name' => $options['form-dir-name'])); }
public static function getContent(sfGeneratorManager $generatorManager, $class, $parameters) { $data = ''; // needed to maintain BC with the 1.0 admin generator $r = new ReflectionClass($class); if (class_exists('sfPropelAdminGenerator') && ('sfPropelAdminGenerator' == $class || $r->isSubclassOf(new ReflectionClass('sfPropelAdminGenerator'))) || class_exists('sfDoctrineAdminGenerator') && ('sfDoctrineAdminGenerator' == $class || $r->isSubclassOf(new ReflectionClass('sfDoctrineAdminGenerator')))) { $data .= "require sfConfig::get('sf_symfony_lib_dir').'/plugins/sfCompat10Plugin/config/config.php';\n"; } $data .= $generatorManager->generate($class, $parameters); return $data; }
public function customizeGenerator($params) { $params['model_class'] = 'Article'; $params['moduleName'] = $this->moduleName; sfToolkit::clearDirectory(sfConfig::get('sf_cache_dir')); $generatorManager = new sfGeneratorManager(); $generatorManager->initialize(); mkdir(sfConfig::get('sf_config_cache_dir'), 0777); file_put_contents(sprintf('%s/modules_%s_config_generator.yml.php', sfConfig::get('sf_config_cache_dir'), $this->moduleName), '<?php ' . $generatorManager->generate('sfPropelAdminGenerator', $params)); return $this; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('propel', 'generating form classes'); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate('sfPropelFormGenerator', array('connection' => $options['connection'], 'model_dir_name' => $options['model-dir-name'], 'form_dir_name' => $options['form-dir-name'])); $properties = parse_ini_file(sfConfig::get('sf_config_dir') . DIRECTORY_SEPARATOR . 'properties.ini', true); $constants = array('PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here'); // customize php and yml files $finder = sfFinder::type('file')->name('*.php'); $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir') . '/form/'), '##', '##', $constants); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('doctrine', 'generating filter form classes'); $databaseManager = new sfDatabaseManager($this->configuration); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate($options['generator-class'], array('model_dir_name' => $options['model-dir-name'], 'filter_dir_name' => $options['filter-dir-name'])); $properties = parse_ini_file(sfConfig::get('sf_config_dir') . DIRECTORY_SEPARATOR . 'properties.ini', true); $constants = array('PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Karina Garcia, Dario Chuquilla'); // customize php and yml files $finder = sfFinder::type('file')->name('*.php'); $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir') . '/filter/'), '##', '##', $constants); $this->reloadAutoload(); }
/** * Execute task * * @param array $arguments Task arguments [optional] * @param array $options Task options [optional] */ protected function execute($arguments = array(), $options = array()) { $this->logSection('doctrine', 'generating form classes'); $databaseManager = new sfDatabaseManager($this->configuration); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate($options['generator-class'], array('model_dir_name' => $options['model-dir-name'], 'form_dir_name' => $options['form-dir-name'])); if (!class_exists('BaseForm')) { $file = sfConfig::get('sf_lib_dir') . '/' . $options['form-dir-name'] . '/BaseForm.php'; ob_start(); require sfConfig::get('sf_plugins_dir') . '/dinDoctrineExtraPlugin/data/generator/skeleton/form/default/template/dinBaseFormTemplate.php'; file_put_contents($file, str_replace(array('[?php', '[?=', '?]'), array('<?php', '<?php echo', '?>'), ob_get_clean())); } $this->reloadAutoload(); }
public static function getContent(sfGeneratorManager $generatorManager, $class, $parameters) { $data = ''; // TODO: remove when the admin generator is moved to the new form framework $r = new ReflectionClass($class); if ('sfPropelAdminGenerator' == $class || $r->isSubclassOf(new ReflectionClass('sfPropelAdminGenerator'))) { $data .= <<<EOF sfConfig::set('sf_compat_10', true); require sfConfig::get('sf_symfony_lib_dir').'/plugins/sfCompat10Plugin/config/config.php'; EOF; } $data .= $generatorManager->generate($class, $parameters); return $data; }
/** * Reloads the autoloader. * * @param string $class * * @return boolean */ public function autoload($class) { if (substr($class, -strlen(self::EXTENSION)) == self::EXTENSION) { // this is a request for a decorator class // the class does not exist yet (otherwise it would have been loaded by sfSimpleAutoload) // so generate the class first and then include it // TODO: make a log entry that the decorator is generated $decoratedClass = substr($class, 0, strlen($class) - strlen(self::EXTENSION)); if (class_exists($decoratedClass)) { $generatorManager = new sfGeneratorManager(self::$configuration); eval($generatorManager->generate('sfDecoratorGenerator', array('decorated_class' => $decoratedClass, 'generated_class' => $class))); return true; } } return false; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('doctrine', 'generating form classes'); $databaseManager = new sfDatabaseManager($this->configuration); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate('sfMmwExtjsDoctrineFormGenerator', array('connection' => $options['connection'], 'model_dir_name' => $options['model-dir-name'], 'form_dir_name' => $options['form-dir-name'], 'model' => $options['model'], 'theme' => 'mmwExtjs')); $properties = parse_ini_file(sfConfig::get('sf_config_dir') . DIRECTORY_SEPARATOR . 'properties.ini', true); $constants = array('PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here'); // customize php and yml files if (!empty($options['model']) && $options['model'] !== false) { $finder = sfFinder::type('file')->name($options['model'] . 'Form.class.php', 'Plugin' . $options['model'] . 'Form.class.php'); } else { $finder = sfFinder::type('file')->name('*.php'); } $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir') . '/form/'), '##', '##', $constants); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('propel', 'generating lucene indexes...'); $generatorManager = new sfGeneratorManager($this->configuration); $luceneableModels = $generatorManager->generate($options['generator-class'], array( 'connection' => $options['connection'] )); $databaseManager = new sfDatabaseManager($this->configuration); foreach ($luceneableModels as $luceneableModel) { $this->logSection('propel', sprintf('optimizing lucene index for %s model', $luceneableModel)); sfLuceneableToolkit::optimizeIndex($luceneableModel); } $this->logSection('propel', 'done...'); }
function run_propel_generate_crud($task, $args) { if (count($args) < 2) { throw new Exception('You must provide your module name.'); } if (count($args) < 3) { throw new Exception('You must provide your model class name.'); } $theme = isset($args[3]) ? $args[3] : 'default'; $app = $args[0]; $module = $args[1]; $model_class = $args[2]; $sf_root_dir = sfConfig::get('sf_root_dir'); // generate module $tmp_dir = $sf_root_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); sfConfig::set('sf_module_cache_dir', $tmp_dir); $generator_manager = new sfGeneratorManager(); $generator_manager->initialize(); $generator_manager->generate('sfPropelCrudGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme)); $moduleDir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module; // copy our generated module $finder = pakeFinder::type('any'); pake_mirror($finder, $tmp_dir . '/auto' . ucfirst($module), $moduleDir); // change module name pake_replace_tokens($moduleDir . '/actions/actions.class.php', getcwd(), '', '', array('auto' . ucfirst($module) => $module)); try { $author_name = $task->get_property('author', 'symfony'); } catch (pakeException $e) { $author_name = 'Your name here'; } $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name); // customize php and yml files $finder = pakeFinder::type('file')->name('*.php', '*.yml'); pake_replace_tokens($finder, $moduleDir, '##', '##', $constants); // create basic test pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/module/test/actionsTest.php', $sf_root_dir . '/test/functional/' . $app . '/' . $module . 'ActionsTest.php'); // customize test file pake_replace_tokens($module . 'ActionsTest.php', $sf_root_dir . '/test/functional/' . $app, '##', '##', $constants); // delete temp files $finder = pakeFinder::type('any'); pake_remove($finder, $tmp_dir); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); // generate module $tmpDir = sfConfig::get('sf_cache_dir') . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); sfConfig::set('sf_module_cache_dir', $tmpDir); $generatorManager = new sfGeneratorManager(sfProjectConfiguration::getActive()); $generatorManager->generate('sfDoctrineAdminGenerator', array('model_class' => $arguments['model'], 'moduleName' => $arguments['module'], 'theme' => $options['theme'])); $moduleDir = sfConfig::get('sf_apps_dir') . '/' . $arguments['application'] . '/modules/' . $arguments['module']; // copy our generated module $this->getFileSystem()->mirror($tmpDir . '/auto' . ucfirst($arguments['module']), $moduleDir, sfFinder::type('any')); // change module name $this->getFileSystem()->replaceTokens($moduleDir . '/actions/actions.class.php', '', '', array('auto' . ucfirst($arguments['module']) => $arguments['module'])); $constants = array('PROJECT_NAME' => 'symfony', 'APP_NAME' => $arguments['application'], 'MODULE_NAME' => $arguments['module'], 'MODEL_CLASS' => $arguments['model'], 'AUTHOR_NAME' => 'Your name here'); // customize php and yml files $finder = sfFinder::type('file')->name('*.php', '*.yml'); $this->getFileSystem()->replaceTokens($finder->in($moduleDir), '##', '##', $constants); // create basic test $this->getFileSystem()->copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/module/test/actionsTest.php', sfConfig::get('sf_root_dir') . '/test/functional/' . $arguments['application'] . '/' . $arguments['module'] . 'ActionsTest.php'); // customize test file $this->getFileSystem()->replaceTokens(sfConfig::get('sf_root_dir') . '/test/functional/' . $arguments['application'] . DIRECTORY_SEPARATOR . $arguments['module'] . 'ActionsTest.php', '##', '##', $constants); // delete temp files $this->getFileSystem()->remove(sfFinder::type('any')->in($tmpDir)); }
/** * Execute handler * * @param array $configFiles Configuration files * @return string Php code for configuration file */ public function execute($configFiles) { if (!($config = self::parseYamls($configFiles))) { return ''; } if (!isset($config['generator'])) { throw new sfParseException(sprintf('Configuration file "%s" must specify a generator section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0])); } $config = sfToolkit::arrayDeepMerge($this->getBaseConfig(), $config); $config = $this->configureI18nFields($this->configureSort($config['generator'])); if (!isset($config['class'])) { throw new sfParseException(sprintf('Configuration file "%s" must specify a generator class section under the generator section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0])); } foreach (array('fields', 'list', 'edit') as $section) { if (isset($config[$section])) { throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0], $section)); } } $generatorManager = new sfGeneratorManager(sfContext::getInstance()->getConfiguration()); $generatorParam = isset($config['param']) ? $config['param'] : array(); preg_match('#.*/modules/([^/]+)/#', str_replace('\\', '/', $configFiles[0]), $match); $generatorParam['moduleName'] = $match[1]; return sprintf("<?php\n// auto-generated by dinGeneratorConfigHandler\n// date: %s\n%s\n", date('Y/m/d H:i:s'), $generatorManager->generate($config['class'], $generatorParam)); }
protected function generate($type, $connection, $params) { $baseOptions = array('dispatcher' => $this->dispatcher, 'formatter' => $this->formatter); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate($this->generatorClass($connection, $type), array_merge($baseOptions, $params)); }
public static function getContent(sfGeneratorManager $generatorManager, $class, $parameters) { return $generatorManager->generate($class, $parameters); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('propel', 'generating form classes'); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate('sfPropelFormGenerator', array('connection' => $options['connection'], 'model_dir_name' => $options['model-dir-name'], 'form_dir_name' => $options['form-dir-name'])); }
function run_doctrine_generate_crud($task, $args) { if (count($args) < 2) { throw new Exception('You must provide your module name.'); } if (count($args) < 3) { throw new Exception('You must provide your model class name.'); } $app = $args[0]; $module = $args[1]; $model_class = $args[2]; $theme = isset($args[3]) ? $args[3] : 'crud'; // function variables $doctrineModelDir = sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR; $sf_root_dir = sfConfig::get('sf_root_dir'); $sf_symfony_lib_dir = sfConfig::get('sf_symfony_lib_dir'); $pluginDir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); $doctrineLibDir = $pluginDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR; $tmp_dir = $sf_root_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); sfConfig::set('sf_module_cache_dir', $tmp_dir); sfConfig::set('sf_app_dir', $tmp_dir); // add classes to autoload function pake_echo_action('PluginDir', $pluginDir); simpleAutoloader::registerCallable(array('Doctrine', 'autoload')); // generate module $generator_manager = new sfGeneratorManager(); $generator_manager->initialize(); $generator_manager->generate('sfDoctrineAdminGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme)); $moduleDir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module; // copy our generated module $finder = pakeFinder::type('any'); pake_mirror($finder, $tmp_dir . '/auto' . ucfirst($module), $moduleDir); // change module name pake_replace_tokens($moduleDir . '/actions/actions.class.php', getcwd(), '', '', array('auto' . ucfirst($module) => $module)); try { $author_name = $task->get_property('author', 'symfony'); } catch (pakeException $e) { $author_name = 'Your name here'; } $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name); // customize php files $finder = pakeFinder::type('file')->name('*.php'); pake_replace_tokens($finder, $moduleDir, '##', '##', $constants); // delete temp files $finder = pakeFinder::type('any'); pake_remove($finder, $tmp_dir); // for some reason the above does not remove the tmp dir as it should. // delete temp dir @rmdir($tmp_dir); // delete cache/tmp @rmdir(sfConfig::get('sf_cache_dir') . 'tmp'); }