<?php
namespace App\Middlewares;

class CsrfMiddleware {
    
    public function handle() {
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $token = $_POST['csrf_token'] ?? $_SERVER['HTTP_X_CSRF_TOKEN'] ?? null;
            
            if (!\Security::validateCSRFToken($token)) {
                header('HTTP/1.0 403 Forbidden');
                die('Invalid CSRF token');
            }
        }
    }
}