Attribute
1 year ago
CI
1 year ago
Command
1 year ago
CommandLoader
2 years ago
Completion
1 year ago
DependencyInjection
1 year ago
Descriptor
1 year ago
Event
1 year ago
EventListener
2 years ago
Exception
2 years ago
Formatter
1 year ago
Helper
1 year ago
Input
1 year ago
Logger
1 year ago
Output
1 year ago
Question
1 year ago
Resources
1 year ago
SignalRegistry
1 year ago
Style
1 year ago
Tester
1 year ago
Application.php
1 year ago
Color.php
1 year ago
ConsoleEvents.php
2 years ago
Cursor.php
2 years ago
LICENSE
2 years ago
README.md
2 years ago
SingleCommandApplication.php
1 year ago
Terminal.php
1 year ago
SingleCommandApplication.php
63 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 Matomo\Dependencies\Symfony\Component\Console; |
| 12 | |
| 13 | use Matomo\Dependencies\Symfony\Component\Console\Command\Command; |
| 14 | use Matomo\Dependencies\Symfony\Component\Console\Input\InputInterface; |
| 15 | use Matomo\Dependencies\Symfony\Component\Console\Output\OutputInterface; |
| 16 | /** |
| 17 | * @author Grégoire Pineau <lyrixx@lyrixx.info> |
| 18 | */ |
| 19 | class SingleCommandApplication extends Command |
| 20 | { |
| 21 | private $version = 'UNKNOWN'; |
| 22 | private $autoExit = \true; |
| 23 | private $running = \false; |
| 24 | /** |
| 25 | * @return $this |
| 26 | */ |
| 27 | public function setVersion(string $version) : self |
| 28 | { |
| 29 | $this->version = $version; |
| 30 | return $this; |
| 31 | } |
| 32 | /** |
| 33 | * @final |
| 34 | * |
| 35 | * @return $this |
| 36 | */ |
| 37 | public function setAutoExit(bool $autoExit) : self |
| 38 | { |
| 39 | $this->autoExit = $autoExit; |
| 40 | return $this; |
| 41 | } |
| 42 | public function run(?InputInterface $input = null, ?OutputInterface $output = null) : int |
| 43 | { |
| 44 | if ($this->running) { |
| 45 | return parent::run($input, $output); |
| 46 | } |
| 47 | // We use the command name as the application name |
| 48 | $application = new Application($this->getName() ?: 'UNKNOWN', $this->version); |
| 49 | $application->setAutoExit($this->autoExit); |
| 50 | // Fix the usage of the command displayed with "--help" |
| 51 | $this->setName($_SERVER['argv'][0]); |
| 52 | $application->add($this); |
| 53 | $application->setDefaultCommand($this->getName(), \true); |
| 54 | $this->running = \true; |
| 55 | try { |
| 56 | $ret = $application->run($input, $output); |
| 57 | } finally { |
| 58 | $this->running = \false; |
| 59 | } |
| 60 | return $ret ?? 1; |
| 61 | } |
| 62 | } |
| 63 |