Added PDF generation service for management reports as per Spec 378, including Gotenberg integration in docker-compose and configuration updates. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #449
85 lines
2.3 KiB
PHP
85 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Pdf;
|
|
|
|
final class PdfRenderResult
|
|
{
|
|
public const string RENDERER_DISABLED = 'renderer_disabled';
|
|
|
|
public const string PAYLOAD_TOO_LARGE = 'payload_too_large';
|
|
|
|
public const string INVALID_ASSET = 'invalid_asset';
|
|
|
|
public const string INVALID_REQUEST = 'invalid_request';
|
|
|
|
public const string INVALID_RESPONSE = 'invalid_response';
|
|
|
|
public const string OUTPUT_TOO_LARGE = 'output_too_large';
|
|
|
|
public const string RENDERER_TIMEOUT = 'renderer_timeout';
|
|
|
|
public const string RENDERER_UNAVAILABLE = 'renderer_unavailable';
|
|
|
|
public const string RENDERER_FAILED = 'renderer_failed';
|
|
|
|
private function __construct(
|
|
private readonly bool $successful,
|
|
public readonly ?string $pdfBytes,
|
|
public readonly ?string $contentType,
|
|
public readonly ?string $outputFilename,
|
|
public readonly ?string $correlationId,
|
|
public readonly ?string $failureCode,
|
|
public readonly ?string $safeMessage,
|
|
public readonly ?int $statusCode,
|
|
) {}
|
|
|
|
public static function success(
|
|
string $pdfBytes,
|
|
string $contentType = 'application/pdf',
|
|
?string $outputFilename = null,
|
|
?string $correlationId = null,
|
|
?int $statusCode = 200,
|
|
): self {
|
|
return new self(
|
|
successful: true,
|
|
pdfBytes: $pdfBytes,
|
|
contentType: $contentType,
|
|
outputFilename: $outputFilename,
|
|
correlationId: $correlationId,
|
|
failureCode: null,
|
|
safeMessage: null,
|
|
statusCode: $statusCode,
|
|
);
|
|
}
|
|
|
|
public static function failure(
|
|
string $failureCode,
|
|
string $safeMessage,
|
|
?int $statusCode = null,
|
|
?string $correlationId = null,
|
|
): self {
|
|
return new self(
|
|
successful: false,
|
|
pdfBytes: null,
|
|
contentType: null,
|
|
outputFilename: null,
|
|
correlationId: $correlationId,
|
|
failureCode: $failureCode,
|
|
safeMessage: $safeMessage,
|
|
statusCode: $statusCode,
|
|
);
|
|
}
|
|
|
|
public function successful(): bool
|
|
{
|
|
return $this->successful;
|
|
}
|
|
|
|
public function failed(): bool
|
|
{
|
|
return ! $this->successful;
|
|
}
|
|
}
|