Development

Changeset 19116

You must first sign up to be able to contribute.

Changeset 19116

Show
Ignore:
Timestamp:
06/10/09 15:43:17 (9 months ago)
Author:
fabien
Message:

[1.3] added a --installer option to the generate:project task, and added a --orm option to choose the ORM at project creation time

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.3/data/bin/create_sandbox.sh

    r17795 r19116  
    11#!/bin/sh 
    22 
    3 # creates a symfony sandbox for this symfony version 
     3# Creates a sandbox for this symfony version 
    44 
    55echo ">>> sandbox initialization" 
    66DIR=`pwd`/`dirname $0` 
    77SANDBOX_NAME=sf_sandbox 
    8 APP_NAME=frontend 
    98PHP=php 
    109 
     
    1817 
    1918echo ">>> create a new project and a new app" 
    20 ${PHP} lib/vendor/symfony/data/bin/symfony generate:project ${SANDBOX_NAME} 
    21 ${PHP} symfony generate:app ${APP_NAME} 
    22  
    23 echo ">>> add LICENSE" 
    24 cp ${DIR}/../../LICENSE LICENSE 
    25  
    26 echo ">>> add README" 
    27 cp ${DIR}/SANDBOX_README README 
    28  
    29 echo ">>> add symfony command line for windows users" 
    30 cp ${DIR}/symfony.bat symfony.bat 
    31  
    32 echo ">>> default to sqlite" 
    33 ${PHP} symfony configure:database "sqlite:%SF_DATA_DIR%/sandbox.db" 
    34  
    35 echo ">>> fix sqlite database permissions" 
    36 touch data/sandbox.db 
    37 chmod 777 data 
    38 chmod 777 data/sandbox.db 
    39  
    40 echo ">>> add some empty files in empty directories" 
    41 touch apps/${APP_NAME}/modules/.sf apps/${APP_NAME}/i18n/.sf 
    42 touch cache/.sf doc/.sf log/.sf plugins/.sf 
    43 touch test/unit/.sf test/functional/.sf test/functional/${APP_NAME}/.sf 
    44 touch web/images/.sf web/js/.sf web/uploads/assets/.sf 
     19${PHP} lib/vendor/symfony/data/bin/symfony generate:project ${SANDBOX_NAME} --installer=${DIR}/sandbox_installer.php 
    4520 
    4621echo ">>> create archives" 
  • branches/1.3/lib/command/sfCommandApplication.class.php

    r18728 r19116  
    106106  } 
    107107 
     108  public function clearTasks() 
     109  { 
     110    $this->tasks = array(); 
     111  } 
     112 
    108113  /** 
    109114   * Registers an array of task objects. 
     
    117122    if (is_null($tasks)) 
    118123    { 
    119       $tasks = array(); 
    120       foreach (get_declared_classes() as $class) 
    121       { 
    122         $r = new Reflectionclass($class); 
    123         if ($r->isSubclassOf('sfTask') && !$r->isAbstract()) 
    124         { 
    125           $tasks[] = new $class($this->dispatcher, $this->formatter); 
    126         } 
    127       } 
     124      $tasks = $this->autodiscoverTasks(); 
    128125    } 
    129126 
     
    157154      $this->tasks[$alias] = $task; 
    158155    } 
     156  } 
     157 
     158  /** 
     159   * Autodiscovers task classes. 
     160   * 
     161   * @return array An array of tasks instances 
     162   */ 
     163  public function autodiscoverTasks() 
     164  { 
     165    $tasks = array(); 
     166    foreach (get_declared_classes() as $class) 
     167    { 
     168      $r = new Reflectionclass($class); 
     169      if ($r->isSubclassOf('sfTask') && !$r->isAbstract()) 
     170      { 
     171        $tasks[] = new $class($this->dispatcher, $this->formatter); 
     172      } 
     173    } 
     174 
     175    return $tasks; 
    159176  } 
    160177 
     
    415432   * @return sfTask A sfTask object 
    416433   */ 
    417   protected function getTaskToExecute($name) 
     434  public function getTaskToExecute($name) 
    418435  { 
    419436    // namespace 
  • branches/1.3/lib/command/sfSymfonyCommandApplication.class.php

    r18734 r19116  
    8686   * @param sfProjectConfiguration $configuration The project configuration 
    8787   */ 
    88   protected function loadTasks(sfProjectConfiguration $configuration) 
     88  public function loadTasks(sfProjectConfiguration $configuration) 
    8989  { 
    9090    // Symfony core tasks 
  • branches/1.3/lib/plugins/sfPropelPlugin/lib/task/sfPropelConfigureDatabaseTask.class.php

    r14965 r19116  
    1010 
    1111/** 
    12  * Generates a new application. 
     12 * Configures the database connection. 
    1313 * 
    1414 * @package    symfony 
     
    1717 * @version    SVN: $Id$ 
    1818 */ 
    19 class sfConfigureDatabaseTask extends sfBaseTask 
     19class sfPropelConfigureDatabaseTask extends sfBaseTask 
    2020{ 
    2121  /** 
     
    5959You can also specify the connection name and the database class name: 
    6060 
    61   [./symfony configure:database --name=main --class=sfDoctrineDatabase mysql:host=localhost;dbname=example root|INFO] 
     61  [./symfony configure:database --name=main --class=ProjectDatabase mysql:host=localhost;dbname=example root|INFO] 
    6262 
    6363WARNING: The [propel.ini|COMMENT] file is also updated when you use a [Propel|COMMENT] database 
  • branches/1.3/lib/task/generator/sfGenerateProjectTask.class.php

    r19111 r19116  
    4040    )); 
    4141 
     42    $this->addOptions(array( 
     43      new sfCommandOption('orm', null, sfCommandOption::PARAMETER_REQUIRED, 'The ORM to use by default', 'Doctrine'), 
     44      new sfCommandOption('installer', null, sfCommandOption::PARAMETER_REQUIRED, 'An installer script to execute', null), 
     45    )); 
     46 
    4247    $this->aliases = array('init-project'); 
    4348    $this->namespace = 'generate'; 
     
    6873 
    6974    // create basic project structure 
    70     $finder = sfFinder::type('any')->discard('.sf'); 
    71     $this->getFilesystem()->mirror(dirname(__FILE__).'/skeleton/project', sfConfig::get('sf_root_dir'), $finder); 
     75    $this->installDir(dirname(__FILE__).'/skeleton/project'); 
    7276 
    73     $constants = array( 
    74       'PROJECT_NAME' => $arguments['name'], 
    75       'PROJECT_DIR'  => sfConfig::get('sf_root_dir'), 
    76     ); 
     77    // execute the choosen ORM installer script 
     78    include dirname(__FILE__).'/../../plugins/sf'.ucfirst(strtolower($options['orm'])).'Plugin/config/installer.php'; 
    7779 
    78     // update project name and directory 
    79     $finder = sfFinder::type('file')->name('properties.ini', 'apache.conf', 'propel.ini', 'databases.yml'); 
    80     $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_config_dir')), '##', '##', $constants); 
    81     $this->getFilesystem()->replaceTokens(sfFinder::type('file')->in(sfConfig::get('sf_lib_dir')), '##', '##', $constants); 
     80    $this->arguments = $arguments; 
     81    $this->options = $options; 
     82 
     83    $this->replaceTokens(); 
     84 
     85    // execute a custom installer 
     86    if ($options['installer'] && $this->commandApplication) 
     87    { 
     88      $this->reloadTasks(); 
     89 
     90      include $options['installer']; 
     91    } 
     92 
     93    // fix permission for common directories 
     94    $fixPerms = new sfProjectPermissionsTask($this->dispatcher, $this->formatter); 
     95    $fixPerms->setCommandApplication($this->commandApplication); 
     96    $fixPerms->run(); 
     97 
     98    $this->replaceTokens(); 
     99  } 
     100 
     101  /** 
     102   * Executes another task in the context of the current one. 
     103   * 
     104   * @param  string  $name      The name of the task to execute 
     105   * @param  array   $arguments An array of arguments to pass to the task 
     106   * @param  array   $options   An array of options to pass to the task 
     107   * 
     108   * @return Boolean The returned value of the task run() method 
     109   */ 
     110  protected function runTask($name, $arguments = array(), $options = array()) 
     111  { 
     112    if (is_null($this->commandApplication)) 
     113    { 
     114      throw new LogicException('No command application associated with this task yet.'); 
     115    } 
     116 
     117    $task = $this->commandApplication->getTaskToExecute($name); 
     118    $task->setCommandApplication($this->commandApplication); 
     119 
     120    return $task->run($arguments, $options); 
     121  } 
     122 
     123  /** 
     124   * Mirrors a directory structure inside the created project. 
     125   * 
     126   * @param string   $dir    The directory to mirror 
     127   * @param sfFinder $finder A sfFinder instance to use for the mirroring 
     128   */ 
     129  protected function installDir($dir, $finder = null) 
     130  { 
     131    if (is_null($finder)) 
     132    { 
     133      $finder = sfFinder::type('any')->discard('.sf'); 
     134    } 
     135 
     136    $this->getFilesystem()->mirror($dir, sfConfig::get('sf_root_dir'), $finder); 
     137  } 
     138 
     139  /** 
     140   * Replaces tokens in files contained in a given directory. 
     141   * 
     142   * If you don't pass a directory, it will replace in the config/ and lib/ directory. 
     143   * 
     144   * @param array $dirs   An array of directory where to do the replacement 
     145   * @param array $tokens An array of tokens to use 
     146   */ 
     147  protected function replaceTokens($dirs = array(), $tokens = array()) 
     148  { 
     149    if (!$dirs) 
     150    { 
     151      $dirs = array(sfConfig::get('sf_config_dir'), sfConfig::get('sf_lib_dir')); 
     152    } 
    82153 
    83154    // update ProjectConfiguration class (use a relative path when the symfony core is nested within the project) 
     
    85156      sprintf('dirname(__FILE__).\'/..%s/autoload/sfCoreAutoload.class.php\'', str_replace(sfConfig::get('sf_root_dir'), '', sfConfig::get('sf_symfony_lib_dir'))) : 
    86157      var_export(sfConfig::get('sf_symfony_lib_dir').'/autoload/sfCoreAutoload.class.php', true); 
    87     $this->getFilesystem()->replaceTokens(sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php', '##', '##', array('SYMFONY_CORE_AUTOLOAD' => $symfonyCoreAutoload)); 
    88158 
    89     // fix permission for common directories 
    90     $fixPerms = new sfProjectPermissionsTask($this->dispatcher, $this->formatter); 
    91     $fixPerms->setCommandApplication($this->commandApplication); 
    92     $fixPerms->run(); 
     159    $tokens = array_merge(array( 
     160      'ORM'                   => $this->options['orm'], 
     161      'OTHER_ORM'             => 'Doctrine' == $this->options['orm'] ? 'Propel' : 'Doctrine', 
     162      'PROJECT_NAME'          => $this->arguments['name'], 
     163      'PROJECT_DIR'           => sfConfig::get('sf_root_dir'), 
     164      'SYMFONY_CORE_AUTOLOAD' => $symfonyCoreAutoload, 
     165    ), $tokens); 
     166 
     167    $this->getFilesystem()->replaceTokens(sfFinder::type('file')->prune('vendor')->in($dirs), '##', '##', $tokens); 
     168  } 
     169 
     170  /** 
     171   * Reloads tasks. 
     172   * 
     173   * Useful when you install plugins with tasks and if you want to use them with the runTask() method. 
     174   */ 
     175  protected function reloadTasks() 
     176  { 
     177    $this->configuration = $this->createConfiguration(null, null); 
     178 
     179    $this->commandApplication->clearTasks(); 
     180    $this->commandApplication->loadTasks($this->configuration); 
     181 
     182    $tasks = array(); 
     183    foreach (get_declared_classes() as $class) 
     184    { 
     185      $r = new Reflectionclass($class); 
     186      if ($r->isSubclassOf('sfTask') && !$r->isAbstract() && false === strpos($class, 'Doctrine' == $this->options['orm'] ? 'Propel' : 'Doctrine')) 
     187      { 
     188        $tasks[] = new $class($this->dispatcher, $this->formatter); 
     189      } 
     190    } 
     191 
     192    $this->commandApplication->registerTasks($tasks); 
    93193  } 
    94194} 
  • branches/1.3/lib/task/generator/skeleton/project/config/ProjectConfiguration.class.php

    r14695 r19116  
    99  { 
    1010    // for compatibility / remove and enable only the plugins you want 
    11     $this->enableAllPluginsExcept(array('sfDoctrinePlugin', 'sfCompat10Plugin')); 
     11    $this->enableAllPluginsExcept(array('sf##OTHER_ORM##Plugin', 'sfCompat10Plugin')); 
    1212  } 
    1313} 
  • branches/1.3/lib/task/generator/skeleton/project/config/properties.ini

    r500 r19116  
    11[symfony] 
    22  name=##PROJECT_NAME## 
     3  orm=##ORM## 
  • branches/1.3/lib/task/sfTask.class.php

    r18728 r19116  
    101101   * Runs the task. 
    102102   * 
    103    * @param array $arguments  An array of argument
    104    * @param array $options    An array of options 
     103   * @param array|string $arguments  An array of arguments or a string representing the CLI arguments and option
     104   * @param array        $options    An array of options 
    105105   * 
    106106   * @return integer 0 if everything went fine, or an error code 
     
    119119    } 
    120120 
    121     return $this->doRun($commandManager, implode(' ', array_merge($arguments, $options))); 
     121    return $this->doRun($commandManager, is_string($arguments) ? $arguments : implode(' ', array_merge($arguments, $options))); 
    122122  } 
    123123 
  • branches/1.3/test/other/tasksTest.php

    r18746 r19116  
    7979 
    8080// generate:* 
    81 $content = $c->execute_command('generate:project myproject'); 
     81$content = $c->execute_command('generate:project myproject --orm=Propel'); 
    8282$t->ok(file_exists($c->tmp_dir.DS.'symfony'), '"generate:project" installs the symfony CLI in root project directory'); 
    8383 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.