---
title: "Services"
description: "The services this package provides, their interfaces, exceptions, and how to wire them with Symfony&#039;s dependency injection"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-10-12"
last_update: "2026-10-12"
time_minutes: 2
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/data/ubl/services"
---

# 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:

```php
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:

```yaml
imports:
    - { resource: '../vendor/derafu/ubl/resources/config/ubl-services.yaml' }
```

With that imported, a service can simply type-hint the interface it needs:

```php
use Derafu\Ubl\Contract\SerializerInterface;

final class QuotationController
{
    public function __construct(
        private readonly SerializerInterface $serializer,
    ) {
    }
}
```



---
Last updated on 12/10/2026

