pdftract/sdk/php/src/Pdftract/Models/Diagnostic.php
jedarden 246befd8d1 feat(pdftract-2m3gl): implement PHP SDK with Packagist publishing
- Add jedarden/pdftract Composer package (sdk/php/)
- Implement Client.php with proc_open subprocess execution
- Add PSR-3 LoggerInterface integration (defaults to NullLogger)
- Add 9 contract methods: extract, extractText, extractMarkdown, extractStream, search, getMetadata, hash, classify, verifyReceipt
- Add readonly model classes: Document, Page, Metadata, Fingerprint, Classification, Match, Receipt
- Add exception classes: PdftractException base + 8 subclasses
- Add PHPUnit conformance test suite
- Add phpunit.xml configuration
- Add composer.json with jedarden/pdftract package name
- Add .ci/argo-workflows/pdftract-php-publish.yaml (Packagist auto-discovery from git tags)

Also includes Ruby SDK scaffold from parallel workflow.

Closes pdftract-2m3gl
2026-06-01 10:27:03 -04:00

96 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Jedarden\Pdftract\Models;
/**
* JSON representation of a diagnostic error
*
* This struct wraps the internal Diagnostic type for JSON serialization,
* providing stable error codes and human-readable messages for consumers.
*/
class Diagnostic
{
/**
* Stable string identifier for this diagnostic (e.g., "FONT_GLYPH_UNMAPPED")
*/
public string $code;
/**
* Human-readable description of the diagnostic
*/
public string $message;
/**
* Severity level: "info", "warning", "error", or "fatal"
*/
public string $severity;
/**
* Page index where this diagnostic occurred, or null for document-level events
*/
public ?int $page_index = null;
/**
* PDF object reference where the issue originated, if applicable
*/
public ?ObjectLocation $location = null;
/**
* Optional hint for resolving the diagnostic
*
* Example: "Install Tesseract for OCR recovery"
*/
public ?string $hint = null;
/**
* Create Diagnostic from JSON array
*
* @param array<string,mixed> $data JSON data
* @return self
*/
public static function fromArray(array $data): self
{
$diag = new self();
$diag->code = $data['code'];
$diag->message = $data['message'];
$diag->severity = $data['severity'];
$diag->page_index = $data['page_index'] ?? null;
$diag->hint = $data['hint'] ?? null;
if (isset($data['location']) && $data['location'] !== null) {
$diag->location = ObjectLocation::fromArray($data['location']);
}
return $diag;
}
/**
* Convert to JSON array
*
* @return array<string,mixed>
*/
public function toArray(): array
{
$data = [
'code' => $this->code,
'message' => $this->message,
'severity' => $this->severity,
];
if ($this->page_index !== null) {
$data['page_index'] = $this->page_index;
}
if ($this->location !== null) {
$data['location'] = $this->location->toArray();
}
if ($this->hint !== null) {
$data['hint'] = $this->hint;
}
return $data;
}
}