* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once(dirname(__FILE__).'/sfGeneratorBaseTask.class.php'); /** * Generates a new project. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfGenerateProjectTask.class.php 30530 2010-08-04 16:38:41Z fabien $ */ class sfGenerateProjectTask extends sfGeneratorBaseTask { /** * @see sfTask */ protected function doRun(sfCommandManager $commandManager, $options) { $this->process($commandManager, $options); return $this->execute($commandManager->getArgumentValues(), $commandManager->getOptionValues()); } /** * @see sfTask */ protected function configure() { $this->addArguments(array( new sfCommandArgument('name', sfCommandArgument::REQUIRED, 'The project name'), new sfCommandArgument('author', sfCommandArgument::OPTIONAL, 'The project author', 'Your name here'), )); $this->addOptions(array( new sfCommandOption('orm', null, sfCommandOption::PARAMETER_REQUIRED, 'The ORM to use by default', 'Doctrine'), new sfCommandOption('installer', null, sfCommandOption::PARAMETER_REQUIRED, 'An installer script to execute', null), )); $this->namespace = 'generate'; $this->name = 'project'; $this->briefDescription = 'Generates a new project'; $this->detailedDescription = <<commandApplication && !file_exists($options['installer'])) { throw new InvalidArgumentException(sprintf('The installer "%s" does not exist.', $options['installer'])); } // clean orm option $options['orm'] = ucfirst(strtolower($options['orm'])); $this->arguments = $arguments; $this->options = $options; // create basic project structure $this->installDir(dirname(__FILE__).'/skeleton/project'); // update ProjectConfiguration class (use a relative path when the symfony core is nested within the project) $symfonyCoreAutoload = 0 === strpos(sfConfig::get('sf_symfony_lib_dir'), sfConfig::get('sf_root_dir')) ? sprintf('dirname(__FILE__).\'/..%s/autoload/sfCoreAutoload.class.php\'', str_replace(sfConfig::get('sf_root_dir'), '', sfConfig::get('sf_symfony_lib_dir'))) : var_export(sfConfig::get('sf_symfony_lib_dir').'/autoload/sfCoreAutoload.class.php', true); $this->replaceTokens(array(sfConfig::get('sf_config_dir')), array('SYMFONY_CORE_AUTOLOAD' => str_replace('\\', '/', $symfonyCoreAutoload))); $this->tokens = array( 'ORM' => $this->options['orm'], 'PROJECT_NAME' => $this->arguments['name'], 'AUTHOR_NAME' => $this->arguments['author'], 'PROJECT_DIR' => sfConfig::get('sf_root_dir'), ); $this->replaceTokens(); // execute the choosen ORM installer script if (in_array($options['orm'], array('Doctrine', 'Propel'))) { include dirname(__FILE__).'/../../plugins/sf'.$options['orm'].'Plugin/config/installer.php'; } // execute a custom installer if ($options['installer'] && $this->commandApplication) { if ($this->canRunInstaller($options['installer'])) { $this->reloadTasks(); include $options['installer']; } } // fix permission for common directories $fixPerms = new sfProjectPermissionsTask($this->dispatcher, $this->formatter); $fixPerms->setCommandApplication($this->commandApplication); $fixPerms->setConfiguration($this->configuration); $fixPerms->run(); $this->replaceTokens(); } protected function canRunInstaller($installer) { if (preg_match('#^(https?|ftps?)://#', $installer)) { if (ini_get('allow_url_fopen') === false) { $this->logSection('generate', sprintf('Cannot run remote installer "%s" because "allow_url_fopen" is off', $installer)); } if (ini_get('allow_url_include') === false) { $this->logSection('generate', sprintf('Cannot run remote installer "%s" because "allow_url_include" is off', $installer)); } return ini_get('allow_url_fopen') && ini_get('allow_url_include'); } return true; } }