-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
scoper.php
96 lines (81 loc) · 3.38 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
92
93
94
95
96
<?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' => 'ConfigTransformerPrefix' . $timestamp,
'expose-constants' => ['#^SYMFONY\_[\p{L}_]+$#'],
// excluded
'exclude-namespaces' => [
'#^Symplify\\\\ConfigTransformer#',
'#^Symplify\\\\PhpConfigPrinter#',
'#^Symfony\\\\Polyfill#',
// used in generate-config-classes command
],
'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,
],
'patchers' => [
// unprefix strings used for config printing
// fixes https://github.com/symplify/symplify/issues/3976
function (string $filePath, string $prefix, string $content): string {
/** @see \Symplify\PhpConfigPrinter\ValueObject\FunctionName */
if (! str_ends_with($filePath, 'vendor/symplify/php-config-printer/src/ValueObject/FunctionName.php')) {
return $content;
}
$pattern = sprintf('#public const (.*?) = \'%s\\\\\\\\#', $prefix);
return Strings::replace($content, $pattern, 'public const $1 = \'');
},
// unprefix strings class, used for node factory
// fixes https://github.com/symplify/symplify/issues/3976
function (string $filePath, string $prefix, string $content): string {
if (! str_ends_with($filePath, 'src/NodeFactory/ContainerConfiguratorReturnClosureFactory.php')) {
return $content;
}
return str_replace(
$prefix . '\\\\Symfony\\\\Component\\\\DependencyInjection\\\\Loader\\\\Configurator\\\\ContainerConfigurator',
'Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator',
$content
);
},
// unprefix strings class, used for node factory
// fixes https://github.com/symplify/symplify/issues/3976
function (string $filePath, string $prefix, string $content): string {
if (! str_ends_with($filePath, '/PhpParser/NodeFactory/ConfiguratorClosureNodeFactory.php')) {
return $content;
}
return str_replace(
$prefix . '\\\\Symfony\\\\Component\\\\Routing\\\\Loader\\\\Configurator\\\\RoutingConfigurator',
'Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator',
$content
);
},
],
];