forked from flippedbits/crunz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
composer-install.php
executable file
·69 lines (57 loc) · 1.68 KB
/
composer-install.php
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
#!/usr/bin/env php
<?php
$version = $_SERVER['argv'][1] ?? '';
if ('' === $version) {
throw new RuntimeException('Version cannot be empty.');
}
$dependenciesEnv = $_SERVER['argv'][2] ?? '';
$defaultComposerFlags = $_SERVER['argv'][3] ?? '';
$phpunitBridgeVersion = $_SERVER['argv'][4] ?? $version;
$composerFilePath = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json';
$ignoredPackages = ['symfony/error-handler'];
$changeVersion = static function (
array $packages
) use (
$version,
$phpunitBridgeVersion,
$ignoredPackages
): array {
foreach ($packages as $packageName => &$packageVersion) {
$isIgnored = \in_array(
$packageName,
$ignoredPackages,
true
);
if ($isIgnored) {
continue;
}
if (false === \mb_strpos($packageName, 'symfony/')) {
continue;
}
if ('symfony/phpunit-bridge' === $packageName) {
$packageVersion = $phpunitBridgeVersion;
continue;
}
$packageVersion = $version;
}
return $packages;
};
$composerJson = \json_decode(
\file_get_contents($composerFilePath),
true
);
$packages = $composerJson['require'] ?? [];
$packagesDev = $composerJson['require-dev'] ?? [];
$composerJson['require'] = $changeVersion($packages);
$composerJson['require-dev'] = $changeVersion($packagesDev);
\file_put_contents(
$composerFilePath,
\json_encode($composerJson, JSON_PRETTY_PRINT)
);
$preferLowest = '';
if ('high' !== $dependenciesEnv) {
$preferLowest = '--prefer-lowest';
}
$command = \trim("composer update -o {$defaultComposerFlags} {$preferLowest}");
echo $command, PHP_EOL;
echo \shell_exec($command);