Merge pull request #9713 from Seldaek/fix-unixy-proxy
Generate binary proxy in PHP if the target binary is detected as a PHP scriptpull/9735/head
commit
cf2128a889
|
@ -191,6 +191,42 @@ class BinaryInstaller
|
|||
$binDir = ProcessExecutor::escape(dirname($binPath));
|
||||
$binFile = basename($binPath);
|
||||
|
||||
$binContents = file_get_contents($bin);
|
||||
if (preg_match('{^(?:#!(?:/usr)?/bin/env php|#!(?:/usr)?/bin/php|<?php)\r?\n}', $binContents, $match)) {
|
||||
$proxyCode = trim($match[0]);
|
||||
// carry over the existing shebang if present, otherwise add our own
|
||||
if ($proxyCode === "<?php") {
|
||||
$proxyCode = "#!/usr/bin/env php";
|
||||
}
|
||||
$binPathExported = var_export($binPath, true);
|
||||
return $proxyCode . "\n" . <<<PROXY
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Proxy PHP file generated by Composer
|
||||
*
|
||||
* This file includes the referenced bin path ($binPath) using eval to remove the shebang if present
|
||||
*
|
||||
* @generated
|
||||
*/
|
||||
|
||||
\$binPath = realpath(__DIR__ . "/" . $binPathExported);
|
||||
\$contents = file_get_contents(\$binPath);
|
||||
\$contents = preg_replace('{^#!/.+\\r?\\n<\\?(php)?}', '', \$contents, 1, \$replaced);
|
||||
if (\$replaced) {
|
||||
\$contents = strtr(\$contents, array(
|
||||
'__FILE__' => var_export(\$binPath, true),
|
||||
'__DIR__' => var_export(dirname(\$binPath), true),
|
||||
));
|
||||
|
||||
eval(\$contents);
|
||||
exit(0);
|
||||
}
|
||||
include \$binPath;
|
||||
|
||||
PROXY;
|
||||
}
|
||||
|
||||
$proxyCode = <<<PROXY
|
||||
#!/usr/bin/env sh
|
||||
|
||||
|
|
Loading…
Reference in New Issue