ifnex/04_Laravel/bootstrap/app.php
Kazem Alghasi a1a6dbdd8a feat(core): complete phase 3 integration and enhance country/phone features
This commit marks the completion of Phase 3 (Integration and Improvements) and updates the project status to reflect that Phases 0 through 3 are finished.

Key changes include:
- **Laravel (Backend):**
  - Added `calling_code` column to `countries` table via new migration.
  - Added scripts to update calling codes for all countries.
  - Updated `CustomerOrderController` to include `calling_code` in country data.
  - Registered `api_key` middleware alias in `bootstrap/app.php`.
  - Improved error handling to return JSON 401 for API authentication failures.
  - Updated `README.md` with detailed architecture and feature descriptions.
- **WordPress (Frontend/Bridge):**
  - Added `ifnex_wallet_charge` shortcode and AJAX handler for wallet top-ups.
  - Implemented auto-fill for calling codes in the order form based on selected country.
  - Added real-time phone number validation (digits, +, spaces only).
  - Added English-only validation for name, city, and address fields with UI warnings.
  - Updated asset enqueuing logic and versioning for CSS/JS.
- **Documentation:**
  - Updated `IFNEX_File_Map.md`, `IFNEX_Phase0_Checklist.md`, and `IFNEX_Roadmap.md` to reflect completed phases and new features.
  - Updated `DEPLOYMENT.md` with new environment variables (`IFNEX_BRIDGE_API_KEY`) and required WordPress pages.
  - Updated project `README.md` with comprehensive feature list and system architecture.
2026-08-29 04:38:28 +03:30

56 lines
2.3 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use App\Http\Middleware\ApiKeyAuth;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withCommands([
\App\Console\Commands\ImportShippingRates::class,
\App\Console\Commands\ImportTrackingData::class,
\App\Console\Commands\UpdateExchangeRates::class,
\App\Console\Commands\GenerateApiToken::class,
\App\Console\Commands\SyncWordPressUsers::class,
])
->withMiddleware(function (Middleware $middleware): void {
$middleware->alias([
'api_key' => ApiKeyAuth::class,
]);
// Stateful API برای Sanctum
$middleware->statefulApi();
// API با CORS
$middleware->api(prepend: \Illuminate\Http\Middleware\HandleCors::class);
// گروه web برای Filament و صفحات عادی
$middleware->group('web', [
\Illuminate\Cookie\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
]);
})
->withExceptions(function (Exceptions $exceptions): void {
// برای APIها، به جای redirect به login، JSON 401 برگردان
$exceptions->render(function (AuthenticationException $e, Request $request) {
if ($request->is('api/*') || $request->expectsJson() || $request->wantsJson()) {
return response()->json([
'success' => false,
'message' => 'Unauthenticated',
'error' => 'توکن نامعتبر است یا منقضی شده است. لطفاً دوباره وارد شوید.',
], 401);
}
});
})->create();