Application.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Console;
  11. use Symfony\Component\Console\Application as BaseApplication;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\HttpKernel\KernelInterface;
  16. use Symfony\Component\HttpKernel\Kernel;
  17. use Symfony\Component\HttpKernel\Bundle\Bundle;
  18. /**
  19. * Application.
  20. *
  21. * @author Fabien Potencier <fabien@symfony.com>
  22. */
  23. class Application extends BaseApplication
  24. {
  25. private $kernel;
  26. /**
  27. * Constructor.
  28. *
  29. * @param KernelInterface $kernel A KernelInterface instance
  30. */
  31. public function __construct(KernelInterface $kernel)
  32. {
  33. $this->kernel = $kernel;
  34. parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : ''));
  35. $this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.'));
  36. $this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'));
  37. $this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
  38. }
  39. /**
  40. * Gets the Kernel associated with this Console.
  41. *
  42. * @return KernelInterface A KernelInterface instance
  43. */
  44. public function getKernel()
  45. {
  46. return $this->kernel;
  47. }
  48. /**
  49. * Runs the current application.
  50. *
  51. * @param InputInterface $input An Input instance
  52. * @param OutputInterface $output An Output instance
  53. *
  54. * @return integer 0 if everything went fine, or an error code
  55. */
  56. public function doRun(InputInterface $input, OutputInterface $output)
  57. {
  58. $this->registerCommands();
  59. if (true === $input->hasParameterOption(array('--shell', '-s'))) {
  60. $shell = new Shell($this);
  61. $shell->run();
  62. return 0;
  63. }
  64. return parent::doRun($input, $output);
  65. }
  66. protected function registerCommands()
  67. {
  68. $this->kernel->boot();
  69. foreach ($this->kernel->getBundles() as $bundle) {
  70. if ($bundle instanceof Bundle) {
  71. $bundle->registerCommands($this);
  72. }
  73. }
  74. }
  75. }