Skip to content

Commit

Permalink
Add slash in the end of laravel home path when use realpath
Browse files Browse the repository at this point in the history
  • Loading branch information
alustau committed Nov 13, 2023
1 parent cf8341c commit 48df7cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
24 changes: 24 additions & 0 deletions src/LaravelHomeResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Bref\LaravelBridge;

class LaravelHomeResolver
{
/**
* Resolve the Laravel home path.
*
* @return string
*/
public static function resolvePath(): string
{
$laravelHome = $_SERVER['LAMBDA_TASK_ROOT'] . '/bootstrap/cache/config.php';

// If the config cache exists, we can assume that the Laravel home path is the same as the Lambda task root
if (file_exists($laravelHome)) {
return $_SERVER['LAMBDA_TASK_ROOT'];
}

// the fallback is going up 4 directories will get us from `vendor/brefphp/laravel-bridge/src` to the Laravel root folder
return realpath(__DIR__ . '/../../../../') . '/';
}
}
16 changes: 2 additions & 14 deletions src/bref-init.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

use Bref\Bref;

use Bref\LaravelBridge\LaravelHomeResolver;
use Bref\LaravelBridge\HandlerResolver;
use Bref\LaravelBridge\MaintenanceMode;
use Bref\LaravelBridge\StorageDirectories;

Bref::beforeStartup(static function () {
$laravelHome = resolveBootstrapLocation();
$laravelHome = LaravelHomeResolver::resolvePath();

if (! defined('STDERR')) {
define('STDERR', fopen('php://stderr', 'wb'));
Expand Down Expand Up @@ -50,15 +50,3 @@
});

Bref::setContainer(static fn() => new HandlerResolver);

function resolveBootstrapLocation(): string
{
$laravelHome = $_SERVER['LAMBDA_TASK_ROOT'] . '/bootstrap/cache/config.php';

if (file_exists($laravelHome)) {
return $_SERVER['LAMBDA_TASK_ROOT'];
}

// Going up 4 directories will get us from `vendor/brefphp/laravel-bridge/src` to the Laravel root folder
return realpath(__DIR__ . '/../../../../');
}

0 comments on commit 48df7cf

Please sign in to comment.