/**
  * 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;
 }
Пример #2
0
 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');
 }
 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;
 }
Пример #4
0
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);
}
Пример #5
0
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');
}