1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Phinx |
4
|
|
|
* |
5
|
|
|
* (The MIT license) |
6
|
|
|
* Copyright (c) 2015 Rob Morgan |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated * documentation files (the "Software"), to |
10
|
|
|
* deal in the Software without restriction, including without limitation the |
11
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
12
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
16
|
|
|
* all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
23
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
24
|
|
|
* IN THE SOFTWARE. |
25
|
|
|
* |
26
|
|
|
* @author Richard Quadling |
27
|
|
|
* @package Phinx |
28
|
|
|
* @subpackage Phinx\Console |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
namespace Phinx\Console\Command; |
32
|
|
|
|
33
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
34
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
35
|
|
|
|
36
|
|
|
class ListAliases extends AbstractCommand |
37
|
|
|
{ |
38
|
|
|
protected static $defaultName = 'list:aliases'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
protected function configure() |
44
|
|
|
{ |
45
|
|
|
parent::configure(); |
46
|
|
|
|
47
|
|
|
$this->setDescription('List template class aliases') |
48
|
|
|
->setHelp('The <info>list:aliases</info> command lists the migration template generation class aliases'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* List migration template creation aliases. |
53
|
|
|
* |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
57
|
|
|
{ |
58
|
|
|
$this->bootstrap($input, $output); |
59
|
|
|
|
60
|
|
|
$aliases = $this->config->getAliases(); |
61
|
|
|
|
62
|
|
|
if ($aliases) { |
|
|
|
|
63
|
|
|
$maxAliasLength = max(array_map('strlen', array_keys($aliases))); |
64
|
|
|
$maxClassLength = max(array_map('strlen', $aliases)); |
65
|
|
|
$output->writeln( |
66
|
|
|
array_merge( |
|
|
|
|
67
|
|
|
[ |
68
|
|
|
'', |
69
|
|
|
sprintf('%s %s', str_pad('Alias', $maxAliasLength), str_pad('Class', $maxClassLength)), |
70
|
|
|
sprintf('%s %s', str_repeat('=', $maxAliasLength), str_repeat('=', $maxClassLength)), |
71
|
|
|
], |
72
|
|
|
array_map( |
73
|
|
|
function ($alias, $class) use ($maxAliasLength, $maxClassLength) { |
74
|
|
|
return sprintf('%s %s', str_pad($alias, $maxAliasLength), str_pad($class, $maxClassLength)); |
75
|
|
|
}, |
76
|
|
|
array_keys($aliases), |
77
|
|
|
$aliases |
78
|
|
|
) |
79
|
|
|
) |
80
|
|
|
); |
81
|
|
|
} else { |
82
|
|
|
$output->writeln( |
83
|
|
|
sprintf( |
84
|
|
|
'<error>No aliases defined in %s</error>', |
85
|
|
|
str_replace(getcwd(), '', realpath($this->config->getConfigFilePath())) |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return 0; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.