1
0
Fork 0

Support @php prefix for scripts to reuse the current PHP interpreter, fixes #5957

pull/5636/merge
Jordi Boggiano 2016-12-11 16:14:36 +01:00
parent 9b0ddcd9dd
commit b0000617cc
2 changed files with 30 additions and 1 deletions

View File

@ -249,3 +249,23 @@ resolve to whatever composer.phar is currently being used:
One limitation of this is that you can not call multiple composer commands in
a row like `@composer install && @composer foo`. You must split them up in a
JSON array of commands.
## Executing PHP scripts
To execute PHP scripts, you can use `@php` which will automatically
resolve to whatever php process is currently being used:
```json
{
"scripts": {
"test": [
"@php script.php",
"phpunit"
]
}
}
```
One limitation of this is that you can not call multiple commands in
a row like `@php install && @php foo`. You must split them up in a
JSON array of commands.

View File

@ -233,6 +233,15 @@ class EventDispatcher
}
}
if (substr($exec, 0, 5) === '@php ') {
$finder = new PhpExecutableFinder();
$phpPath = $finder->find();
if (!$phpPath) {
throw new \RuntimeException('Failed to locate PHP binary to execute "'.$exec.'"');
}
$exec = $phpPath . ' ' . substr($exec, 5);
}
if (0 !== ($exitCode = $this->process->execute($exec))) {
$this->io->writeError(sprintf('<error>Script %s handling the %s event returned with error code '.$exitCode.'</error>', $callable, $event->getName()));
@ -460,7 +469,7 @@ class EventDispatcher
*/
protected function isComposerScript($callable)
{
return '@' === substr($callable, 0, 1);
return '@composer ' === substr($callable, 0, 10);
}
/**