Skip to content

Commit

Permalink
Merge pull request #135 from alustau/implement-custom-vendor-placement
Browse files Browse the repository at this point in the history
  • Loading branch information
deleugpn authored Nov 6, 2023
2 parents d283a70 + f7a8b08 commit 06438bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/HandlerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ private function resolveBootstrapLocation(): string
return $bootstrapFile;
}

// Here we leave 4 levels of folder.
// 1 is the `src` folder inside Laravel Bridge
// 2 are `brefphp/laravel-bridge - the way Composer Packages are formed
// 1 is the `vendor` folder itself, giving a total of 4 levels.
// Once we're in the root of the Laravel project, we can navigate to `bootstrap/app.php` to locate the bootstrap file.
// Going up 4 directories will get us from `vendor/brefphp/laravel-bridge/src`
// to the Laravel root folder so we can navigate to `bootstrap/app.php`
if (file_exists(__DIR__ . '/../../../../bootstrap/app.php')) {
return realpath(__DIR__ . '/../../../../bootstrap/app.php');
}
Expand Down
16 changes: 14 additions & 2 deletions src/bref-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Bref\LaravelBridge\StorageDirectories;

Bref::beforeStartup(static function () {
$laravelHome = realpath(__DIR__ . '/../../../../');
$laravelHome = resolveBootstrapLocation();

if (! defined('STDERR')) {
define('STDERR', fopen('php://stderr', 'wb'));
Expand All @@ -28,7 +28,7 @@
return;
}

$defaultConfigCachePath = $laravelHome . '/bootstrap/cache/config.php';
$defaultConfigCachePath = $laravelHome . '/bootstrap/cache/config.php';

if (file_exists($defaultConfigCachePath)) {
return;
Expand All @@ -50,3 +50,15 @@
});

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 06438bc

Please sign in to comment.