1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the box project. |
7
|
|
|
* |
8
|
|
|
* (c) Kevin Herrera <[email protected]> |
9
|
|
|
* Théo Fidry <[email protected]> |
10
|
|
|
* |
11
|
|
|
* This source file is subject to the MIT license that is bundled |
12
|
|
|
* with this source code in the file LICENSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
function get_prefix(): string |
16
|
|
|
{ |
17
|
|
|
$lastReleaseEndpoint = shell_exec(<<<'BASH' |
18
|
|
|
curl -s https://api.github.com/repos/humbug/box/releases/latest \ |
19
|
|
|
| grep "browser_download_url.*box.phar" \ |
20
|
|
|
| cut -d '"' -f 4 |
21
|
|
|
BASH |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
if (1 !== preg_match('/download\/(?<version>.*?)\/box\.phar$/', $lastReleaseEndpoint, $matches)) { |
25
|
|
|
throw new \RuntimeException(sprintf( |
26
|
|
|
'Could not retrieve the last release endpoint. Last URL download link found: "%s"', |
27
|
|
|
$lastReleaseEndpoint |
28
|
|
|
)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$lastRelease = $matches['version']; |
32
|
|
|
|
33
|
|
|
return 'HumbugBox'.str_replace('.', '', $lastRelease); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return [ |
37
|
|
|
'prefix' => get_prefix(), |
38
|
|
|
|
39
|
|
|
'whitelist-global-classes' => false, |
40
|
|
|
'whitelist-global-functions' => false, |
41
|
|
|
'whitelist' => [ |
42
|
|
|
\Composer\Semver\Semver::class, |
43
|
|
|
], |
44
|
|
|
|
45
|
|
|
'patchers' => [ |
46
|
|
|
// `stream_isatty()` is a PHP 7.2 function hence not defined in PHP 7.1. Unlike its function call, the string |
47
|
|
|
// in `function_exists()` is prefixed because the name can be resolved to a FQCN and appears as a user-land |
48
|
|
|
// function. |
49
|
|
|
// |
50
|
|
|
// Function whitelisting is not used here since most checks are in the form of: |
51
|
|
|
// |
52
|
|
|
// ``` |
53
|
|
|
// if (function_exists('stream_isatty') return @stream_isatty($stream); |
54
|
|
|
// ``` |
55
|
|
|
// |
56
|
|
|
// If the function is simply whitelisted, then it will check if the function `Humbug\stream_isatty` exists which |
57
|
|
|
// it will always even though the underlying function may not exists. |
58
|
|
|
// |
59
|
|
|
// The following patcher can be safely removed however once https://github.com/humbug/php-scoper/issues/278 is |
60
|
|
|
// fixed. |
61
|
|
|
// |
62
|
|
|
static function (string $filePath, string $prefix, string $contents): string { |
63
|
|
|
$files = [ |
64
|
|
|
'vendor/symfony/console/Output/StreamOutput.php', |
65
|
|
|
'vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php', |
66
|
|
|
'vendor/symfony/polyfill-php72/bootstrap.php', |
67
|
|
|
'vendor/symfony/polyfill-php72/Php72.php', |
68
|
|
|
'vendor/symfony/var-dumper/Dumper/CliDumper.php', |
69
|
|
|
'vendor/composer/xdebug-handler/src/Process.php', |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
if (false === in_array($filePath, $files, true)) { |
73
|
|
|
return $contents; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$contents = preg_replace( |
77
|
|
|
'/function_exists\(\''.$prefix.'\\\\(\\\\)?stream_isatty\'\)/', |
78
|
|
|
"function_exists('stream_isatty')", |
79
|
|
|
$contents |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$contents = preg_replace( |
83
|
|
|
'/function_exists\(\''.$prefix.'\\\\(\\\\)?sapi_windows_vt100_support\'\)/', |
84
|
|
|
"function_exists('sapi_windows_vt100_support')", |
85
|
|
|
$contents |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
return $contents; |
89
|
|
|
}, |
90
|
|
|
], |
91
|
|
|
]; |
92
|
|
|
|