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

Add slash in the end of laravel root path and namespacing function #140

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions src/LaravelRootResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Bref\LaravelBridge;

class LaravelRootResolver
{
/**
* Resolve the Laravel root 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 root 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__ . '/../../../../') . '/';
}
}
20 changes: 4 additions & 16 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\LaravelRootResolver;
use Bref\LaravelBridge\HandlerResolver;
use Bref\LaravelBridge\MaintenanceMode;
use Bref\LaravelBridge\StorageDirectories;

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

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

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

if (file_exists($defaultConfigCachePath)) {
return;
Expand All @@ -45,20 +45,8 @@
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 {$laravelHome}artisan config:cache 1>&2");
passthru("php {$laravelRoot}artisan config:cache 1>&2");
}
});

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__ . '/../../../../');
}