These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of phpDocumentor. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @author Mike van Riel <[email protected]> |
||
9 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
10 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
11 | * @link http://phpdoc.org |
||
12 | */ |
||
13 | |||
14 | namespace phpDocumentor\Application\Console; |
||
15 | |||
16 | use PackageVersions\Versions; |
||
17 | use Symfony\Bundle\FrameworkBundle\Console\Application as BaseApplication; |
||
18 | use Symfony\Component\Console\Input\InputInterface; |
||
19 | use Symfony\Component\Console\Input\InputOption; |
||
20 | use Symfony\Component\HttpKernel\KernelInterface; |
||
21 | |||
22 | final class Application extends BaseApplication |
||
23 | { |
||
24 | const VERSION = '@package_version@'; |
||
25 | |||
26 | 4 | public function __construct(KernelInterface $kernel) |
|
27 | { |
||
28 | 4 | parent::__construct($kernel); |
|
29 | |||
30 | 4 | $this->setName('phpDocumentor'); |
|
31 | 4 | $this->setVersion($this->detectVersion()); |
|
32 | 4 | } |
|
33 | |||
34 | 2 | protected function getCommandName(InputInterface $input) |
|
35 | { |
||
36 | // the regular setDefaultCommand option does not allow for options and arguments; with this workaround |
||
37 | // we can have options and arguments when the first element in the argv options is not a recognized |
||
38 | // command name. |
||
39 | // We explicitly do not use the getFirstArgument of the $input variable since that skips options; we |
||
40 | // explicitly want to know if the first thing after the php filename is a known command! |
||
41 | 2 | if ((isset($_SERVER['argv'][1]) === false || $this->has($_SERVER['argv'][1]) === false)) { |
|
42 | 1 | return 'project:run'; |
|
43 | } |
||
44 | |||
45 | 1 | return $input->getFirstArgument(); |
|
46 | } |
||
47 | |||
48 | 1 | protected function getDefaultInputDefinition() |
|
49 | { |
||
50 | 1 | $inputDefinition = parent::getDefaultInputDefinition(); |
|
51 | |||
52 | 1 | $inputDefinition->addOption( |
|
53 | 1 | new InputOption( |
|
54 | 1 | 'config', |
|
55 | 1 | 'c', |
|
56 | 1 | InputOption::VALUE_OPTIONAL, |
|
57 | 1 | 'Location of a custom configuration file' |
|
58 | ) |
||
59 | ); |
||
60 | 1 | $inputDefinition->addOption( |
|
61 | 1 | new InputOption('log', null, InputOption::VALUE_OPTIONAL, 'Log file to write to') |
|
62 | ); |
||
63 | |||
64 | 1 | return $inputDefinition; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Returns the long version of the application. |
||
69 | * |
||
70 | * @return string The long application version |
||
71 | */ |
||
72 | 1 | public function getLongVersion(): string |
|
73 | { |
||
74 | 1 | return sprintf('%s <info>%s</info>', $this->getName(), $this->getVersion()); |
|
75 | } |
||
76 | |||
77 | 4 | private function detectVersion(): string |
|
78 | { |
||
79 | 4 | $version = static::VERSION; |
|
80 | 4 | if (static::VERSION === '@' . 'package_version' . '@') { //prevent replacing the version. |
|
81 | 4 | $version = trim(file_get_contents(__DIR__ . '/../../../../VERSION')); |
|
82 | try { |
||
83 | 4 | $version = 'v' . ltrim( |
|
84 | 4 | \Jean85\PrettyVersions::getVersion(Versions::ROOT_PACKAGE_NAME)->getPrettyVersion(), |
|
85 | 4 | 'v' |
|
86 | ); |
||
87 | } catch (\OutOfBoundsException $e) { |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
Loading history...
|
|||
88 | } |
||
89 | } |
||
90 | 4 | return $version; |
|
91 | } |
||
92 | } |
||
93 |