-
Notifications
You must be signed in to change notification settings - Fork 885
Expand file tree
/
Copy pathPhinxApplication.php
More file actions
118 lines (104 loc) · 3.67 KB
/
Copy pathPhinxApplication.php
File metadata and controls
118 lines (104 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/
namespace Phinx\Console;
use Composer\InstalledVersions;
use Phinx\Console\Command\Breakpoint;
use Phinx\Console\Command\Create;
use Phinx\Console\Command\Init;
use Phinx\Console\Command\ListAliases;
use Phinx\Console\Command\Migrate;
use Phinx\Console\Command\Rollback;
use Phinx\Console\Command\SeedCreate;
use Phinx\Console\Command\SeedRun;
use Phinx\Console\Command\Status;
use Phinx\Console\Command\Test;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Phinx console application.
*/
class PhinxApplication extends Application
{
/**
* @var string The current application version as determined by the getVersion() function.
*/
private string $version;
/**
* Initialize the Phinx console application.
*/
public function __construct()
{
parent::__construct('Phinx by CakePHP - https://phinx.org.', $this->getVersion());
$this->addCommands([
new Init(),
new Create(),
new Migrate(),
new Rollback(),
new Status(),
new Breakpoint(),
new Test(),
new SeedCreate(),
new SeedRun(),
new ListAliases(),
]);
}
/**
* Setup default input definition.
*
* @return \Symfony\Component\Console\Input\InputDefinition the overridden input definition.
*/
protected function getDefaultInputDefinition(): InputDefinition
{
$definition = parent::getDefaultInputDefinition();
$definition->addOption(new InputOption('--configuration', '-c', InputOption::VALUE_REQUIRED, 'The configuration file to load'));
return $definition;
}
/**
* Runs the current application.
*
* @param \Symfony\Component\Console\Input\InputInterface $input An Input instance
* @param \Symfony\Component\Console\Output\OutputInterface $output An Output instance
* @return int 0 if everything went fine, or an error code
*/
public function doRun(InputInterface $input, OutputInterface $output): int
{
// always show the version information except when the user invokes the help
// command as that already does it
if ($input->hasParameterOption('--no-info') === false) {
if (($input->hasParameterOption(['--help', '-h']) !== false) || ($input->getFirstArgument() !== null && $input->getFirstArgument() !== 'list')) {
$output->writeln($this->getLongVersion());
$output->writeln('');
}
}
return parent::doRun($input, $output);
}
/**
* Get the current application version.
*
* @return string The application version if it could be found, otherwise 'UNKNOWN'
*/
public function getVersion(): string
{
if (isset($this->version)) {
return $this->version;
}
// humbug/box will replace this with actual version when building
// so use that if available
$gitTag = '@git_tag@';
if (!str_starts_with($gitTag, '@')) {
return $this->version = $gitTag;
}
// Otherwise fallback to the version as reported by composer
if (class_exists(InstalledVersions::class)) {
return $this->version = InstalledVersions::getPrettyVersion('robmorgan/phinx') ?? 'UNKNOWN';
}
return $this->version = 'UNKNOWN';
}
}