Skip to content

Cache type iso in ElementEncoder, refactor value builder/reader#53

Merged
veewee merged 1 commit intophp-soap:mainfrom
veewee:feature/element-encoder-iso-cache
Mar 26, 2026
Merged

Cache type iso in ElementEncoder, refactor value builder/reader#53
veewee merged 1 commit intophp-soap:mainfrom
veewee:feature/element-encoder-iso-cache

Conversation

@veewee
Copy link
Copy Markdown
Member

@veewee veewee commented Mar 26, 2026

Summary

Captures the type iso once in ElementEncoder::iso() and passes it through to avoid redundant iso() rebuilds on every encode/decode call.

ElementValueBuilder

  • Constructor is now private with two static factories: fromEncoder() and fromIso()
  • fromIso() accepts a pre-built iso (used by ElementEncoder which caches it)
  • fromEncoder() builds the iso on the fly (for callsites without a cached iso)
  • Value encoding happens lazily via a closure during __invoke, not eagerly in the constructor
  • Internally stores a list of builder closures composed at construction time; no more stored encoder/context/value
  • Removed deprecated resolveXsiTypeForValue() / shouldIncludeXsiTargetNamespace()

ElementValueReader

  • Added forEncoder(context, encoder, element) and forIso(iso, element) static methods
  • __invoke() delegates to forEncoder() for backwards compatibility
  • forIso() is used by ElementEncoder; forEncoder() by SoapObjectEncoder and ApacheMapEncoder

Impact

~1% improvement (negligible in isolation). The value is in the cleaner API and in establishing the pattern that the iso should be captured once at iso() construction time.

Test plan

  • Full test suite passes (549 tests)
  • Psalm clean (no errors)
  • Benchmarked against main: no regression

…ementValueReader

ElementEncoder now captures the type iso once via $typeEncoder->iso($context)
and passes it to ElementValueBuilder::fromIso() and ElementValueReader::forIso(),
avoiding redundant iso rebuilds on every encode/decode invocation.

ElementValueBuilder:
- Constructor is now private; use fromEncoder() or fromIso() static factories
- Stores a list of builder closures composed at construction time
- Value encoding happens lazily via a valueProvider closure during __invoke
- Removed deprecated resolveXsiTypeForValue/shouldIncludeXsiTargetNamespace

ElementValueReader:
- Added forEncoder(context, encoder, element) and forIso(iso, element)
  static methods for callsites with or without a cached iso
- __invoke delegates to forEncoder for backwards compatibility

SoapObjectEncoder, ApacheMapEncoder: switched to ElementValueReader::forEncoder().
@veewee veewee force-pushed the feature/element-encoder-iso-cache branch from d9d40f8 to fe5b6a8 Compare March 26, 2026 09:42
@veewee veewee merged commit bc9d10b into php-soap:main Mar 26, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant