Attribute
2 years ago
CI
2 years ago
Command
2 years ago
CommandLoader
2 years ago
Completion
2 years ago
DependencyInjection
2 years ago
Descriptor
2 years ago
Event
2 years ago
EventListener
2 years ago
Exception
2 years ago
Formatter
2 years ago
Helper
2 years ago
Input
2 years ago
Logger
2 years ago
Output
2 years ago
Question
2 years ago
Resources
2 years ago
SignalRegistry
2 years ago
Style
2 years ago
Tester
2 years ago
Application.php
2 years ago
Color.php
2 years ago
ConsoleEvents.php
2 years ago
Cursor.php
2 years ago
SingleCommandApplication.php
2 years ago
Terminal.php
2 years ago
SingleCommandApplication.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace IAWP_SCOPED\Symfony\Component\Console; |
| 12 | |
| 13 | use IAWP_SCOPED\Symfony\Component\Console\Command\Command; |
| 14 | use IAWP_SCOPED\Symfony\Component\Console\Input\InputInterface; |
| 15 | use IAWP_SCOPED\Symfony\Component\Console\Output\OutputInterface; |
| 16 | /** |
| 17 | * @author Grégoire Pineau <lyrixx@lyrixx.info> |
| 18 | * @internal |
| 19 | */ |
| 20 | class SingleCommandApplication extends Command |
| 21 | { |
| 22 | private $version = 'UNKNOWN'; |
| 23 | private $autoExit = \true; |
| 24 | private $running = \false; |
| 25 | /** |
| 26 | * @return $this |
| 27 | */ |
| 28 | public function setVersion(string $version) : self |
| 29 | { |
| 30 | $this->version = $version; |
| 31 | return $this; |
| 32 | } |
| 33 | /** |
| 34 | * @final |
| 35 | * |
| 36 | * @return $this |
| 37 | */ |
| 38 | public function setAutoExit(bool $autoExit) : self |
| 39 | { |
| 40 | $this->autoExit = $autoExit; |
| 41 | return $this; |
| 42 | } |
| 43 | public function run(InputInterface $input = null, OutputInterface $output = null) : int |
| 44 | { |
| 45 | if ($this->running) { |
| 46 | return parent::run($input, $output); |
| 47 | } |
| 48 | // We use the command name as the application name |
| 49 | $application = new Application($this->getName() ?: 'UNKNOWN', $this->version); |
| 50 | $application->setAutoExit($this->autoExit); |
| 51 | // Fix the usage of the command displayed with "--help" |
| 52 | $this->setName($_SERVER['argv'][0]); |
| 53 | $application->add($this); |
| 54 | $application->setDefaultCommand($this->getName(), \true); |
| 55 | $this->running = \true; |
| 56 | try { |
| 57 | $ret = $application->run($input, $output); |
| 58 | } finally { |
| 59 | $this->running = \false; |
| 60 | } |
| 61 | return $ret ?? 1; |
| 62 | } |
| 63 | } |
| 64 |