sfSymfonyCommandApplication.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. /**
  10. * sfSymfonyCommandApplication manages the symfony CLI.
  11. *
  12. * @package symfony
  13. * @subpackage command
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfSymfonyCommandApplication.class.php 12499 2008-10-31 16:10:07Z Kris.Wallsmith $
  16. */
  17. class sfSymfonyCommandApplication extends sfCommandApplication
  18. {
  19. /**
  20. * Configures the current symfony command application.
  21. */
  22. public function configure()
  23. {
  24. if (!isset($this->options['symfony_lib_dir']))
  25. {
  26. throw new sfInitializationException('You must pass a "symfony_lib_dir" option.');
  27. }
  28. $configurationFile = getcwd().'/config/ProjectConfiguration.class.php';
  29. if (is_readable($configurationFile))
  30. {
  31. require_once $configurationFile;
  32. $configuration = new ProjectConfiguration(getcwd(), $this->dispatcher);
  33. }
  34. else
  35. {
  36. $configuration = new sfProjectConfiguration(getcwd(), $this->dispatcher);
  37. }
  38. // application
  39. $this->setName('symfony');
  40. $this->setVersion(SYMFONY_VERSION);
  41. $this->loadTasks($configuration);
  42. }
  43. /**
  44. * Runs the current application.
  45. *
  46. * @param mixed $options The command line options
  47. */
  48. public function run($options = null)
  49. {
  50. $this->handleOptions($options);
  51. $arguments = $this->commandManager->getArgumentValues();
  52. if (!isset($arguments['task']))
  53. {
  54. $arguments['task'] = 'list';
  55. $this->commandOptions .= $arguments['task'];
  56. }
  57. $this->currentTask = $this->getTaskToExecute($arguments['task']);
  58. if ($this->currentTask instanceof sfCommandApplicationTask)
  59. {
  60. $this->currentTask->setCommandApplication($this);
  61. }
  62. $ret = $this->currentTask->runFromCLI($this->commandManager, $this->commandOptions);
  63. $this->currentTask = null;
  64. return $ret;
  65. }
  66. /**
  67. * Loads all available tasks.
  68. *
  69. * Looks for tasks in the symfony core, the current project and all project plugins.
  70. *
  71. * @param sfProjectConfiguration $configuration The project configuration
  72. */
  73. protected function loadTasks(sfProjectConfiguration $configuration)
  74. {
  75. // Symfony core tasks
  76. $dirs = array(sfConfig::get('sf_symfony_lib_dir').'/task');
  77. // Plugin tasks
  78. foreach ($configuration->getPluginPaths() as $path)
  79. {
  80. if (is_dir($taskPath = $path.'/lib/task'))
  81. {
  82. $dirs[] = $taskPath;
  83. }
  84. }
  85. // project tasks
  86. $dirs[] = sfConfig::get('sf_lib_dir').'/task';
  87. // require tasks
  88. $finder = sfFinder::type('file')->name('*Task.class.php');
  89. foreach ($finder->in($dirs) as $task)
  90. {
  91. require_once $task;
  92. }
  93. }
  94. /**
  95. * @see sfCommandApplication
  96. */
  97. public function getLongVersion()
  98. {
  99. return sprintf('%s version %s (%s)', $this->getName(), $this->formatter->format($this->getVersion(), 'INFO'), sfConfig::get('sf_symfony_lib_dir'))."\n";
  100. }
  101. }