-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathscoper.inc.php
More file actions
72 lines (62 loc) · 2.27 KB
/
scoper.inc.php
File metadata and controls
72 lines (62 loc) · 2.27 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
<?php
declare(strict_types=1);
use Isolated\Symfony\Component\Finder\Finder;
$composerJsonRaw = file_get_contents(__DIR__ . '/composer.json');
$composerJson = \json_decode($composerJsonRaw, true);
$dependencies = [];
$finderConfig = [];
// Detect which composer to use (global or downloaded)
$composerCmd = 'composer';
$globalComposer = shell_exec('which composer 2>/dev/null');
if ($globalComposer === null || $globalComposer === false || trim($globalComposer) === '') {
// No global composer, check for downloaded one
$downloadedComposer = __DIR__ . '/.tools/composer.phar';
if (file_exists($downloadedComposer)) {
$composerCmd = 'php "' . $downloadedComposer . '"';
}
}
$dependenciesListRaw = shell_exec($composerCmd . ' show --format=json --tree --no-dev');
if($dependenciesListRaw === null || $dependenciesListRaw === false) {
error_log('Cannot determine dependencies');
exit(1);
}
$dependenciesList = \json_decode($dependenciesListRaw, true);
if(!is_array($dependenciesList) || !isset($dependenciesList['installed'])) {
error_log('Invalid composer show output');
exit(2);
}
addDependencies($dependenciesList['installed'], $dependencies);
function isIgnorable(array $depInfo, array $dependencies): bool {
return ($depInfo['name'] === 'php'
|| $depInfo['name'] === 'bamarni/composer-bin-plugin'
|| str_starts_with($depInfo['name'], 'ext-')
|| isset($dependencies[$depInfo['name']])
);
}
function addDependencies(array $requires, array &$dependencies): void {
foreach($requires as $depInfo) {
if (isIgnorable($depInfo, $dependencies)) {
continue;
}
if (!isset($dependencies[$depInfo['name']])) {
$dependencies[$depInfo['name']] = 1;
}
if (isset($depInfo['requires'])) {
addDependencies($depInfo['requires'], $dependencies);
}
}
}
foreach (array_keys($dependencies) as $name) {
fwrite(STDERR, 'Adding ' . $name . PHP_EOL);
$finderConfig[] = Finder::create()
->path($name)
->files()
->exclude(["test", "tests", "composer", "bin"])
->notName("autoload.php")
->in("vendor/");
}
return [
"prefix" => "OCA\\News\\Vendor",
'exclude-namespaces' => [ 'Psr\\Log\\' ],
"finders" => $finderConfig,
];