errorCode) { return $this->errorCode; } $request = $this->requestStack->getMainRequest(); if (null === $request) { return null; } $requestId = $request->attributes->get('request_id'); if (null === $requestId) { return null; } $this->errorCode = $this->generateCode((string) $requestId); return $this->errorCode; } /** * Marks that an error has occurred during this request. * * Called by the ErrorCodeProcessor when a log entry with ERROR level * or higher is created. */ public function markErrorOccurred(): void { $this->hasError = true; } /** * Checks whether an error has been logged during this request. * * @return bool True if an error has been logged, false otherwise */ public function hasError(): bool { return $this->hasError; } /** * Generates an error code from a request ID. * * Strips sequence suffixes, hashes the normalized ID, and converts * to a base36 representation prefixed with E-. * * @param string $requestId The request ID to generate a code from * * @return string The generated error code in format E-XXXXXXXX */ private function generateCode(string $requestId): string { $normalizedId = preg_replace('/_\d+$/', '', $requestId); $hash = md5((string) $normalizedId); $hexPart = substr($hash, 0, 12); $decimal = hexdec($hexPart); $base36 = strtoupper(base_convert((string) $decimal, 10, 36)); $padded = str_pad($base36, 8, '0', STR_PAD_LEFT); return 'E-'.substr($padded, 0, 8); } }