[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/data/tasks/ -> sfPakeGenerator.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 symfony project');
  12  pake_task('init-project');
  13  pake_alias('new', 'init-project');
  14  
  15  pake_desc('initialize a new symfony application');
  16  pake_task('init-app', 'project_exists');
  17  pake_alias('app', 'init-app');
  18  
  19  pake_desc('initialize a new symfony module');
  20  pake_task('init-module', 'app_exists');
  21  pake_alias('module', 'init-module');
  22  
  23  pake_desc('initialize a new symfony batch script');
  24  pake_task('init-batch', 'project_exists');
  25  pake_alias('batch', 'init-batch');
  26  
  27  pake_desc('initialize a new symfony controller script');
  28  pake_task('init-controller', 'app_exists');
  29  pake_alias('controller', 'init-controller');
  30  
  31  function run_init_project($task, $args)
  32  {
  33    if (file_exists('symfony'))
  34    {
  35      throw new Exception('A symfony project already exists in this directory.');
  36    }
  37  
  38    if (!count($args))
  39    {
  40      throw new Exception('You must provide a project name.');
  41    }
  42  
  43    $project_name = $args[0];
  44  
  45    $sf_root_dir = sfConfig::get('sf_root_dir');
  46  
  47    // create basic project structure
  48    $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
  49    pake_mirror($finder, sfConfig::get('sf_symfony_data_dir').'/skeleton/project', $sf_root_dir);
  50  
  51    $finder = pakeFinder::type('file')->name('properties.ini', 'apache.conf', 'propel.ini');
  52    pake_replace_tokens($finder, $sf_root_dir, '##', '##', array('PROJECT_NAME' => $project_name));
  53  
  54    $finder = pakeFinder::type('file')->name('propel.ini');
  55    pake_replace_tokens($finder, $sf_root_dir, '##', '##', array('PROJECT_DIR' => $sf_root_dir));
  56  
  57    // update config/config.php
  58    pake_replace_tokens('config.php', sfConfig::get('sf_config_dir'), '##', '##', array(
  59      'SYMFONY_LIB_DIR'  => sfConfig::get('sf_symfony_lib_dir'),
  60      'SYMFONY_DATA_DIR' => sfConfig::get('sf_symfony_data_dir'),
  61    ));
  62  
  63    run_fix_perms($task, $args);
  64  }
  65  
  66  function run_init_app($task, $args)
  67  {
  68    if (!count($args))
  69    {
  70      throw new Exception('You must provide your application name.');
  71    }
  72  
  73    $app = $args[0];
  74  
  75    $sf_root_dir = sfConfig::get('sf_root_dir');
  76    $app_dir = $sf_root_dir.'/'.sfConfig::get('sf_apps_dir_name').'/'.$app;
  77  
  78    if (is_dir($app_dir))
  79    {
  80      throw new Exception(sprintf('The directory "%s" already exists.', $app_dir));
  81    }
  82  
  83    // create basic application structure
  84    $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
  85    pake_mirror($finder, sfConfig::get('sf_symfony_data_dir').'/skeleton/app/app', $app_dir);
  86  
  87    // create $app.php or index.php if it is our first app
  88    $index_name = 'index';
  89    $first_app = file_exists(sfConfig::get('sf_web_dir').'/index.php') ? false : true;
  90    if (!$first_app)
  91    {
  92      $index_name = $app;
  93    }
  94  
  95    // set no_script_name value in settings.yml for production environment
  96    $finder = pakeFinder::type('file')->name('settings.yml');
  97    pake_replace_tokens($finder, $app_dir.'/'.sfConfig::get('sf_app_config_dir_name'), '##', '##', array('NO_SCRIPT_NAME' => ($first_app ? 'on' : 'off')));
  98  
  99    pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/app/web/index.php', sfConfig::get('sf_web_dir').'/'.$index_name.'.php');
 100    pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/app/web/index_dev.php', sfConfig::get('sf_web_dir').'/'.$app.'_dev.php');
 101  
 102    $finder = pakeFinder::type('file')->name($index_name.'.php', $app.'_dev.php');
 103    pake_replace_tokens($finder, sfConfig::get('sf_web_dir'), '##', '##', array('APP_NAME' => $app));
 104  
 105    run_fix_perms($task, $args);
 106  
 107    // create test dir
 108    pake_mkdirs($sf_root_dir.'/test/functional/'.$app);
 109  }
 110  
 111  function run_init_module($task, $args)
 112  {
 113    if (count($args) < 2)
 114    {
 115      throw new Exception('You must provide your module name.');
 116    }
 117  
 118    $app    = $args[0];
 119    $module = $args[1];
 120    $sf_root_dir = sfConfig::get('sf_root_dir');
 121    $module_dir  = $sf_root_dir.'/'.sfConfig::get('sf_apps_dir_name').'/'.$app.'/'.sfConfig::get('sf_app_module_dir_name').'/'.$module;
 122  
 123    if (is_dir($module_dir))
 124    {
 125      throw new Exception(sprintf('The directory "%s" already exists.', $module_dir));
 126    }
 127  
 128    try
 129    {
 130      $author_name = $task->get_property('author', 'symfony');
 131    }
 132    catch (pakeException $e)
 133    {
 134      $author_name = 'Your name here';
 135    }
 136  
 137    $constants = array(
 138      'PROJECT_NAME' => $task->get_property('name', 'symfony'),
 139      'APP_NAME'     => $app,
 140      'MODULE_NAME'  => $module,
 141      'AUTHOR_NAME'  => $author_name,
 142    );
 143  
 144    if (is_readable(sfConfig::get('sf_data_dir').'/skeleton/module'))
 145    {
 146      $sf_skeleton_dir = sfConfig::get('sf_data_dir').'/skeleton/module';
 147    }
 148    else
 149    {
 150      $sf_skeleton_dir = sfConfig::get('sf_symfony_data_dir').'/skeleton/module';
 151    }
 152  
 153    // create basic application structure
 154    $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
 155    pake_mirror($finder, $sf_skeleton_dir.'/module', $module_dir);
 156  
 157    // create basic test
 158    pake_copy($sf_skeleton_dir.'/test/actionsTest.php', $sf_root_dir.'/test/functional/'.$app.'/'.$module.'ActionsTest.php');
 159  
 160    // customize test file
 161    pake_replace_tokens($module.'ActionsTest.php', $sf_root_dir.'/test/functional/'.$app, '##', '##', $constants);
 162  
 163    // customize php and yml files
 164    $finder = pakeFinder::type('file')->name('*.php', '*.yml');
 165    pake_replace_tokens($finder, $module_dir, '##', '##', $constants);
 166  }
 167  
 168  function run_init_batch($task, $args)
 169  {
 170    // handling two required arguments (application and batch name)
 171    if (count($args) < 1)
 172    {
 173      throw new Exception('You must provide the batch skeleton name');
 174    }
 175  
 176    // TODO: add finder here to locate batch skeleton locally or in symfony dirs, and send path to skeletons function
 177    $batch = '_batch_'.$args[0];
 178  
 179    if (!function_exists($batch))
 180    {
 181      throw new Exception(sprintf('The specified batch "%s" does not exist.', $args[0]));
 182    }
 183  
 184    $batch($task, $args);
 185  
 186    if (!file_exists(sfConfig::get('sf_symfony_data_dir').'/skeleton/batch/'.$args[0].'.php'))
 187    {
 188      throw new Exception('The skeleton you specified could not be found.');
 189    }
 190  }
 191  
 192  function _batch_default($task, $args)
 193  {
 194    if (count($args) < 2)
 195    {
 196      throw new Exception('You must provide the destination script name');
 197    }
 198    if (count($args) < 3)
 199    {
 200      throw new Exception('You must provide the application name');
 201    }
 202  
 203    $batch = $args[1];
 204    $app   = $args[2];
 205  
 206    // handling two optional arguments (environment and debug)
 207    $env   = isset($args[3]) ? $args[3] : 'dev';
 208    $debug = isset($args[4]) ? $args[4] : true;
 209  
 210    $constants = array(
 211      'PROJECT_NAME' => $task->get_property('name', 'symfony'),
 212      'APP_NAME'     => $app,
 213      'BATCH_NAME'   => $batch,
 214      'ENV_NAME'     => $env,
 215      'DEBUG'        => (boolean) $debug,
 216    );
 217  
 218    $sf_bin_dir = sfConfig::get('sf_bin_dir');
 219  
 220    pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/batch/default.php', $sf_bin_dir.'/'.$batch.'.php');
 221    pake_replace_tokens($batch.'.php', $sf_bin_dir, '##', '##', $constants);
 222  }
 223  
 224  function _batch_rotate_log($task, $args)
 225  {
 226    if (count($args) < 2)
 227    {
 228      throw new Exception('You must provide the application');
 229    }
 230    if (count($args) < 3)
 231    {
 232      throw new Exception('You must provide the environment');
 233    }
 234  
 235    $app = $args[1];
 236    $env = $args[2];
 237    $batch = 'rotate_log_'.$app.'_'.$env;
 238  
 239    // handling two optional arguments (environment and debug)
 240    $env   = isset($args[3]) ? $args[3] : 'dev';
 241    $debug = isset($args[4]) ? $args[4] : true;
 242  
 243    $constants = array(
 244      'PROJECT_NAME' => $task->get_property('name', 'symfony'),
 245      'APP_NAME'     => $app,
 246      'BATCH_NAME'   => $batch,
 247      'ENV_NAME'     => $env,
 248      'DEBUG'        => (boolean) $debug,
 249    );
 250  
 251    $sf_bin_dir = sfConfig::get('sf_bin_dir');
 252  
 253    pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/batch/rotate_log.php', $sf_bin_dir.'/'.$batch.'.php');
 254    pake_replace_tokens($batch.'.php', $sf_bin_dir, '##', '##', $constants);
 255  }
 256  
 257  function run_init_controller($task, $args)
 258  {
 259    // handling two required arguments (application and batch name)
 260    if (count($args) < 2)
 261    {
 262      throw new Exception('You must provide the environment name');
 263    }
 264  
 265    $app = $args[0];
 266    $env = $args[1];
 267  
 268    // handling two optional arguments (environment and debug)
 269    $controller   = isset($args[2]) ? $args[2] : $app.'_'.$env;
 270    $debug        = isset($args[3]) ? $args[3] : true;
 271  
 272    $constants = array(
 273      'PROJECT_NAME'    => $task->get_property('name', 'symfony'),
 274      'APP_NAME'        => $app,
 275      'CONTROLLER_NAME' => $controller,
 276      'ENV_NAME'        => $env,
 277      'DEBUG'           => (boolean) $debug,
 278    );
 279  
 280    $sf_web_dir = sfConfig::get('sf_web_dir');
 281  
 282    pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/controller/controller.php', $sf_web_dir.'/'.$controller.'.php');
 283    pake_replace_tokens($controller.'.php', $sf_web_dir, '##', '##', $constants);
 284  }


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