-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscoper.php
64 lines (52 loc) · 2.33 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
<?php
declare(strict_types=1);
use Nette\Utils\DateTime;
use Nette\Utils\Strings;
require_once __DIR__ . '/vendor/autoload.php';
// remove phpstan, because it is already prefixed in its own scope
$dateTime = DateTime::from('now');
$timestamp = $dateTime->format('Ymd');
// see https://github.com/humbug/php-scoper
return [
'prefix' => 'RevealPrefix' . $timestamp,
// @see https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposed-symbols - regex format
'exclude-namespaces' => [
'#^PHPStan#',
'#^Reveal#',
'#^PhpParser#',
'#^Symplify\\\\Astral#',
'#^Symplify\\\\SmartFileSystem#',
'#^Symplify\\\\PackageBuilder#',
],
'expose-functions' => ['u', 'b', 's', 'trigger_deprecation'],
'patchers' => [
// fixes https://github.com/rectorphp/rector/issues/7017 - still needed 2022-06
function (string $filePath, string $prefix, string $content): string {
if (\str_ends_with($filePath, 'vendor/symfony/string/ByteString.php')) {
return Strings::replace($content, '#' . $prefix . '\\\\\\\\1_\\\\\\\\2#', '\\\\1_\\\\2');
}
if (\str_ends_with($filePath, 'vendor/symfony/string/AbstractUnicodeString.php')) {
return Strings::replace($content, '#' . $prefix . '\\\\\\\\1_\\\\\\\\2#', '\\\\1_\\\\2');
}
return $content;
},
// scoper missed PSR-4 autodiscovery in Symfony - still needed
function (string $filePath, string $prefix, string $content): string {
if (! \str_ends_with($filePath, 'config.php') && ! \str_ends_with($filePath, 'services.php')) {
return $content;
}
// skip "Rector\\" namespace
if (\str_contains($content, '$services->load(\'Reveal')) {
return $content;
}
return Strings::replace($content, '#services\->load\(\'#', "services->load('" . $prefix . '\\');
},
// latte services
function (string $filePath, string $prefix, string $content): string {
if (! \str_ends_with($filePath, 'config.neon') && ! \str_ends_with($filePath, 'services.neon')) {
return $content;
}
return Strings::replace($content, '#- Latte\\\\#', "- $prefix\\Latte\\");
},
],
];