[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/data/tasks/ -> sfPakePropelCrudGenerator.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the symfony package.
   5   * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
   6   * 
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  pake_desc('initialize a new propel CRUD module');
  12  pake_task('propel-init-crud', 'app_exists');
  13  
  14  pake_desc('generate a new propel CRUD module');
  15  pake_task('propel-generate-crud', 'app_exists');
  16  
  17  function run_propel_init_crud($task, $args)
  18  {
  19    if (count($args) < 2)
  20    {
  21      throw new Exception('You must provide your module name.');
  22    }
  23  
  24    if (count($args) < 3)
  25    {
  26      throw new Exception('You must provide your model class name.');
  27    }
  28  
  29    $app         = $args[0];
  30    $module      = $args[1];
  31    $model_class = $args[2];
  32  
  33    try
  34    {
  35      $author_name = $task->get_property('author', 'symfony');
  36    }
  37    catch (pakeException $e)
  38    {
  39      $author_name = 'Your name here';
  40    }
  41  
  42    $constants = array(
  43      'PROJECT_NAME' => $task->get_property('name', 'symfony'),
  44      'APP_NAME'     => $app,
  45      'MODULE_NAME'  => $module,
  46      'MODEL_CLASS'  => $model_class,
  47      'AUTHOR_NAME'  => $author_name,
  48    );
  49  
  50    $sf_root_dir = sfConfig::get('sf_root_dir');
  51    $moduleDir   = $sf_root_dir.'/'.sfConfig::get('sf_apps_dir_name').'/'.$app.'/'.sfConfig::get('sf_app_module_dir_name').'/'.$module;
  52  
  53    // create basic application structure
  54    $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
  55    pake_mirror($finder, sfConfig::get('sf_symfony_data_dir').'/generator/sfPropelCrud/default/skeleton', $moduleDir);
  56  
  57    // create basic test
  58    pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/module/test/actionsTest.php', $sf_root_dir.'/test/functional/'.$app.'/'.$module.'ActionsTest.php');
  59  
  60    // customize test file
  61    pake_replace_tokens($module.'ActionsTest.php', $sf_root_dir.'/test/functional/'.$app, '##', '##', $constants);
  62  
  63    // customize php and yml files
  64    $finder = pakeFinder::type('file')->name('*.php', '*.yml');
  65    pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
  66  }
  67  
  68  function run_propel_generate_crud($task, $args)
  69  {
  70    if (count($args) < 2)
  71    {
  72      throw new Exception('You must provide your module name.');
  73    }
  74  
  75    if (count($args) < 3)
  76    {
  77      throw new Exception('You must provide your model class name.');
  78    }
  79  
  80    $theme = isset($args[3]) ? $args[3] : 'default';
  81  
  82    $app         = $args[0];
  83    $module      = $args[1];
  84    $model_class = $args[2];
  85  
  86    $sf_root_dir = sfConfig::get('sf_root_dir');
  87  
  88    // generate module
  89    $tmp_dir = $sf_root_dir.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.md5(uniqid(rand(), true));
  90    sfConfig::set('sf_module_cache_dir', $tmp_dir);
  91    $generator_manager = new sfGeneratorManager();
  92    $generator_manager->initialize();
  93    $generator_manager->generate('sfPropelCrudGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme));
  94  
  95    $moduleDir = $sf_root_dir.'/'.sfConfig::get('sf_apps_dir_name').'/'.$app.'/'.sfConfig::get('sf_app_module_dir_name').'/'.$module;
  96  
  97    // copy our generated module
  98    $finder = pakeFinder::type('any');
  99    pake_mirror($finder, $tmp_dir.'/auto'.ucfirst($module), $moduleDir);
 100  
 101    // change module name
 102    pake_replace_tokens($moduleDir.'/actions/actions.class.php', getcwd(), '', '', array('auto'.ucfirst($module) => $module));
 103  
 104    try
 105    {
 106      $author_name = $task->get_property('author', 'symfony');
 107    }
 108    catch (pakeException $e)
 109    {
 110      $author_name = 'Your name here';
 111    }
 112  
 113    $constants = array(
 114      'PROJECT_NAME' => $task->get_property('name', 'symfony'),
 115      'APP_NAME'     => $app,
 116      'MODULE_NAME'  => $module,
 117      'MODEL_CLASS'  => $model_class,
 118      'AUTHOR_NAME'  => $author_name,
 119    );
 120  
 121    // customize php and yml files
 122    $finder = pakeFinder::type('file')->name('*.php', '*.yml');
 123    pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
 124  
 125    // create basic test
 126    pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/module/test/actionsTest.php', $sf_root_dir.'/test/functional/'.$app.'/'.$module.'ActionsTest.php');
 127  
 128    // customize test file
 129    pake_replace_tokens($module.'ActionsTest.php', $sf_root_dir.'/test/functional/'.$app, '##', '##', $constants);
 130  
 131    // delete temp files
 132    $finder = pakeFinder::type('any');
 133    pake_remove($finder, $tmp_dir);
 134  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7