-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComposerService.php
More file actions
525 lines (475 loc) · 30.5 KB
/
ComposerService.php
File metadata and controls
525 lines (475 loc) · 30.5 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<?php
namespace CommonGateway\CoreBundle\Service;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use function PHPUnit\Framework\throwException;
/**
* @Author Ruben van der Linde <ruben@conduction.nl>, Barry Brands <barry@conduction.nl>, Wilco Louwerse <wilco@conduction.nl>
*
* @license EUPL <https://github.com/ConductionNL/contactcatalogus/blob/master/LICENSE.md>
*
* @category Service
*/
class ComposerService
{
private function arrayEnum(array $array, array $enum): bool
{
// Let's see if the values in the array arry pressent in the enum.
foreach ($array as $value) {
if (in_array($value, $enum) === false) {
return false;
}
}
return true;
}//end arrayEnum()
/**
* Make a call to composer.
*
* @param string $call The call that you want to make to composer shoul be one of show, init, install.
* @param string|null $package
* @param array $options
*
* @return array|string
*/
private function composerCall(string $call, array $options = [], string $package = '')
{
$optionsList = [];
// Let's check for valid calls.
switch ($call) {
case 'init':
$optionsList = [];
// name: Name of the package.
// --description: Description of the package.
// --author: Author name of the package.
// --type: Type of package.
// --homepage: Homepage of the package.
// --require: Package to require with a version constraint. Should be in format foo/bar:1.0.0.
// --require-dev: Development requirements, see --require.
// --stability (-s): Value for the minimum-stability field.
// --license (-l): License of package.
// --repository: Provide one (or more) custom repositories. They will be stored in the generated composer.json, and used for auto-completion when prompting for the list of requires. Every repository can be either an HTTP URL pointing to a composer repository or a JSON string which similar to what the repositories key accepts.
// --autoload (-a): Add a PSR-4 autoload mapping to.
break;
case 'install':
$optionsList = [];
// --prefer-install: There are two ways of downloading a package: source and dist. Composer uses dist by default. If you pass --prefer-install=source (or --prefer-source) Composer will install from source if there is one. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly. To get the legacy behavior where Composer use source automatically for dev versions of packages, use --prefer-install=auto. See also config.preferred-install. Passing this flag will override the config value.
// --dry-run: If you want to run through an installation without actually installing a package, you can use --dry-run. This will simulate the installation and show you what would happen.
// --download-only: Download only, do not install packages.
// --dev: Install packages listed in require-dev (this is the default behavior).
// --no-dev: Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules. Also see COMPOSER_NO_DEV.
// --no-autoloader: Skips autoloader generation.
// --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
// --audit: Run an audit after installation is complete.
// --audit-format: Audit output format. Must be "table", "plain", "json", or "summary" (default).
// --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
// --classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.
// --apcu-autoloader: Use APCu to cache found/not-found classes.
// --apcu-autoloader-prefix: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.
// --ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.
// --ignore-platform-req: ignore a specific platform requirement(php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill it. Multiple requirements can be ignored via wildcard. Appending a + makes it only ignore the upper-bound of the requirements. For example, if a package requires php: ^7, then the option --ignore-platform-req=php+ would allow installing on PHP 8, but installation on PHP 5.6 would still fail.
break;
case 'update':
$optionsList = [];
// --prefer-install: There are two ways of downloading a package: source and dist. Composer uses dist by default. If you pass --prefer-install=source (or --prefer-source) Composer will install from source if there is one. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly. To get the legacy behavior where Composer use source automatically for dev versions of packages, use --prefer-install=auto. See also config.preferred-install. Passing this flag will override the config value.
// --dry-run: Simulate the command without actually doing anything.
// --dev: Install packages listed in require-dev (this is the default behavior).
// --no-dev: Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules. Also see COMPOSER_NO_DEV.
// --no-install: Does not run the install step after updating the composer.lock file.
// --no-audit: Does not run the audit steps after updating the composer.lock file. Also see COMPOSER_NO_AUDIT.
// --audit-format: Audit output format. Must be "table", "plain", "json", or "summary" (default).
// --lock: Only updates the lock file hash to suppress warning about the lock file being out of date.
// --with: Temporary version constraint to add, e.g. foo/bar:1.0.0 or foo/bar=1.0.0
// --no-autoloader: Skips autoloader generation.
// --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
// --with-dependencies (-w): Update also dependencies of packages in the argument list, except those which are root requirements.
// --with-all-dependencies (-W): Update also dependencies of packages in the argument list, including those which are root requirements.
// --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run, so it is currently not done by default.
// --classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.
// --apcu-autoloader: Use APCu to cache found/not-found classes.
// --apcu-autoloader-prefix: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.
// --ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.
// --ignore-platform-req: ignore a specific platform requirement(php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill it. Multiple requirements can be ignored via wildcard. Appending a + makes it only ignore the upper-bound of the requirements. For example, if a package requires php: ^7, then the option --ignore-platform-req=php+ would allow installing on PHP 8, but installation on PHP 5.6 would still fail.
// --prefer-stable: Prefer stable versions of dependencies. Can also be set via the COMPOSER_PREFER_STABLE=1 env var.
// --prefer-lowest: Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable. Can also be set via the COMPOSER_PREFER_LOWEST=1 env var.
// --interactive: Interactive interface with autocompletion to select the packages to update.
// --root-reqs: Restricts the update to your first degree dependencies.+ makes it only ignore the upper-bound of the requirements. For example, if a package requires php: ^7, then the option --ignore-platform-req=php+ would allow installing on PHP 8, but installation on PHP 5.6 would still fail.
break;
case 'require':
$optionsList = [];
// --dev: Add packages to require-dev.
// --dry-run: Simulate the command without actually doing anything.
// --prefer-install: There are two ways of downloading a package: source and dist. Composer uses dist by default. If you pass --prefer-install=source (or --prefer-source) Composer will install from source if there is one. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly. To get the legacy behavior where Composer use source automatically for dev versions of packages, use --prefer-install=auto. See also config.preferred-install. Passing this flag will override the config value.
// --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
// --no-update: Disables the automatic update of the dependencies (implies --no-install).
// --no-install: Does not run the install step after updating the composer.lock file.
// --no-audit: Does not run the audit steps after updating the composer.lock file. Also see COMPOSER_NO_AUDIT.
// --audit-format: Audit output format. Must be "table", "plain", "json", or "summary" (default).
// --update-no-dev: Run the dependency update with the --no-dev option. Also see COMPOSER_NO_DEV.
// --update-with-dependencies (-w): Also update dependencies of the newly required packages, except those that are root requirements.
// --update-with-all-dependencies (-W): Also update dependencies of the newly required packages, including those that are root requirements.
// --ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.
// --ignore-platform-req: ignore a specific platform requirement(php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill it. Multiple requirements can be ignored via wildcard.
// --prefer-stable: Prefer stable versions of dependencies. Can also be set via the COMPOSER_PREFER_STABLE=1 env var.
// --prefer-lowest: Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable. Can also be set via the COMPOSER_PREFER_LOWEST=1 env var.
// --sort-packages: Keep packages sorted in composer.json.
// --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run, so it is currently not done by default.
// --classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.
// --apcu-autoloader: Use APCu to cache found/not-found classes.
// --apcu-autoloader-prefix: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.ard. Appending a + makes it only ignore the upper-bound of the requirements. For example, if a package requires php: ^7, then the option --ignore-platform-req=php+ would allow installing on PHP 8, but installation on PHP 5.6 would still fail.
break;
case 'remove':
$optionsList = [];
// --dev: Remove packages from require-dev.
// --dry-run: Simulate the command without actually doing anything.
// --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
// --no-update: Disables the automatic update of the dependencies (implies --no-install).
// --no-install: Does not run the install step after updating the composer.lock file.
// --no-audit: Does not run the audit steps after installation is complete. Also see COMPOSER_NO_AUDIT.
// --audit-format: Audit output format. Must be "table", "plain", "json", or "summary" (default).
// --update-no-dev: Run the dependency update with the --no-dev option. Also see COMPOSER_NO_DEV.
// --update-with-dependencies (-w): Also update dependencies of the removed packages. (Deprecated, is now default behavior)
// --update-with-all-dependencies (-W): Allows all inherited dependencies to be updated, including those that are root requirements.
// --ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.
// --ignore-platform-req: ignore a specific platform requirement(php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill it. Multiple requirements can be ignored via wildcard.
// --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
// --classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.
// --apcu-autoloader: Use APCu to cache found/not-found classes.
// --apcu-autoloader-prefix: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.x: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.ard. Appending a + makes it only ignore the upper-bound of the requirements. For example, if a package requires php: ^7, then the option --ignore-platform-req=php+ would allow installing on PHP 8, but installation on PHP 5.6 would still fail.
break;
case 'bump':
$optionsList = [];
//
// --dev-only: Only bump requirements in "require-dev".
// --no-dev-only: Only bump requirements in "require".
// --dry-run: Outputs the packages to bump, but will not execute anything.
break;
case 'check-platform-reqs':
$optionsList = [];
// --lock: Checks requirements only from the lock file, not from installed packages.
// --no-dev: Disables checking of require-dev packages requirements.
// --format (-f): Format of the output: text (default) or json
break;
case 'remove':
$optionsList = [];
// --dev: Remove packages from require-dev.
// --dry-run: Simulate the command without actually doing anything.
// --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
// --no-update: Disables the automatic update of the dependencies (implies --no-install).
// --no-install: Does not run the install step after updating the composer.lock file.
// --no-audit: Does not run the audit steps after installation is complete. Also see COMPOSER_NO_AUDIT.
// --audit-format: Audit output format. Must be "table", "plain", "json", or "summary" (default).
// --update-no-dev: Run the dependency update with the --no-dev option. Also see COMPOSER_NO_DEV.
// --update-with-dependencies (-w): Also update dependencies of the removed packages. (Deprecated, is now default behavior)
// --update-with-all-dependencies (-W): Allows all inherited dependencies to be updated, including those that are root requirements.
// --ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.
// --ignore-platform-req: ignore a specific platform requirement(php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill it. Multiple requirements can be ignored via wildcard.
// --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
// --classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.
// --apcu-autoloader: Use APCu to cache found/not-found classes.
// --apcu-autoloader-prefix: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.x: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.ard. Appending a + makes it only ignore the upper-bound of the requirements. For example, if a package requires php: ^7, then the option --ignore-platform-req=php+ would allow installing on PHP 8, but installation on PHP 5.6 would still fail.
break;
case 'search':
$optionsList = ['--format'];
// --only-name (-N): Search only in package names.
// --only-vendor (-O): Search only for vendor / organization names, returns only "vendor" as a result.
// --type (-t): Search for a specific package type.
// --format (-f): Let's you pick between text (default) or json output format. Note that in the json, only the name and description keys are guaranteed to be present. The rest (url, repository, downloads and favers) are available for Packagist.org search results and other repositories may return more or less data.
break;
case 'show':
$optionsList = [
'--all',
'--installed',
'--locked',
'--platform ',
'--available',
'--self',
'--name-only',
'--path',
'--tree',
'--latest',
'--outdated',
'--latest',
'--ignore',
'--no-dev',
'--major-only',
'--minor-only',
'--patch-only',
'--direct',
'--strict',
'--ignore-platform-reqs',
'--ignore-platform-req',
'--format',
];
break;
case 'home':
$optionsList = [];
// --homepage (-H): Open the homepage instead of the repository URL.
// --show (-s): Only show the homepage or repository URL.
break;
case 'suggests':
$optionsList = [];
// --by-package: Groups output by suggesting package (default).
// --by-suggestion: Groups output by suggested package.
// --all: Show suggestions from all dependencies, including transitive ones (by default only direct dependencies' suggestions are shown).
// --list: Show only list of suggested package names.
// --no-dev: Excludes suggestions from require-dev packages.
break;
case 'fund':
$optionsList = [];
// --format (-f): Let's you pick between text (default) or json output format.
break;
case 'depends ':
$optionsList = [];
// --recursive (-r): Recursively resolves up to the root package.
// --tree (-t): Prints the results as a nested tree, implies -r.
break;
case 'prohibits ':
$optionsList = [];
// --recursive (-r): Recursively resolves up to the root package.
// --tree (-t): Prints the results as a nested tree, implies -r.
break;
case 'validate ':
$optionsList = [];
// --no-check-all: Do not emit a warning if requirements in composer.json use unbound or overly strict version constraints.
// --no-check-lock: Do not emit an error if composer.lock exists and is not up to date.
// --no-check-publish: Do not emit an error if composer.json is unsuitable for publishing as a package on Packagist but is otherwise valid.
// --with-dependencies: Also validate the composer.json of all installed dependencies.
// --strict: Return a non-zero exit code for warnings as well as errors.
break;
case 'status ':
$optionsList = [];
// --recursive (-r): Recursively resolves up to the root package.
// --tree (-t): Prints the results as a nested tree, implies -r.
break;
case 'config ':
$optionsList = [];
// --global (-g): Operate on the global config file located at $COMPOSER_HOME/config.json by default. Without this option, this command affects the local composer.json file or a file specified by --file.
// --editor (-e): Open the local composer.json file using in a text editor as defined by the EDITOR env variable. With the --global option, this opens the global config file.
// --auth (-a): Affect auth config file (only used for --editor).
// --unset: Remove the configuration element named by setting-key.
// --list (-l): Show the list of current config variables. With the --global option this lists the global configuration only.
// --file="..." (-f): Operate on a specific file instead of composer.json. Note that this cannot be used in conjunction with the --global option.
// --absolute: Returns absolute paths when fetching *-dir config values instead of relative.
// --json: JSON decode the setting value, to be used with extra.* keys.
// --merge: Merge the setting value with the current value, to be used with extra.* keys in combination with --json.
// --append: When adding a repository, append it (lowest priority) to the existing ones instead of prepending it (highest priority).
// --source: Display where the config value is loaded from.
break;
case 'diagnose ':
$optionsList = [];
break;
case 'archive ':
$optionsList = [];
// --no-dev: Disables auditing of require-dev packages.
// --format (-f): Audit output format. Must be "table" (default), "plain", "json", or "summary".
// --locked: Audit packages from the lock file, regardless of what is currently in vendor dir.
break;
case 'audit ':
$optionsList = ['--format'];
break;
}//end switch
// Prepare the comand.
$cmd = [
'composer',
$call,
];
if (empty($package) === false) {
$cmd[] = strtolower($package);
}
// Check the enums.
if ($options and !$this->arrayEnum($options, $optionsList)) {
// @todo throwException();
}
// Force JSON output where supported.
if (in_array('--format', $optionsList) && in_array('--format json', $options) === false) {
$options[] = '--format=json';
}
// Include options.
$cmd = array_merge_recursive($cmd, $options);
// Start the procces.
$process = new Process($cmd);
$process->setWorkingDirectory('/srv/api');
$process->setTimeout(3600);
$process->run();
// executes after the command finishes.
if ($process->isSuccessful() === false) {
// throw new ProcessFailedException($process);
// var_dump('error');
$content = $process->getErrorOutput();
} else {
$content = $process->getOutput();
}
// Turn in into simpethin workable.
if (in_array('--format=json', $options)) {
$content = json_decode($content, true);
} else {
$content = explode(PHP_EOL, $content);
}
return $content;
}//end composerCall()
/**
* Gets all installed plugins from the lock file.
*
* @return array
*/
public function getLockFile(): array
{
$finder = new Finder();
$files = $finder->in('.')->files()->name('composer.lock')->exclude('vendor');
if (count($files) === 0) {
return [];
}
$lockFile = null;
foreach ($files as $file) {
$lockFile = $file;
break;
}
$plugins = json_decode($lockFile->getContents(), true);
return $plugins['packages'];
}//end getLockFile()
/**
* Show al packages installed trough composer.
*
* See https://getcomposer.org/doc/03-cli.md#show-info for a full list of al options and there function.
*
* @todo We used to have a $options argument in this function for filtering on types of plugins (installed, disabled etc). Removed because not implemented.
*
* @return array
*/
public function getAll(): array
{
$lockFile = $this->getLockFile();
$plugins = [];
foreach ($lockFile as $result) {
// Remove non gateway plugins from the result.
if (isset($result['keywords']) === false || in_array('common-gateway-plugin', $result['keywords']) === false) {
continue;
}
$plugins[] = array_merge($result, $this->getSingle($result['name']));
}
return $plugins;
}//end getAll()
/**
* Show a single package installed trough composer.
*
* See https://getcomposer.org/doc/03-cli.md#show-info for a full list of al options and there function
*
* @param string $package
* @param array $options
*
* @return array
*/
public function require(string $package, array $options = []): array
{
return $this->composerCall('require', $options, $package);
}//end require()
/**
* Show a single package installed trough composer.
*
* See https://getcomposer.org/doc/03-cli.md#show-info for a full list of al options and there function
*
* @param string $package
* @param array $options
*
* @return array
*/
public function upgrade(string $package, array $options = []): array
{
return $this->composerCall('upgrade', $options, $package);
}//end upgrade()
/**
* Show a single package installed trough composer.
*
* See https://getcomposer.org/doc/03-cli.md#show-info for a full list of al options and there function.
*
* @param string $package
* @param array $options
*
* @return array
*/
public function remove(string $package, array $options = []): array
{
return $this->composerCall('remove', $options, $package);
}//end remove()
/**
* Show a single package installed trough composer.
*
* See https://getcomposer.org/doc/03-cli.md#show-info for a full list of al options and there function.
*
* @param string $package
*
* @return array
*/
public function getSingle(string $package): array
{
$url = 'https://packagist.org/packages/'.$package.'.json';
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $url);
$plugin = json_decode($response->getBody()->getContents(), true)['package'];
$installedPlugins = $this->getLockFile();
foreach ($installedPlugins as $installedPlugin) {
if ($installedPlugin['name'] == $plugin['name']) {
$plugin = array_merge($installedPlugin, $plugin);
$plugin['update'] = false;
// Let's see if we have newer versions than currently installer
foreach ($plugin['versions'] as $version => $versionDetails) {
if (version_compare($plugin['version'], $version) < 0) {
if (empty($plugin['update']) === true) {
$plugin['update'] = $version;
continue;
}
if (version_compare($plugin['update'], $version) < 0) {
$plugin['update'] = $version;
}
}
}//end foreach
break;
}//end if
}//end foreach
return $plugin;
}//end getSingle()
/**
* Search for a given term.
*
* See https://getcomposer.org/doc/03-cli.md#show-info for a full list of al options and there function.
*
* @todo We used to have a $options argument in this function for filtering on types of plugins (installed, disabled etc). Removed because not implemented.
*
* @param string|null $search
*
* @return array
*/
public function search(string $search = null): array
{
$query = ['tags' => 'common-gateway-plugin'];
if ($search) {
$query['q'] = $search;
}
$client = new \GuzzleHttp\Client();
$response = $client->request(
'GET',
'https://packagist.org/search.json',
['query' => $query]
);
$plugins = json_decode($response->getBody()->getContents(), true)['results'];
// Let's pull the online detail datail
foreach ($plugins as $key => $plugin) {
$plugins[$key] = array_merge($plugin, $this->getSingle($plugin['name']));
}
return $plugins;
}//end search()
/**
* Search for a given term.
*
* See https://getcomposer.org/doc/03-cli.md#show-info for a full list of al options and there function.
*
* @param array $options
*
* @return array
*/
public function audit(array $options = []): array
{
return $this->composerCall('audit', $options);
}//end audit()
}//end class