-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from brefphp/custom-vendor-placement
Allow to run Laravel under custom vendor location
- Loading branch information
Showing
3 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Bref\LaravelBridge; | ||
|
||
use RuntimeException; | ||
|
||
final class LaravelPathFinder | ||
{ | ||
/** | ||
* Resolve the Laravel root path. Path is always returned without a leading slash. | ||
* | ||
* @return string | ||
*/ | ||
public static function root(): string | ||
{ | ||
$app = $_SERVER['LAMBDA_TASK_ROOT'] . '/bootstrap/app.php'; | ||
|
||
// If the config cache exists, we can assume that the Laravel root path is the same as the Lambda task root. | ||
// This may not be needed as the fallback "should" work in all cases, but we're keeping | ||
// this as it's safer to keep 100% compatibility with the original implementation. | ||
if (file_exists($app)) { | ||
return $_SERVER['LAMBDA_TASK_ROOT']; | ||
} | ||
|
||
// If Laravel is installed on a sub-folder, we can navigate from where we are | ||
// (inside composer) to the root of Laravel. | ||
// We will go up 4 directories, represented by `vendor/brefphp/laravel-bridge/src`. | ||
return realpath(__DIR__ . '/../../../../'); | ||
} | ||
|
||
public static function app(): string | ||
{ | ||
$bootstrapFile = self::root() . '/bootstrap/app.php'; | ||
|
||
if (file_exists($bootstrapFile)) { | ||
return $bootstrapFile; | ||
} | ||
|
||
throw new RuntimeException( | ||
"Unable to locate `{$bootstrapFile}`: Bref tried to load that file to retrieve the Laravel app" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters