forked from llaville/php-compatinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox-metadata.php
More file actions
76 lines (63 loc) · 2.08 KB
/
box-metadata.php
File metadata and controls
76 lines (63 loc) · 2.08 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
<?php declare(strict_types=1);
/**
* This file is part of the PHP_CompatInfoDB package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/vendor/autoload.php';
use Composer\Factory;
use Composer\IO\NullIO;
/**
* Composer script that prepare metadata to compile PHAR version of application.
*
* @author Laurent Laville
*/
class ComposerScripts
{
/**
* Generate metadata when box compile read metadata directive.
*
* @return null|array<int, string>
*/
public static function getPharMetadata(): ?array
{
$composer = Factory::create(new NullIO());
$locker = $composer->getLocker();
try {
$lockData = $locker->getLockData();
} catch (LogicException $e) {
// Composer installation was not run.
return null;
}
$installed = [];
foreach (array_keys($lockData['platform']) as $type) {
if ('php' === $type) {
$installed[$type] = phpversion();
} else {
$installed[$type] = phpversion(str_replace('ext-', '', $type));
}
}
foreach ($lockData['packages'] as $package) {
$installed[$package['name']] = $package['version'];
}
foreach ($lockData['packages-dev'] as $package) {
$installed[$package['name']] = $package['version'];
}
$rootPackage = $composer->getPackage();
$componentCollection = [];
$requires = array_merge(
$rootPackage->getRequires(),
$rootPackage->getDevRequires()
);
foreach ($requires as $type => $require) {
$prettyString = (string) $require->getPrettyString($rootPackage);
if (isset($installed[$type])) {
$prettyString .= sprintf(' : <info>%s</info>', $installed[$type]);
}
$componentCollection[] = $prettyString;
}
return $componentCollection;
}
}
return ComposerScripts::getPharMetadata();