Skip to content

Add ContentTypeAwarePayload and ContentTypeAwareEncoder#51

Merged
veewee merged 1 commit intophpro:v2.xfrom
veewee:content-type-aware-payload
Apr 2, 2026
Merged

Add ContentTypeAwarePayload and ContentTypeAwareEncoder#51
veewee merged 1 commit intophpro:v2.xfrom
veewee:content-type-aware-payload

Conversation

@veewee
Copy link
Copy Markdown
Contributor

@veewee veewee commented Apr 2, 2026

Summary

  • Adds ContentTypeAwarePayload<T> generic DTO that pairs any payload with a content-type string
  • Adds ContentTypeAwareEncoder<T> decorator that wraps any existing encoder to set the Content-Type header from the payload metadata
  • Composable: works with any encoder (Raw, Stream, ResourceStream, etc.) without modifying existing code

Usage

$encoder = new ContentTypeAwareEncoder(
    ResourceStreamEncoder::createWithAutodiscoveredPsrFactories()
);

// In a request handler:
$payload = new ContentTypeAwarePayload('application/pdf', $resourceStream);

Test plan

  • Unit test: wraps RawEncoder, verifies body content and Content-Type header
  • Unit test: Content-Type from payload overrides pre-existing header
  • Psalm passes
  • PHP-CS-Fixer passes
  • 100% code coverage maintained

@veewee veewee force-pushed the content-type-aware-payload branch from 6339661 to 5325989 Compare April 2, 2026 07:07
@veewee veewee changed the title Add ContentTypeAwarePayload and ContentAwareEncoder Add ContentTypeAwarePayload and ContentTypeAwareEncoder Apr 2, 2026
@veewee veewee force-pushed the content-type-aware-payload branch from 5325989 to c75da34 Compare April 2, 2026 09:03
Introduce a generic DTO that pairs any payload with a content type,
and a decorator encoder that wraps any existing encoder to set the
Content-Type header from the payload metadata.
@veewee veewee force-pushed the content-type-aware-payload branch from c75da34 to 60402f5 Compare April 2, 2026 09:05
@veewee veewee merged commit 27a1835 into phpro:v2.x Apr 2, 2026
4 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