mmnewmedia / dto-xml-serializer
DTO <-> XML/JSON serializer driven by XSD-like PHP attribute classes
1.1.0
2026-10-22 20:22 UTC
Requires
- php: ^8.4|^8.5
- ext-dom: *
- ext-json: *
- ext-mbstring: *
- laminas/laminas-serializer: ^4.0
Requires (Dev)
- phpunit/phpunit: ^13.0
- vimeo/psalm: ^6.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 1.1.0
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.0
- dev-issue-17-add-minlength-and-maxlength
- dev-issue-15-fix-release-workflow-repo-context
- dev-issue-13-release-workflow
- dev-issue-11-ci-github-actions-workflow
- dev-issue-9-improve-documentation
- dev-issue-7-add-agentsmd-file
- dev-issue-5-support-for-simpletype-restriction-pattern
- dev-issue-3-enumeration-attribute
- dev-issue-1-root-element
This package is auto-updated.
Last update: 2026-10-22 20:24:35 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-mbstringlaminas/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:
- Overview
- Getting Started
- Mapping - XSD <-> PHP mappings for simple types, complex types, attributes, root elements
- Serialization - XML and JSON serialization
- Validation
- Namespaces
- Migration Guide
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.