DTO -> XML and DTO <-> JSON serialization for PHP, driven by XSD-like PHP attribute classes.
The library maps your PHP objects to XML and JSON based on structural attributes that mirror the XSD constructs the model is derived from.
- PHP ^8.4|^8.5
ext-dom,ext-jsonlaminas/laminas-serializer^4.0
composer require mmnewmedia/dto-xml-serializeruse MMNewmedia\Model\ValueableInterface;
use MMNewmedia\Model\ValueableTrait;
use MMNewmedia\Xsd;
#[Xsd\SimpleType]
#[Xsd\Restriction(base: 'xsd:string')]
#[Xsd\Enumeration(enum: CurrencyCode::class)]
final class CurrencyCodeType implements ValueableInterface
{
use ValueableTrait;
}use MMNewmedia\Serializer\XmlDtoSerializer;
$serializer = new XmlDtoSerializer();
$serializer->setNamespaces(HeaderNamespaces::class);
$xml = $serializer->serialize($invoice);use MMNewmedia\Serializer\JsonDtoSerializer;
$serializer = new JsonDtoSerializer();
$serializer->setRootClasses(['Invoice' => InvoiceType::class]);
$invoice = $serializer->unserialize($json);See the full documentation in the /docs directory:
- Overview
- Getting Started
- Mapping - XSD <-> PHP mappings for simple types, complex types, attributes, root elements
- Serialization - XML and JSON serialization
- Validation
- Namespaces
- Migration Guide
composer install
composer testcomposer psalmPsalm runs with errorLevel="5". See psalm.xml for details.
This project is licensed under the BSD 3‑Clause License.
See the LICENSE file for the full text.