forked from box-project/box
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscoper.inc.php
156 lines (139 loc) · 5.5 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
declare(strict_types=1);
/*
* This file is part of the box project.
*
* (c) Kevin Herrera <[email protected]>
* Théo Fidry <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
use Isolated\Symfony\Component\Finder\Finder;
$classLoaderContents = file_get_contents(__DIR__.'/vendor/composer/composer/src/Composer/Autoload/ClassLoader.php');
return [
'patchers' => [
function (string $filePath, string $prefix, string $contents): string {
$finderClass = sprintf('\%s\%s', $prefix, Finder::class);
return str_replace($finderClass, '\\'.Finder::class, $contents);
},
function (string $filePath, string $prefix, string $contents): string {
$file = 'vendor/beberlei/assert/lib/Assert/Assertion.php';
if ($filePath !== $file) {
return $contents;
}
return preg_replace(
"/exceptionClass = 'Assert\\\\\\\\InvalidArgumentException'/",
sprintf(
'exceptionClass = \'%s\\\\Assert\\\\InvalidArgumentException\'',
$prefix
),
$contents
);
},
function (string $filePath, string $prefix, string $contents): string {
$files = [
'src/functions.php',
'src/Configuration.php',
];
if (false === in_array($filePath, $files, true)) {
return $contents;
}
$contents = preg_replace(
sprintf(
'/\\\\'.$prefix.'\\\\Herrera\\\\Box\\\\Compactor/',
$prefix
),
'\\Herrera\\\Box\\Compactor',
$contents
);
return preg_replace(
sprintf(
'/\\\\'.$prefix.'\\\\KevinGH\\\\Box\\\\Compactor\\\\/',
$prefix
),
'\\KevinGH\\\Box\\Compactor\\',
$contents
);
},
function (string $filePath, string $prefix, string $contents): string {
if ('vendor/composer/composer/src/Composer/Autoload/AutoloadGenerator.php' !== $filePath) {
return $contents;
}
return preg_replace(
sprintf(
'/\$loader = new \\\\%s\\\\Composer\\\\Autoload\\\\ClassLoader\(\)/',
$prefix
),
'$loader = new \Composer\Autoload\ClassLoader();',
$contents
);
},
function (string $filePath, string $prefix, string $contents) use ($classLoaderContents): string {
return 'vendor/composer/composer/src/Composer/Autoload/ClassLoader.php' === $filePath ? $classLoaderContents : $contents;
},
function (string $filePath, string $prefix, string $contents): string {
if ('vendor/paragonie/sodium_compat/autoload.php' !== $filePath) {
return $contents;
}
return preg_replace(
'/\'sodiumCompatAutoloader\'/',
sprintf(
'\'%s\\%s\'',
$prefix,
'sodiumCompatAutoloader'
),
preg_replace(
'/\$namespace = \'ParagonIE_Sodium_\';/',
sprintf(
'$namespace = \'%s\\ParagonIE_Sodium_\';',
$prefix
),
$contents
)
);
},
function (string $filePath, string $prefix, string $contents): string {
if ('vendor/paragonie/sodium_compat/lib/php72compat.php' !== $filePath) {
return $contents;
}
return preg_replace(
'/\\\\define\\("SODIUM_{\\$constant}", \\\\constant\\("ParagonIE_Sodium_Compat::{\\$constant}"\\)\\);/',
sprintf(
'\define("SODIUM_{$constant}", \constant("%s\\ParagonIE_Sodium_Compat::{$constant}"));',
$prefix
),
$contents
);
},
// `stream_isatty()` is a PHP 7.2 function hence not defined in PHP 7.1. Unlike its function call, the string
// in `function_exists()` is prefixed because the name can be resolved to a FQCN and appears as a user-land
// function.
function (string $filePath, string $prefix, string $contents): string {
$files = [
'vendor/symfony/console/Output/StreamOutput.php',
'vendor/symfony/var-dumper/Dumper/CliDumper.php',
'vendor/composer/xdebug-handler/src/Process.php',
];
if (false === in_array($filePath, $files, true)) {
return $contents;
}
return preg_replace(
'/function_exists\(\''.$prefix.'\\\\\\\\stream_isatty\'\)/',
"function_exists('stream_isatty')",
$contents
);
},
],
'whitelist' => [
\Composer\Autoload\ClassLoader::class,
\Herrera\Box\Compactor\Json::class,
\KevinGH\Box\Compactor\Json::class,
\Herrera\Box\Compactor\Php::class,
\KevinGH\Box\Compactor\Php::class,
\KevinGH\Box\Compactor\PhpScoper::class,
],
'whitelist-global-constants' => false,
'whitelist-global-classes' => false,
'whitelist-global-functions' => false,
];