Update: laravel 8 to 12, php 7.3 to php 8.3, Jenkinsfile, Unit/Feature testing, vapor, docker

This commit is contained in:
Dillon Ngo
2026-04-03 06:59:39 +08:00
parent 58de1017d7
commit b34b7c19d6
142 changed files with 3334 additions and 1101 deletions
+138 -46
View File
@@ -1,55 +1,147 @@
<?php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
use App\Http\Middleware\ValidateToken;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Support\Facades\Route;
use App\Classes\ValueObjects\Constants\HttpStatus;
use App\Classes\ValueObjects\Response\ApiResponseObject;
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
api: __DIR__ . '/../routes/api.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
then: function () {
// Load public API routes (not loaded in api.php)
Route::middleware('apipub')
->prefix('public/api')
->group(base_path('routes/apipub.php'));
},
)
->withMiddleware(function (Middleware $middleware) {
// '*' trusts all proxies, required for correct IP/HTTPS detection behind AWS ALB/Vapor
$middleware->trustProxies(at: '*');
/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/
$middleware->web(append: [
\App\Http\Middleware\LogRequestPathMiddleware::class,
]);
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
$middleware->api(append: [
\App\Http\Middleware\LogRequestPathMiddleware::class,
]);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$middleware->api(prepend: [
'throttle:300,1',
]);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$middleware->validateCsrfTokens(except: [
/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
]);
return $app;
$middleware->alias([
'valid.token' => ValidateToken::class,
'token.check' => \App\Http\Middleware\TokenCheckerMiddleware::class,
'admin' => \App\Http\Middleware\EnsureUserIsAdmin::class,
]);
$middleware->appendToGroup('apipub', [
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\LogRequestPathMiddleware::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
// Custom exception rendering
// $exceptions->render(function (MaintenanceModeException $e, $request) {
// return response()->view('pages.errors.maintenance');
// });
$exceptions->render(function (AuthenticationException $e, $request) {
return (new ApiResponseObject(
'Authentication',
'To keep your account secure, we need to re-validate it.',
HttpStatus::ACCESS_UNAUTHORISED
))->handler();
});
// Don't flash these inputs
$exceptions->dontFlash([
'password',
'password_confirmation',
]);
})
->withCommands([
__DIR__ . '/../app/Console/Commands',
__DIR__ . '/../app/Console/Commands/V2',
])
->withSchedule(function ($schedule) {
// Commands Version 2: Laravel Vapor/AWS
$isEnabled = env('COMMANDS_V2_ENABLED', false);
if ($isEnabled) {
$schedule->command('housekeeping-s3-files-command')
->dailyAt('01:00')
->withoutOverlapping();
$schedule->command('password-reset-token-expriration-check-command')
->everySixHours()
->withoutOverlapping();
$schedule->command('new-user-registration-expire-check-command')
->everySixHours()
->withoutOverlapping();
if (env('APP_ENV') === 'production') {
$schedule->command('email-do-to-vt-command')
->dailyAt('10:00')
->withoutOverlapping();
$schedule->command('seasonal-segmant-company-remove-command')
->dailyAt('01:00')
->withoutOverlapping();
$schedule->command('delete-bulk-download-files-command')
->hourly()
->withoutOverlapping();
$schedule->command('booking-expired-command')
->dailyAt('02:00')
->withoutOverlapping();
// Push company module to Lark
$schedule->command('lark:push-company-module')
->hourly()
->withoutOverlapping();
// Push booking module to Lark
$schedule->command('lark:push-booking-module')
->hourly()
->withoutOverlapping();
}
}
// Commands Version 1: Before Laravel Vapor/AWS
else {
$schedule->command('mail:EmailDoToVTCommand')
->dailyAt('10:00')
->withoutOverlapping();
$schedule->command('seasonalSegmantCompany:remove')
->dailyAt('01:00')
->appendOutputTo(storage_path() . '/logs/soft-delete-seasonal-segmant-company.log')
->withoutOverlapping();
$schedule->command('delete:bulk-download-files')
->hourly()
->appendOutputTo(storage_path() . '/logs/delete-bulk-download-files.log')
->withoutOverlapping();
$schedule->command('booking:expired')
->dailyAt('02:00')
->appendOutputTo(storage_path() . '/logs/expire-booking.log')
->withoutOverlapping();
}
})
->create();