Application.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Symfony\Bundle\FrameworkBundle\Console;
  3. use Symfony\Components\Console\Application as BaseApplication;
  4. use Symfony\Components\Console\Input\InputInterface;
  5. use Symfony\Components\Console\Input\InputOption;
  6. use Symfony\Components\Console\Output\OutputInterface;
  7. use Symfony\Framework\Kernel;
  8. /*
  9. * This file is part of the Symfony framework.
  10. *
  11. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  12. *
  13. * This source file is subject to the MIT license that is bundled
  14. * with this source code in the file LICENSE.
  15. */
  16. /**
  17. * Application.
  18. *
  19. * @package Symfony
  20. * @subpackage Framework_FrameworkBundle
  21. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  22. */
  23. class Application extends BaseApplication
  24. {
  25. protected $kernel;
  26. /**
  27. * Constructor.
  28. */
  29. public function __construct(Kernel $kernel)
  30. {
  31. $this->kernel = $kernel;
  32. parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName());
  33. $this->definition->addOption(new InputOption('--shell', '-s', InputOption::PARAMETER_NONE, 'Launch the shell.'));
  34. if (!$this->kernel->isBooted()) {
  35. $this->kernel->boot();
  36. }
  37. $this->registerCommands();
  38. }
  39. /**
  40. * Gets the Kernel associated with this Console.
  41. *
  42. * @return Kernel A Kernel 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. if (true === $input->hasParameterOption(array('--shell', '-s'))) {
  59. $shell = new Shell($this);
  60. $shell->run();
  61. return 0;
  62. }
  63. return parent::doRun($input, $output);
  64. }
  65. protected function registerCommands()
  66. {
  67. foreach ($this->kernel->getBundles() as $bundle) {
  68. $bundle->registerCommands($this);
  69. }
  70. }
  71. }