Services
Available Services
| Interface | Class | Purpose |
|---|---|---|
Contract\SerializerInterface |
Service\Serializer |
Turn a document into a json/yaml/xml string. |
Contract\DeserializerInterface |
Service\Deserializer |
Turn a json/yaml/xml string into a document. |
Contract\ValidatorInterface |
Service\SchemaValidator |
Validate a document’s XML against the official XSD. |
Contract\FormatHandlerFactoryInterface |
Service\FormatHandlerFactory |
Resolve a format name to the handler that implements it; register a custom one. |
Every class is namespaced under Derafu\Ubl\. See Formats for Serializer/Deserializer
usage and Validation for SchemaValidator.
Exceptions
Every exception this package throws extends Derafu\Ubl\Exception\UblException, itself a
Derafu\Translation\Exception\Core\TranslatableException:
| Exception | Thrown when |
|---|---|
UnsupportedFormatException |
A format name is not json, yaml or xml (or a custom registered one). |
SerializationException |
A document cannot be turned into the requested format. |
DeserializationException |
Content cannot be turned into a document (invalid JSON/YAML, an unknown document type, …). |
ValidationException |
A document’s XML does not validate against the schema. Carries the real LibXMLError list, see Validation. |
Catching the base UblException catches any of them:
use Derafu\Ubl\Exception\UblException;
try {
$document = (new Deserializer())->deserialize($content, 'yaml');
} catch (UblException $e) {
// SerializationException, DeserializationException, ValidationException, ...
}
Dependency Injection
For an application using symfony/dependency-injection, resources/config/ubl-services.yaml
wires every service above to its interface, ready to autowire:
imports:
- { resource: '../vendor/derafu/ubl/resources/config/ubl-services.yaml' }
With that imported, a service can simply type-hint the interface it needs:
use Derafu\Ubl\Contract\SerializerInterface;
final class QuotationController
{
public function __construct(
private readonly SerializerInterface $serializer,
) {
}
}
On this page
Last updated on 12/10/2026
by Anonymous