Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to run Laravel under custom vendor location #131

Merged
merged 22 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/HandlerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,7 @@ private function laravel(): Application
return $this->laravel;
}

$bootstrapFile = getcwd() . '/bootstrap/app.php';

if (! file_exists($bootstrapFile)) {
throw new RuntimeException(
"Unable to locate `{$bootstrapFile}`: Bref tried to load that file to retrieve the Laravel app"
);
}
$bootstrapFile = $this->resolveBootstrapLocation();

$this->laravel = require $bootstrapFile;

Expand All @@ -96,4 +90,26 @@ private function laravel(): Application

return $this->laravel;
}

private function resolveBootstrapLocation(): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems to duplicate the other resolveBootstrapLocation() function, but with a slightly different implementation (but same name), any reason for that?

Can we merge both functions into one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just addressed this

{
$bootstrapFile = getcwd() . '/bootstrap/app.php';

if (file_exists($bootstrapFile)) {
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.
tillkruss marked this conversation as resolved.
Show resolved Hide resolved
if (file_exists(__DIR__ . '/../../../../bootstrap/app.php')) {
tillkruss marked this conversation as resolved.
Show resolved Hide resolved
return realpath(__DIR__ . '/../../../../bootstrap/app.php');
}

throw new RuntimeException(
"Unable to locate `{$bootstrapFile}`: Bref tried to load that file to retrieve the Laravel app"
);
}
}
6 changes: 4 additions & 2 deletions src/bref-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Bref\LaravelBridge\StorageDirectories;

Bref::beforeStartup(static function () {
$laravelHome = realpath(__DIR__ . '/../../../../');
tillkruss marked this conversation as resolved.
Show resolved Hide resolved

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

$defaultConfigCachePath = $_SERVER['LAMBDA_TASK_ROOT'] . '/bootstrap/cache/config.php';
$defaultConfigCachePath = $laravelHome . '/bootstrap/cache/config.php';

if (file_exists($defaultConfigCachePath)) {
return;
Expand All @@ -43,7 +45,7 @@
fwrite(STDERR, "Running 'php artisan config:cache' to cache the Laravel configuration\n");

// 1>&2 redirects the output to STDERR to avoid messing up HTTP responses with FPM
passthru('php artisan config:cache 1>&2');
passthru("php {$laravelHome}artisan config:cache 1>&2");
}
});

Expand Down