Changeset 19116
- Timestamp:
- 06/10/09 15:43:17 (9 months ago)
- Files:
-
- branches/1.3/data/bin/create_sandbox.sh (modified) (2 diffs)
- branches/1.3/data/bin/sandbox_installer.php (added)
- branches/1.3/data/bin/sandbox_skeleton (added)
- branches/1.3/data/bin/sandbox_skeleton/README (moved) (moved from branches/1.3/data/bin/SANDBOX_README)
- branches/1.3/lib/command/sfCommandApplication.class.php (modified) (4 diffs)
- branches/1.3/lib/command/sfSymfonyCommandApplication.class.php (modified) (1 diff)
- branches/1.3/lib/plugins/sfDoctrinePlugin/config/installer.php (added)
- branches/1.3/lib/plugins/sfDoctrinePlugin/config/skeleton (added)
- branches/1.3/lib/plugins/sfDoctrinePlugin/config/skeleton/config (added)
- branches/1.3/lib/plugins/sfDoctrinePlugin/config/skeleton/config/databases.yml (added)
- branches/1.3/lib/plugins/sfDoctrinePlugin/config/skeleton/config/doctrine (added)
- branches/1.3/lib/plugins/sfDoctrinePlugin/config/skeleton/config/doctrine/schema.yml (added)
- branches/1.3/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineConfigureDatabaseTask.class.php (added)
- branches/1.3/lib/plugins/sfPropelPlugin/config/installer.php (added)
- branches/1.3/lib/plugins/sfPropelPlugin/config/skeleton (added)
- branches/1.3/lib/plugins/sfPropelPlugin/config/skeleton/config (added)
- branches/1.3/lib/plugins/sfPropelPlugin/config/skeleton/config/databases.yml (moved) (moved from branches/1.3/lib/task/generator/skeleton/project/config/databases.yml)
- branches/1.3/lib/plugins/sfPropelPlugin/config/skeleton/config/propel.ini (moved) (moved from branches/1.3/lib/task/generator/skeleton/project/config/propel.ini)
- branches/1.3/lib/plugins/sfPropelPlugin/config/skeleton/config/schema.yml (moved) (moved from branches/1.3/lib/task/generator/skeleton/project/config/schema.yml)
- branches/1.3/lib/plugins/sfPropelPlugin/lib/task/sfPropelConfigureDatabaseTask.class.php (moved) (moved from branches/1.3/lib/task/configure/sfConfigureDatabaseTask.class.php) (3 diffs)
- branches/1.3/lib/task/generator/sfGenerateProjectTask.class.php (modified) (3 diffs)
- branches/1.3/lib/task/generator/skeleton/project/config/ProjectConfiguration.class.php (modified) (1 diff)
- branches/1.3/lib/task/generator/skeleton/project/config/properties.ini (modified) (1 diff)
- branches/1.3/lib/task/sfTask.class.php (modified) (2 diffs)
- branches/1.3/test/other/tasksTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.3/data/bin/create_sandbox.sh
r17795 r19116 1 1 #!/bin/sh 2 2 3 # creates a symfonysandbox for this symfony version3 # Creates a sandbox for this symfony version 4 4 5 5 echo ">>> sandbox initialization" 6 6 DIR=`pwd`/`dirname $0` 7 7 SANDBOX_NAME=sf_sandbox 8 APP_NAME=frontend9 8 PHP=php 10 9 … … 18 17 19 18 echo ">>> 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 45 20 46 21 echo ">>> create archives" branches/1.3/lib/command/sfCommandApplication.class.php
r18728 r19116 106 106 } 107 107 108 public function clearTasks() 109 { 110 $this->tasks = array(); 111 } 112 108 113 /** 109 114 * Registers an array of task objects. … … 117 122 if (is_null($tasks)) 118 123 { 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(); 128 125 } 129 126 … … 157 154 $this->tasks[$alias] = $task; 158 155 } 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; 159 176 } 160 177 … … 415 432 * @return sfTask A sfTask object 416 433 */ 417 p rotectedfunction getTaskToExecute($name)434 public function getTaskToExecute($name) 418 435 { 419 436 // namespace branches/1.3/lib/command/sfSymfonyCommandApplication.class.php
r18734 r19116 86 86 * @param sfProjectConfiguration $configuration The project configuration 87 87 */ 88 p rotectedfunction loadTasks(sfProjectConfiguration $configuration)88 public function loadTasks(sfProjectConfiguration $configuration) 89 89 { 90 90 // Symfony core tasks branches/1.3/lib/plugins/sfPropelPlugin/lib/task/sfPropelConfigureDatabaseTask.class.php
r14965 r19116 10 10 11 11 /** 12 * Generates a new application.12 * Configures the database connection. 13 13 * 14 14 * @package symfony … … 17 17 * @version SVN: $Id$ 18 18 */ 19 class sf ConfigureDatabaseTask extends sfBaseTask19 class sfPropelConfigureDatabaseTask extends sfBaseTask 20 20 { 21 21 /** … … 59 59 You can also specify the connection name and the database class name: 60 60 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] 62 62 63 63 WARNING: 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 40 40 )); 41 41 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 42 47 $this->aliases = array('init-project'); 43 48 $this->namespace = 'generate'; … … 68 73 69 74 // 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'); 72 76 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'; 77 79 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 } 82 153 83 154 // update ProjectConfiguration class (use a relative path when the symfony core is nested within the project) … … 85 156 sprintf('dirname(__FILE__).\'/..%s/autoload/sfCoreAutoload.class.php\'', str_replace(sfConfig::get('sf_root_dir'), '', sfConfig::get('sf_symfony_lib_dir'))) : 86 157 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));88 158 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); 93 193 } 94 194 } branches/1.3/lib/task/generator/skeleton/project/config/ProjectConfiguration.class.php
r14695 r19116 9 9 { 10 10 // for compatibility / remove and enable only the plugins you want 11 $this->enableAllPluginsExcept(array('sf DoctrinePlugin', 'sfCompat10Plugin'));11 $this->enableAllPluginsExcept(array('sf##OTHER_ORM##Plugin', 'sfCompat10Plugin')); 12 12 } 13 13 } branches/1.3/lib/task/generator/skeleton/project/config/properties.ini
r500 r19116 1 1 [symfony] 2 2 name=##PROJECT_NAME## 3 orm=##ORM## branches/1.3/lib/task/sfTask.class.php
r18728 r19116 101 101 * Runs the task. 102 102 * 103 * @param array $arguments An array of arguments104 * @param array $options An array of options103 * @param array|string $arguments An array of arguments or a string representing the CLI arguments and options 104 * @param array $options An array of options 105 105 * 106 106 * @return integer 0 if everything went fine, or an error code … … 119 119 } 120 120 121 return $this->doRun($commandManager, i mplode(' ', array_merge($arguments, $options)));121 return $this->doRun($commandManager, is_string($arguments) ? $arguments : implode(' ', array_merge($arguments, $options))); 122 122 } 123 123 branches/1.3/test/other/tasksTest.php
r18746 r19116 79 79 80 80 // generate:* 81 $content = $c->execute_command('generate:project myproject ');81 $content = $c->execute_command('generate:project myproject --orm=Propel'); 82 82 $t->ok(file_exists($c->tmp_dir.DS.'symfony'), '"generate:project" installs the symfony CLI in root project directory'); 83 83

