Skip to content

Commit

Permalink
[11.x] Allows Laravel Framework to correctly resolve PHP binary when …
Browse files Browse the repository at this point in the history
…running via Laravel Herd (#52791)

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* Apply fixes from StyleCI

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* Apply fixes from StyleCI

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* Update src/Illuminate/Support/functions.php

Co-authored-by: Marcel Pociot <[email protected]>

* Apply fixes from StyleCI

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Marcel Pociot <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent 0d0f55f commit d582690
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"src/Illuminate/Filesystem/functions.php",
"src/Illuminate/Foundation/helpers.php",
"src/Illuminate/Log/functions.php",
"src/Illuminate/Support/functions.php",
"src/Illuminate/Support/helpers.php"
],
"psr-4": {
Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Process\PhpExecutableFinder;

use function Illuminate\Support\php_binary;

class Application extends SymfonyApplication implements ApplicationContract
{
Expand Down Expand Up @@ -84,7 +85,7 @@ public function __construct(Container $laravel, Dispatcher $events, $version)
*/
public static function phpBinary()
{
return ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false) ?: 'php');
return ProcessUtils::escapeArgument(php_binary());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Illuminate\Foundation\Console;

use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

use function Illuminate\Support\php_binary;

trait InteractsWithComposerPackages
{
/**
Expand Down Expand Up @@ -39,6 +40,6 @@ protected function requireComposerPackages(string $composer, array $packages)
*/
protected function phpBinary()
{
return (new PhpExecutableFinder())->find(false) ?: 'php';
return php_binary();
}
}
5 changes: 3 additions & 2 deletions src/Illuminate/Queue/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Illuminate\Queue;

use Closure;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

use function Illuminate\Support\php_binary;

class Listener
{
/**
Expand Down Expand Up @@ -61,7 +62,7 @@ public function __construct($commandPath)
*/
protected function phpBinary()
{
return (new PhpExecutableFinder)->find(false) ?: 'php';
return php_binary();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Support/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Filesystem\Filesystem;
use RuntimeException;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

class Composer
Expand Down Expand Up @@ -204,7 +203,7 @@ protected function findComposerFile()
*/
protected function phpBinary()
{
return (new PhpExecutableFinder)->find(false) ?: 'php';
return php_binary();
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/Illuminate/Support/Process/PhpExecutableFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Illuminate\Support\Process;

use Symfony\Component\Process\PhpExecutableFinder as SymfonyPhpExecutableFinder;

class PhpExecutableFinder extends SymfonyPhpExecutableFinder
{
/**
* Finds The PHP executable.
*/
#[\Override]
public function find(bool $includeArgs = true): string|false
{
if ($herdPath = getenv('HERD_HOME')) {
return (new ExecutableFinder)->find('php', false, [implode(DIRECTORY_SEPARATOR, [$herdPath, 'bin'])]);
}

return parent::find($includeArgs);
}
}
1 change: 1 addition & 0 deletions src/Illuminate/Support/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Illuminate\\Support\\": ""
},
"files": [
"functions.php",
"helpers.php"
]
},
Expand Down
15 changes: 15 additions & 0 deletions src/Illuminate/Support/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Illuminate\Support;

use Illuminate\Support\Process\PhpExecutableFinder;

/**
* Determine the PHP Binary.
*
* @return string
*/
function php_binary()
{
return (new PhpExecutableFinder)->find(false) ?: 'php';
}

0 comments on commit d582690

Please sign in to comment.