-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscoper.inc.php
101 lines (86 loc) · 4.68 KB
/
scoper.inc.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
97
98
99
100
101
<?php
declare(strict_types=1);
use Isolated\Symfony\Component\Finder\Finder;
$polyfillBootstraps = [
\getcwd() . '/vendor/symfony/polyfill-intl-normalizer/bootstrap.php',
\getcwd() . '/vendor/symfony/polyfill-ctype/bootstrap.php',
\getcwd() . '/vendor/symfony/polyfill-php73/bootstrap.php',
\getcwd() . '/vendor/symfony/polyfill-php80/bootstrap.php',
\getcwd() . '/vendor/symfony/polyfill-mbstring/bootstrap.php',
\getcwd() . '/vendor/symfony/polyfill-intl-grapheme/bootstrap.php',
\getcwd() . '/vendor/symfony/polyfill-php72/bootstrap.php'
];
return [
// The prefix configuration. If a non null value will be used, a random prefix will be generated.
'prefix' => '_PhpScoper3fe455fa007d',
// By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
// directory. You can however define which files should be scoped by defining a collection of Finders in the
// following configuration key.
//
// For more see: https://github.com/humbug/php-scoper#finders-and-paths
'finders' => [
Finder::create()->files()->in('src'),
Finder::create()
->files()
->ignoreVCS(true)
->notName('/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/')
->in('vendor'),
Finder::create()->append([
'composer.json',
'functions.php',
]),
],
// Whitelists a list of files. Unlike the other whitelist related features, this one is about completely leaving
// a file untouched.
// Paths are relative to the configuration file unless if they are already absolute
'files-whitelist' => [
'src/a-whitelisted-file.php',
],
// When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
// original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
// support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
// heart contents.
//
// For more see: https://github.com/humbug/php-scoper#patchers
'patchers' => [
function (string $filePath, string $prefix, string $contents) use($polyfillBootstraps): string {
if ($filePath === \getcwd() . '/functions.php') {
$contents = \str_replace($prefix . '\\\\pd', 'pd', $contents);
$contents = \str_replace('namespace ' . $prefix . ';', 'require __DIR__ . \'/vendor/autoload.php\';', $contents);
}
if (in_array($filePath, $polyfillBootstraps, true)) {
$contents = \str_replace('namespace ' . $prefix . ';', '', $contents);
}
if ($filePath === \getcwd() . '/src/Extensions/Doctrine.php') {
$contents = \str_replace('\_PhpScoper3fe455fa007d\Doctrine\DBAL\Query\QueryBuilder', '\Doctrine\DBAL\Query\QueryBuilder', $contents);
}
return $contents;
},
],
// PHP-Scoper's goal is to make sure that all code for a project lies in a distinct PHP namespace. However, you
// may want to share a common API between the bundled code of your PHAR and the consumer code. For example if
// you have a PHPUnit PHAR with isolated code, you still want the PHAR to be able to understand the
// PHPUnit\Framework\TestCase class.
//
// A way to achieve this is by specifying a list of classes to not prefix with the following configuration key. Note
// that this does not work with functions or constants neither with classes belonging to the global namespace.
//
// Fore more see https://github.com/humbug/php-scoper#whitelist
'whitelist' => [
// 'PHPUnit\Framework\TestCase', // A specific class
// 'PHPUnit\Framework\*', // The whole namespace
// '*', // Everything
],
// If `true` then the user defined constants belonging to the global namespace will not be prefixed.
//
// For more see https://github.com/humbug/php-scoper#constants--constants--functions-from-the-global-namespace
'whitelist-global-constants' => true,
// If `true` then the user defined classes belonging to the global namespace will not be prefixed.
//
// For more see https://github.com/humbug/php-scoper#constants--constants--functions-from-the-global-namespace
'whitelist-global-classes' => true,
// If `true` then the user defined functions belonging to the global namespace will not be prefixed.
//
// For more see https://github.com/humbug/php-scoper#constants--constants--functions-from-the-global-namespace
'whitelist-global-functions' => true,
];