|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | /** |
4 | | - * This file is part of the CodeIgniter 4 framework. |
| 4 | + * This file is part of CodeIgniter 4 framework. |
5 | 5 | * |
6 | 6 | * (c) CodeIgniter Foundation <admin@codeigniter.com> |
7 | 7 | * |
8 | | - * For the full copyright and license information, please view the LICENSE |
9 | | - * file that was distributed with this source code. |
| 8 | + * For the full copyright and license information, please view |
| 9 | + * the LICENSE file that was distributed with this source code. |
10 | 10 | */ |
11 | 11 |
|
12 | 12 | namespace CodeIgniter\Commands\Utilities; |
|
22 | 22 | */ |
23 | 23 | class Publish extends BaseCommand |
24 | 24 | { |
25 | | - /** |
26 | | - * The group the command is lumped under |
27 | | - * when listing commands. |
28 | | - * |
29 | | - * @var string |
30 | | - */ |
31 | | - protected $group = 'CodeIgniter'; |
| 25 | + /** |
| 26 | + * The group the command is lumped under |
| 27 | + * when listing commands. |
| 28 | + * |
| 29 | + * @var string |
| 30 | + */ |
| 31 | + protected $group = 'CodeIgniter'; |
32 | 32 |
|
33 | | - /** |
34 | | - * The Command's name |
35 | | - * |
36 | | - * @var string |
37 | | - */ |
38 | | - protected $name = 'publish'; |
| 33 | + /** |
| 34 | + * The Command's name |
| 35 | + * |
| 36 | + * @var string |
| 37 | + */ |
| 38 | + protected $name = 'publish'; |
39 | 39 |
|
40 | | - /** |
41 | | - * The Command's short description |
42 | | - * |
43 | | - * @var string |
44 | | - */ |
45 | | - protected $description = 'Discovers and executes all predefined Publisher classes.'; |
| 40 | + /** |
| 41 | + * The Command's short description |
| 42 | + * |
| 43 | + * @var string |
| 44 | + */ |
| 45 | + protected $description = 'Discovers and executes all predefined Publisher classes.'; |
46 | 46 |
|
47 | | - /** |
48 | | - * The Command's usage |
49 | | - * |
50 | | - * @var string |
51 | | - */ |
52 | | - protected $usage = 'publish [<directory>]'; |
| 47 | + /** |
| 48 | + * The Command's usage |
| 49 | + * |
| 50 | + * @var string |
| 51 | + */ |
| 52 | + protected $usage = 'publish [<directory>]'; |
53 | 53 |
|
54 | | - /** |
55 | | - * The Command's arguments |
56 | | - * |
57 | | - * @var array<string, string> |
58 | | - */ |
59 | | - protected $arguments = [ |
60 | | - 'directory' => '[Optional] The directory to scan within each namespace. Default: "Publishers".', |
61 | | - ]; |
| 54 | + /** |
| 55 | + * The Command's arguments |
| 56 | + * |
| 57 | + * @var array<string, string> |
| 58 | + */ |
| 59 | + protected $arguments = [ |
| 60 | + 'directory' => '[Optional] The directory to scan within each namespace. Default: "Publishers".', |
| 61 | + ]; |
62 | 62 |
|
63 | | - /** |
64 | | - * the Command's Options |
65 | | - * |
66 | | - * @var array |
67 | | - */ |
68 | | - protected $options = []; |
| 63 | + /** |
| 64 | + * the Command's Options |
| 65 | + * |
| 66 | + * @var array |
| 67 | + */ |
| 68 | + protected $options = []; |
69 | 69 |
|
70 | | - //-------------------------------------------------------------------- |
| 70 | + /** |
| 71 | + * Displays the help for the spark cli script itself. |
| 72 | + */ |
| 73 | + public function run(array $params) |
| 74 | + { |
| 75 | + $directory = array_shift($params) ?? 'Publishers'; |
71 | 76 |
|
72 | | - /** |
73 | | - * Displays the help for the spark cli script itself. |
74 | | - * |
75 | | - * @param array $params |
76 | | - */ |
77 | | - public function run(array $params) |
78 | | - { |
79 | | - $directory = array_shift($params) ?? 'Publishers'; |
| 77 | + if ([] === $publishers = Publisher::discover($directory)) { |
| 78 | + CLI::write(lang('Publisher.publishMissing', [$directory])); |
80 | 79 |
|
81 | | - if ([] === $publishers = Publisher::discover($directory)) |
82 | | - { |
83 | | - CLI::write(lang('Publisher.publishMissing', [$directory])); |
84 | | - return; |
85 | | - } |
| 80 | + return; |
| 81 | + } |
86 | 82 |
|
87 | | - foreach ($publishers as $publisher) |
88 | | - { |
89 | | - if ($publisher->publish()) |
90 | | - { |
91 | | - CLI::write(lang('Publisher.publishSuccess', [ |
92 | | - get_class($publisher), |
93 | | - count($publisher->getPublished()), |
94 | | - $publisher->getDestination(), |
95 | | - ]), 'green'); |
96 | | - } |
97 | | - else |
98 | | - { |
99 | | - CLI::error(lang('Publisher.publishFailure', [ |
100 | | - get_class($publisher), |
101 | | - $publisher->getDestination(), |
102 | | - ]), 'light_gray', 'red'); |
| 83 | + foreach ($publishers as $publisher) { |
| 84 | + if ($publisher->publish()) { |
| 85 | + CLI::write(lang('Publisher.publishSuccess', [ |
| 86 | + get_class($publisher), |
| 87 | + count($publisher->getPublished()), |
| 88 | + $publisher->getDestination(), |
| 89 | + ]), 'green'); |
| 90 | + } else { |
| 91 | + CLI::error(lang('Publisher.publishFailure', [ |
| 92 | + get_class($publisher), |
| 93 | + $publisher->getDestination(), |
| 94 | + ]), 'light_gray', 'red'); |
103 | 95 |
|
104 | | - foreach ($publisher->getErrors() as $file => $exception) |
105 | | - { |
106 | | - CLI::write($file); |
107 | | - CLI::error($exception->getMessage()); |
108 | | - CLI::newLine(); |
109 | | - } |
110 | | - } |
111 | | - } |
112 | | - } |
| 96 | + foreach ($publisher->getErrors() as $file => $exception) { |
| 97 | + CLI::write($file); |
| 98 | + CLI::error($exception->getMessage()); |
| 99 | + CLI::newLine(); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
113 | 104 | } |
0 commit comments