sfGenerateProjectTask.class.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. require_once(dirname(__FILE__).'/sfGeneratorBaseTask.class.php');
  10. /**
  11. * Generates a new project.
  12. *
  13. * @package symfony
  14. * @subpackage task
  15. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  16. * @version SVN: $Id: sfGenerateProjectTask.class.php 13588 2008-12-01 13:53:09Z Kris.Wallsmith $
  17. */
  18. class sfGenerateProjectTask extends sfGeneratorBaseTask
  19. {
  20. /**
  21. * @see sfTask
  22. */
  23. protected function doRun(sfCommandManager $commandManager, $options)
  24. {
  25. $this->process($commandManager, $options);
  26. return $this->execute($commandManager->getArgumentValues(), $commandManager->getOptionValues());
  27. }
  28. /**
  29. * @see sfTask
  30. */
  31. protected function configure()
  32. {
  33. $this->addArguments(array(
  34. new sfCommandArgument('name', sfCommandArgument::REQUIRED, 'The project name'),
  35. ));
  36. $this->aliases = array('init-project');
  37. $this->namespace = 'generate';
  38. $this->name = 'project';
  39. $this->briefDescription = 'Generates a new project';
  40. $this->detailedDescription = <<<EOF
  41. The [generate:project|INFO] task creates the basic directory structure
  42. for a new project in the current directory:
  43. [./symfony generate:project blog|INFO]
  44. If the current directory already contains a symfony project,
  45. it throws a [sfCommandException|COMMENT].
  46. EOF;
  47. }
  48. /**
  49. * @see sfTask
  50. */
  51. protected function execute($arguments = array(), $options = array())
  52. {
  53. if (file_exists('symfony'))
  54. {
  55. throw new sfCommandException(sprintf('A project named "%s" already exists in this directory.', $arguments['name']));
  56. }
  57. // create basic project structure
  58. $finder = sfFinder::type('any')->discard('.sf');
  59. $this->getFilesystem()->mirror(dirname(__FILE__).'/skeleton/project', sfConfig::get('sf_root_dir'), $finder);
  60. // update project name and directory
  61. $finder = sfFinder::type('file')->name('properties.ini', 'apache.conf', 'propel.ini', 'databases.yml');
  62. $this->getFileSystem()->replaceTokens($finder->in(sfConfig::get('sf_config_dir')), '##', '##', array('PROJECT_NAME' => $arguments['name'], 'PROJECT_DIR' => sfConfig::get('sf_root_dir')));
  63. // update ProjectConfiguration class
  64. $this->getFileSystem()->replaceTokens(sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php', '##', '##', array('SYMFONY_LIB_DIR' => sfConfig::get('sf_symfony_lib_dir')));
  65. // update vhost sample file
  66. $this->getFileSystem()->replaceTokens(sfConfig::get('sf_config_dir').'/vhost.sample', '##', '##', array('PROJECT_NAME' => $arguments['name'], 'SYMFONY_WEB_DIR' => sfConfig::get('sf_web_dir'), 'SYMFONY_SF_DIR' => realpath(sfCoreAutoload::getInstance()->getBaseDir().'../data/web/sf')));
  67. // fix permission for common directories
  68. $fixPerms = new sfProjectPermissionsTask($this->dispatcher, $this->formatter);
  69. $fixPerms->setCommandApplication($this->commandApplication);
  70. $fixPerms->run();
  71. // publish assets for core plugins
  72. $publishAssets = new sfPluginPublishAssetsTask($this->dispatcher, $this->formatter);
  73. $publishAssets->setCommandApplication($this->commandApplication);
  74. $publishAssets->run(array(), array('--core-only'));
  75. }
  76. }