<?php
namespace App\Http\Middleware;
use App\Support\ApiResponse;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
final class EnsureApiEnvironment { public function handle(Request $request, Closure $next):Response { $key=$request->attributes->get('apiKey'); if(!$key||$key->environment!==config('gateway.environment')) return ApiResponse::error('ENVIRONMENT_MISMATCH','API key environment does not match this deployment.',403); $request->attributes->set('environment',$key->environment); return $next($request); } }
