Skip to content

About

The library maps your PHP objects to XML and JSON based on structural attributes that mirror the XSD constructs the model is derived from.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

mmnewmedia/dto-xml-serializer

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
  • 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.

About

The library maps your PHP objects to XML and JSON based on structural attributes that mirror the XSD constructs the model is derived from.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages