getHeaderLine(self::HEADER_NAME)); if ($provided === '') { $body = $request->getParsedBody(); if (is_array($body)) { $candidate = isset($body[self::FORM_FIELD]) ? $body[self::FORM_FIELD] : (isset($body['_csrf']) ? $body['_csrf'] : ''); $provided = is_scalar($candidate) ? trim((string) $candidate) : ''; } } if (preg_match('/^[a-f0-9]{64}$/', $provided) !== 1) { return false; } return hash_equals(self::token(), $provided); } public static function requiresProtection($method) { return in_array(strtoupper((string) $method), ['POST', 'PUT', 'PATCH', 'DELETE'], true); } private static function sessionKey() { $user = Auth::getUser(); $userId = is_object($user) && isset($user->id) ? max(0, (int) $user->id) : 0; return self::SESSION_PREFIX . $userId; } }