🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 13:19
This commit is contained in:
43
app/Middleware/TenantMiddleware.php
Normal file
43
app/Middleware/TenantMiddleware.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Core\{Request, Response, Database};
|
||||
|
||||
final class TenantMiddleware
|
||||
{
|
||||
public function handle(Request $request, callable $next): mixed
|
||||
{
|
||||
$tenantId = $request->tenantId ?? null;
|
||||
|
||||
if (!$tenantId) {
|
||||
Response::error('المستأجر غير معروف', 'TENANT_NOT_FOUND', 400);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if tenant exists and is active
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$stmt = $db->prepare("SELECT status FROM tenants WHERE id = ? AND deleted_at IS NULL");
|
||||
$stmt->execute([$tenantId]);
|
||||
$tenant = $stmt->fetch();
|
||||
|
||||
if (!$tenant) {
|
||||
Response::error('المستأجر غير موجود', 'TENANT_NOT_FOUND', 404);
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($tenant['status'] === 'suspended') {
|
||||
Response::error('تم إيقاف حساب المستأجر', 'TENANT_SUSPENDED', 403);
|
||||
return null;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Response::error('خطأ في الاتصال بقاعدة البيانات', 'DATABASE_ERROR', 500);
|
||||
return null;
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user