simonschaufi/pretty-xml
A tiny PHP library for pretty printing and minifying XML with configurable indent size and character, since DomDocument can't configure indent distance. Install via Composer: simonschaufi/pretty-xml.
format() for humans, minify() for the wire.format, minify) plus two configuration setters (setIndentSize, setIndentCharacter) and has no framework coupling. Frame the options as: (a) adopt via Composer, (b) vendor/copy the formatter under MIT, (c) keep hand-rolling DOMDocument::saveXML() plus regex fixups. Option (c) is the only one that reliably costs more than it saves.local/staging vs. production formatting decision should be a single config flag ("pretty in debug, minified in prod"), not ad-hoc if (app()->isLocal()) scattered across controllers. This package makes that a one-line switch, which is a product-quality decision about predictable output.Adopt when most of the following hold:
DOMDocument hardcodes a 2-space indent and offers no knob. If 2 spaces is fine, the built-in is usually enough.Look elsewhere or write it yourself when:
minify() — or no touch at all — for these.DOMDocument, SimpleXMLElement, or a dedicated XML library; this one is a formatter, and it requires well-formed input.To executives: A free, MIT-licensed utility that makes our XML responses consistent and readable in lower environments and smaller on the wire in production. No infrastructure change, no vendor contract, no lock-in — the entire public surface is a couple of methods, so if it ever becomes a problem we replace it in under a day. The business value is indirect but real: less time spent debugging partner integrations and support tickets, and smaller payloads for XML-consuming clients.
To engineering: Stateless, side-effect-free, PHP-core-only, trivially testable. Pin ^3.1.1 — that release fixes a text-node convergence bug that made repeated formatting drift, which matters the moment formatting lives in middleware that might run twice. Wire it as a single FormatXmlResponse middleware gated on Content-Type: application/xml, guard re-entry with a response flag anyway, keep prettification to local/staging/debug routes, and add two cheap tests: assertXmlStringEqualsXmlString() on a representative fixture, and an explicit format-twice-equals-format-once assertion. Document the one-line rule in the contributing guide so nobody reintroduces a DOMDocument indent hack.
On risk, stated plainly rather than buried: small project, low adoption, one maintainer, patch-level releases with narrow scoped fixes. That profile is acceptable for a leaf-node formatting helper and unacceptable on a critical path for signed or regulated documents — so we scope it accordingly. Mitigations are cheap: vendor or fork under MIT if maintenance lapses, fall back to DOMDocument if anything misbehaves, and cache minified output where the same XML is served repeatedly. The failure mode we care about is silent output corruption, which is why the XML-equality assertion and payload review are part of the adoption, not a later hardening task.
How can I help you explore Laravel packages today?