|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Joomla! Statistics Server |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved. |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Joomla\StatsServer\Providers; |
|
10
|
|
|
|
|
11
|
|
|
use Joomla\Console\Application; |
|
12
|
|
|
use Joomla\Console\Loader\ContainerLoader; |
|
13
|
|
|
use Joomla\Console\Loader\LoaderInterface; |
|
14
|
|
|
use Joomla\DI\Container; |
|
15
|
|
|
use Joomla\DI\ServiceProviderInterface; |
|
16
|
|
|
use Joomla\Event\Command\DebugEventDispatcherCommand; |
|
17
|
|
|
use Joomla\Event\DispatcherInterface; |
|
18
|
|
|
use Joomla\Router\Command\DebugRouterCommand; |
|
19
|
|
|
use Joomla\Router\Router; |
|
20
|
|
|
use Joomla\StatsServer\Commands\Database\MigrateCommand; |
|
21
|
|
|
use Joomla\StatsServer\Commands\Database\MigrationStatusCommand; |
|
22
|
|
|
use Joomla\StatsServer\Commands\SnapshotCommand; |
|
23
|
|
|
use Joomla\StatsServer\Commands\SnapshotRecentlyUpdatedCommand; |
|
24
|
|
|
use Joomla\StatsServer\Commands\Tags\FetchJoomlaTagsCommand; |
|
25
|
|
|
use Joomla\StatsServer\Commands\Tags\FetchPhpTagsCommand; |
|
26
|
|
|
use Joomla\StatsServer\Commands\UpdateCommand; |
|
27
|
|
|
use Joomla\StatsServer\Database\Migrations; |
|
28
|
|
|
use Joomla\StatsServer\GitHub\GitHub; |
|
29
|
|
|
use Joomla\StatsServer\Views\Stats\StatsJsonView; |
|
30
|
|
|
use Psr\Log\LoggerInterface; |
|
31
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
|
32
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Console service provider |
|
36
|
|
|
*/ |
|
37
|
|
|
class ConsoleServiceProvider implements ServiceProviderInterface |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* Registers the service provider with a DI container. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Container $container The DI container. |
|
43
|
|
|
* |
|
44
|
|
|
* @return void |
|
45
|
|
|
*/ |
|
46
|
11 |
|
public function register(Container $container): void |
|
47
|
|
|
{ |
|
48
|
11 |
|
$container->share(Application::class, [$this, 'getConsoleApplicationService']); |
|
49
|
|
|
|
|
50
|
|
|
/* |
|
51
|
|
|
* Application Helpers and Dependencies |
|
52
|
|
|
*/ |
|
53
|
|
|
|
|
54
|
11 |
|
$container->alias(ContainerLoader::class, LoaderInterface::class) |
|
55
|
11 |
|
->share(LoaderInterface::class, [$this, 'getCommandLoaderService']); |
|
56
|
|
|
|
|
57
|
|
|
/* |
|
58
|
|
|
* Commands |
|
59
|
|
|
*/ |
|
60
|
|
|
|
|
61
|
11 |
|
$container->share(DebugEventDispatcherCommand::class, [$this, 'getDebugEventDispatcherCommandService']); |
|
62
|
11 |
|
$container->share(DebugRouterCommand::class, [$this, 'getDebugRouterCommandService']); |
|
63
|
11 |
|
$container->share(MigrateCommand::class, [$this, 'getDatabaseMigrateCommandService']); |
|
64
|
11 |
|
$container->share(MigrationStatusCommand::class, [$this, 'getDatabaseMigrationStatusCommandService']); |
|
65
|
11 |
|
$container->share(FetchJoomlaTagsCommand::class, [$this, 'getFetchJoomlaTagsCommandService']); |
|
66
|
11 |
|
$container->share(FetchPhpTagsCommand::class, [$this, 'getFetchPhpTagsCommandService']); |
|
67
|
11 |
|
$container->share(SnapshotCommand::class, [$this, 'getSnapshotCommandService']); |
|
68
|
11 |
|
$container->share(SnapshotRecentlyUpdatedCommand::class, [$this, 'getSnapshotRecentlyUpdatedCommandService']); |
|
69
|
11 |
|
$container->share(UpdateCommand::class, [$this, 'getUpdateCommandService']); |
|
70
|
11 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get the LoaderInterface service |
|
74
|
|
|
* |
|
75
|
|
|
* @param Container $container The DI container. |
|
76
|
|
|
* |
|
77
|
|
|
* @return LoaderInterface |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function getCommandLoaderService(Container $container): LoaderInterface |
|
80
|
|
|
{ |
|
81
|
|
|
$mapping = [ |
|
82
|
1 |
|
DebugEventDispatcherCommand::getDefaultName() => DebugEventDispatcherCommand::class, |
|
83
|
1 |
|
DebugRouterCommand::getDefaultName() => DebugRouterCommand::class, |
|
84
|
1 |
|
MigrationStatusCommand::getDefaultName() => MigrationStatusCommand::class, |
|
85
|
1 |
|
MigrateCommand::getDefaultName() => MigrateCommand::class, |
|
86
|
1 |
|
FetchJoomlaTagsCommand::getDefaultName() => FetchJoomlaTagsCommand::class, |
|
87
|
1 |
|
FetchPhpTagsCommand::getDefaultName() => FetchPhpTagsCommand::class, |
|
88
|
1 |
|
SnapshotCommand::getDefaultName() => SnapshotCommand::class, |
|
89
|
1 |
|
SnapshotRecentlyUpdatedCommand::getDefaultName() => SnapshotRecentlyUpdatedCommand::class, |
|
90
|
1 |
|
UpdateCommand::getDefaultName() => UpdateCommand::class, |
|
91
|
|
|
]; |
|
92
|
|
|
|
|
93
|
1 |
|
return new ContainerLoader($container, $mapping); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get the console Application service |
|
98
|
|
|
* |
|
99
|
|
|
* @param Container $container The DI container. |
|
100
|
|
|
* |
|
101
|
|
|
* @return Application |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function getConsoleApplicationService(Container $container): Application |
|
104
|
|
|
{ |
|
105
|
1 |
|
$application = new Application(new ArgvInput, new ConsoleOutput, $container->get('config')); |
|
106
|
|
|
|
|
107
|
1 |
|
$application->setCommandLoader($container->get(LoaderInterface::class)); |
|
108
|
1 |
|
$application->setDispatcher($container->get(DispatcherInterface::class)); |
|
109
|
1 |
|
$application->setLogger($container->get(LoggerInterface::class)); |
|
110
|
1 |
|
$application->setName('Joomla! Statistics Server'); |
|
111
|
|
|
|
|
112
|
1 |
|
return $application; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get the MigrateCommand service |
|
117
|
|
|
* |
|
118
|
|
|
* @param Container $container The DI container. |
|
119
|
|
|
* |
|
120
|
|
|
* @return MigrateCommand |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getDatabaseMigrateCommandService(Container $container): MigrateCommand |
|
123
|
|
|
{ |
|
124
|
|
|
$command = new MigrateCommand($container->get(Migrations::class)); |
|
125
|
|
|
$command->setLogger($container->get(LoggerInterface::class)); |
|
126
|
|
|
|
|
127
|
|
|
return $command; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Get the MigrationStatusCommand service |
|
132
|
|
|
* |
|
133
|
|
|
* @param Container $container The DI container. |
|
134
|
|
|
* |
|
135
|
|
|
* @return MigrationStatusCommand |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getDatabaseMigrationStatusCommandService(Container $container): MigrationStatusCommand |
|
138
|
|
|
{ |
|
139
|
|
|
return new MigrationStatusCommand($container->get(Migrations::class)); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get the DebugEventDispatcherCommand service |
|
144
|
|
|
* |
|
145
|
|
|
* @param Container $container The DI container. |
|
146
|
|
|
* |
|
147
|
|
|
* @return DebugEventDispatcherCommand |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getDebugEventDispatcherCommandService(Container $container): DebugEventDispatcherCommand |
|
150
|
|
|
{ |
|
151
|
|
|
return new DebugEventDispatcherCommand($container->get(DispatcherInterface::class)); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Get the DebugRouterCommand service |
|
156
|
|
|
* |
|
157
|
|
|
* @param Container $container The DI container. |
|
158
|
|
|
* |
|
159
|
|
|
* @return DebugRouterCommand |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getDebugRouterCommandService(Container $container): DebugRouterCommand |
|
162
|
|
|
{ |
|
163
|
|
|
return new DebugRouterCommand($container->get(Router::class)); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Get the FetchJoomlaTagsCommand service |
|
168
|
|
|
* |
|
169
|
|
|
* @param Container $container The DI container. |
|
170
|
|
|
* |
|
171
|
|
|
* @return FetchJoomlaTagsCommand |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getFetchJoomlaTagsCommandService(Container $container): FetchJoomlaTagsCommand |
|
174
|
|
|
{ |
|
175
|
|
|
return new FetchJoomlaTagsCommand($container->get(GitHub::class), $container->get('filesystem.versions')); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Get the FetchPhpTagsCommand class service |
|
180
|
|
|
* |
|
181
|
|
|
* @param Container $container The DI container. |
|
182
|
|
|
* |
|
183
|
|
|
* @return FetchPhpTagsCommand |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getFetchPhpTagsCommandService(Container $container): FetchPhpTagsCommand |
|
186
|
|
|
{ |
|
187
|
|
|
return new FetchPhpTagsCommand($container->get(GitHub::class), $container->get('filesystem.versions')); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Get the SnapshotCommand service |
|
192
|
|
|
* |
|
193
|
|
|
* @param Container $container The DI container. |
|
194
|
|
|
* |
|
195
|
|
|
* @return SnapshotCommand |
|
196
|
|
|
*/ |
|
197
|
|
|
public function getSnapshotCommandService(Container $container): SnapshotCommand |
|
198
|
|
|
{ |
|
199
|
|
|
return new SnapshotCommand($container->get(StatsJsonView::class), $container->get('filesystem.snapshot')); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Get the SnapshotRecentlyUpdatedCommand service |
|
204
|
|
|
* |
|
205
|
|
|
* @param Container $container The DI container. |
|
206
|
|
|
* |
|
207
|
|
|
* @return SnapshotRecentlyUpdatedCommand |
|
208
|
|
|
*/ |
|
209
|
|
|
public function getSnapshotRecentlyUpdatedCommandService(Container $container): SnapshotRecentlyUpdatedCommand |
|
210
|
|
|
{ |
|
211
|
|
|
return new SnapshotRecentlyUpdatedCommand($container->get(StatsJsonView::class), $container->get('filesystem.snapshot')); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Get the UpdateCommand class service |
|
216
|
|
|
* |
|
217
|
|
|
* @param Container $container The DI container. |
|
218
|
|
|
* |
|
219
|
|
|
* @return UpdateCommand |
|
220
|
|
|
*/ |
|
221
|
|
|
public function getUpdateCommandService(Container $container): UpdateCommand |
|
|
|
|
|
|
222
|
|
|
{ |
|
223
|
|
|
return new UpdateCommand; |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.