-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
scoper.php
91 lines (79 loc) · 2.99 KB
/
scoper.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
use Isolated\Symfony\Component\Finder\Finder;
require __DIR__ . '/vendor/autoload.php';
$timestamp = (new DateTime('now'))->format('Ym');
// @see https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md
use Nette\Utils\Strings;
$polyfillsBootstraps = array_map(
static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(),
iterator_to_array(
Finder::create()
->files()
->in(__DIR__ . '/vendor/symfony/polyfill-*')
->name('bootstrap*.php'),
false,
),
);
$polyfillsStubs = array_map(
static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(),
iterator_to_array(
Finder::create()
->files()
->in(__DIR__ . '/vendor/symfony/polyfill-*/Resources/stubs')
->name('*.php'),
false,
),
);
// see https://github.com/humbug/php-scoper
return [
'prefix' => 'MonorepoBuilderPrefix' . $timestamp,
'exclude-files' => [
// these paths are relative to this file location, so it should be in the root directory
'vendor/symfony/deprecation-contracts/function.php',
...$polyfillsBootstraps,
...$polyfillsStubs,
],
'exclude-namespaces' => [
'#^Symplify\\\\MonorepoBuilder#',
'#^Symfony\\\\Polyfill#',
// part of public API in \Symplify\MonorepoBuilder\Release\Contract\ReleaseWorker\ReleaseWorkerInterface
'#^PharIo\\\\Version#',
],
'exclude-constants' => ['#^SYMFONY\_[\p{L}_]+$#'],
'expose-classes' => [
'Normalizer',
// part of public interface of configs.php
'Symplify\MonorepoBuilder\ComposerJsonManipulator\ValueObject\ComposerJsonSection',
'Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator',
],
'patchers' => [
// scope symfony configs
function (string $filePath, string $prefix, string $content): string {
if (! Strings::match($filePath, '#(packages|config|services)\.php$#')) {
return $content;
}
// fix symfony config load scoping, except CodingStandard and EasyCodingStandard
$content = Strings::replace(
$content,
'#load\(\'Symplify\\\\\\\\(?<package_name>[A-Za-z]+)#',
function (array $match) use ($prefix) {
return 'load(\'' . $prefix . '\Symplify\\' . $match['package_name'];
}
);
return $content;
},
// scope symfony configs
function (string $filePath, string $prefix, string $content): string {
if (! Strings::match($filePath, '#(packages|config|services)\.php$#')) {
return $content;
}
// unprefix symfony config
return Strings::replace(
$content,
'#load\(\'' . $prefix . '\\\\Symplify\\\\MonorepoBuilder#',
'load(\'' . 'Symplify\\MonorepoBuilder',
);
},
],
];