Search by

mmnewmedia / dto-xml-serializer

ezkimo

DTO <-> XML/JSON serializer driven by XSD-like PHP attribute classes

Package info

github.com/ezkimo/dto-xml-serializer

pkg:composer/mmnewmedia/dto-xml-serializer

Statistics

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

1.1.0 2026-10-22 20:22 UTC

README

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.

Requirements

  • PHP ^8.4|^8.5
  • ext-dom, ext-json, ext-mbstring
  • laminas/laminas-serializer ^4.0

Installation

composer require mmnewmedia/dto-xml-serializer

Quick Start

use 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);

Documentation

See the full documentation in the /docs directory:

Tests

composer install
composer test

Static Analysis

composer psalm

Psalm runs with errorLevel="5". See psalm.xml for details.

License

This project is licensed under the BSD 3‑Clause License.
See the LICENSE file for the full text.