Repository navigation
Releases: magicsunday/xmlmapper
Releases · magicsunday/xmlmapper
Release list
4.0.0
⚠️ Breaking changes
- A new encoder is strict by default.
new XmlEncoder($extractor)now throwsUnmappableValueExceptionfor a value it cannot map, instead of dropping it without a signal. The message names the property path and the type of the value. Anullstays empty and aStringableobject is written as its text in both modes. - Raised the PHP floor to
^8.4. PHP 8.3 is no longer supported. XmlEncoder::$nameConverteris private and read-only. It was protected. A subclass that read the property has to change.CamelCasePropertyNameConverteris a final read-only class. It can no longer be extended. ImplementPropertyNameConverterInterfaceinstead.
🔧 Internal
- Property hooks are read through the reflection API directly, the PHP 8.3 fallbacks are gone.
- A property with a stored value and a
gethook is pinned by a test, the encoder writes what the hook returns. - Copy-paste detection runs through the shared workflow, with jscpd pinned in
package.json. Runnpm cionce before the localci:test.
🧭 Migration
- To keep dropping an unmappable value silently, pass
falseas the third constructor argument:new XmlEncoder($extractor, $nameConverter, false). - Move to PHP 8.4 or newer.
- Replace a subclass of the converter by an implementation of the interface.
The 3.x line (PHP 8.3, lenient default) is maintained on the 3.x branch.
3.2.0
Added
- Opt-in strict mode.
new XmlEncoder($extractor, $nameConverter, true)throwsUnmappableValueExceptionfor a value it cannot map instead of dropping it without a signal. The message names the property path and the type of the value. UnmappableValueException, aRuntimeExceptionwith named constructors for a value that is neither scalar norStringableand for a collection value that cannot be iterated.
The default stays lenient, so an existing encoder behaves exactly as before. A null stays empty and a Stringable object is written as its text in both modes.
Documentation
- The API reference and the recipes describe which values a lenient encoder drops and what a strict encoder does instead. This covers an unresolved array, a nested object without the marker interface, a marker on a collection and a collection converter that returns no iterable.
3.1.0
Added
#[XmlIgnore]keeps a property out of the XML. It is checked before the property is read, so neither the field nor a custom type converter is touched.addType()accepts a fully qualified class or interface name and matches it before theobjectcatch-all, so a converter can target one value object.CircularReferenceException:map()stops with it on a cyclic object graph instead of recursing without bound. The message names the property path that closes the cycle.InvalidXmlValueException:map()refuses a value that XML 1.0 cannot carry (a character below the space other than tab, line feed and carriage return, U+FFFE, U+FFFF, or a string that is not valid UTF-8). The message names the property path.
Fixed
- Values containing an ampersand are no longer corrupted when written through the element path.
map()is repeatable. Every call builds a fresh document.- A typed property that was never assigned is skipped like a
nullvalue instead of raising anError. - A write-only virtual property (PHP 8.4, a
sethook without agethook) is skipped instead of raising anError. - A static property is no longer encoded as state of the object.
- Documentation corrected where it described behaviour the code does not implement. The documented extractor setup now lists both extractors for the types.
Changed
- Dropped the unused
symfony/property-accessrequirement. A project that uses it directly must require it itself. - Behaviour to be aware of: a string that contains a character XML 1.0 forbids, or that is not valid UTF-8, now raises
InvalidXmlValueExceptioninstead of producing a document that cannot be parsed. A public static property that used to appear in the XML no longer does.
Internal
- Development tooling moved to the shared
magicsunday/coding-standardruleset, including the Deptrac architecture layers.
3.0.1
Fixed
- Updated GitHub Actions workflow pins and version comments for the latest released action tags.
- Removed redundant PHPDoc so Rector dry-runs remain clean.
Internal
- Kept CI and security workflows aligned with the shared repository setup.
- Sorted development dependencies and refreshed dependency automation metadata.
3.0.0
⚠️ Breaking changes
- Dropped the Doctrine docblock-annotation marker support. The property markers
XmlAttribute,XmlNodeValueandXmlCDataSectionare now recognised only as native PHP attributes (#[XmlAttribute],#[XmlNodeValue],#[XmlCDataSection]). The legacy@XmlAttribute/@XmlNodeValue/@XmlCDataSectionPHPDoc syntax is no longer read. - Removed the
doctrine/annotationsdependency (it was abandoned and only powered the docblock path). - Raised the PHP floor to
^8.3— PHP 8.2 is no longer supported.
🔧 Internal
- Marker resolution reads a property's attributes in a single reflection pass (exact name match, since the marker classes are
final). - Tested against PHPUnit 12 / 13 (PHP 8.3 → 12, 8.4/8.5 → 13); Rector raised to the PHP 8.3 level.
🧭 Migration
- Replace docblock markers with the native attribute form:
@XmlAttribute→#[XmlAttribute], etc. - Move to PHP 8.3 or newer.
The 2.x line (Doctrine docblock annotations, PHP 8.2) is maintained on the 2.x branch.
2.0.0
⚠️ Breaking changes
- Dropped Symfony 6 support.
symfony/property-infoandsymfony/property-accessnow require^7.3 || ^8.0. - Added
symfony/type-infoas a required dependency — the encoder was migrated from the legacy type resolution tosymfony/type-info. - The supported PHP range is now open-ended (
^8.2), covering PHP 8.5.
✨ Features
- Native PHP 8 attribute syntax for the property markers:
#[XmlAttribute],#[XmlNodeValue],#[XmlCDataSection]— usable interchangeably with the existing Doctrine docblock annotations (@XmlAttribute, …).
🐛 Fixes
- Correctly encode collections whose value type is a union of object types (and mixed scalar/object unions) by routing each entry on its runtime value instead of the static union type.
⚡ Performance
- Memoize the resolved property markers per class property and cache the Doctrine annotation reader across property checks, eliminating redundant reflection and docblock parsing.
🔧 Maintenance
- PHPStan raised to max level (no baseline).
- Tested against PHPUnit 11 / 12 / 13 (PHP 8.2 → 11, 8.3 → 12, 8.4/8.5 → 13).
- Development tooling aligned with
magicsunday/jsonmapper(jscpd copy-paste gate, centralised caches); CI extended to PHP 8.5.