Skip to content

Replace data response by data stream (big refactoring)#107

Open
vjik wants to merge 76 commits intomasterfrom
refactor
Open

Replace data response by data stream (big refactoring)#107
vjik wants to merge 76 commits intomasterfrom
refactor

Conversation

@vjik
Copy link
Member

@vjik vjik commented Jan 15, 2026

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a major refactoring that replaces the old DataResponse approach with a new DataStream concept for handling HTTP response data. The refactoring provides a more flexible and modern approach to data formatting with lazy evaluation and better separation of concerns.

Changes:

  • Introduces DataStream and StringStream classes for lazy data formatting
  • Adds new FormatterInterface with implementations for JSON, XML, HTML, and plain text formats
  • Creates response factory classes that produce PSR-7 responses with DataStream bodies
  • Implements middleware for applying formatters to responses
  • Adds content negotiation support via middleware and response factories
  • Deprecates all old DataResponse-based classes with appropriate migration paths

Reviewed changes

Copilot reviewed 66 out of 66 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/DataStream/DataStream.php Core lazy stream implementation that formats data on read
src/DataStream/StringStream.php Read-only string stream for formatted content
src/Formatter/FormatterInterface.php New interface for data formatters
src/Formatter/JsonFormatter.php JSON data formatter implementation
src/Formatter/XmlFormatter.php XML data formatter implementation
src/Formatter/HtmlFormatter.php HTML data formatter implementation
src/Formatter/PlainTextFormatter.php Plain text formatter implementation
src/Formatter/DataEncodingException.php Exception for data encoding failures
src/ResponseFactory/DataResponseFactoryInterface.php Interface for response factories
src/ResponseFactory/DataResponseFactory.php Creates responses without predefined formatter
src/ResponseFactory/AbstractFormattedResponseFactory.php Base class for formatted response factories
src/ResponseFactory/JsonResponseFactory.php JSON response factory
src/ResponseFactory/XmlResponseFactory.php XML response factory
src/ResponseFactory/HtmlResponseFactory.php HTML response factory
src/ResponseFactory/PlainTextResponseFactory.php Plain text response factory
src/ResponseFactory/ContentNegotiatorResponseFactory.php Content negotiation for response factories
src/Middleware/AbstractDataResponseMiddleware.php Base middleware for applying formatters
src/Middleware/DataResponseMiddleware.php Custom formatter middleware
src/Middleware/JsonDataResponseMiddleware.php JSON formatting middleware
src/Middleware/XmlDataResponseMiddleware.php XML formatting middleware
src/Middleware/HtmlDataResponseMiddleware.php HTML formatting middleware
src/Middleware/PlainTextDataResponseMiddleware.php Plain text formatting middleware
src/Middleware/ContentNegotiatorDataResponseMiddleware.php Content negotiation middleware
src/NotAcceptableRequestHandler.php Returns 406 response for unacceptable content types
tests/* Comprehensive test coverage for all new functionality
docs/deprecated.md Documentation for deprecated classes
README.md Updated usage documentation
CHANGELOG.md Documents the new features and deprecations
config/di-web.php DI container configuration updates
composer.json Dependency and script updates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 66 out of 66 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 66 out of 66 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 66 out of 66 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vjik vjik marked this pull request as ready for review February 5, 2026 17:04
@vjik vjik requested a review from a team February 5, 2026 17:05
@vjik vjik added the status:code review The pull request needs review. label Feb 5, 2026
Comment on lines +30 to +31
private ?FormatterInterface $formatter = null,
private readonly FormatterInterface $fallbackFormatter = new HtmlFormatter(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks a bit weird to me. What's the use case for when $fallbackFormatter is changed but $formatter is not set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallback formatter is set only in the constructor and never changed.

Fallback formatter is used on read stream content in cases where formatter isn't set for a data stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants