generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Replace data response by data stream (big refactoring) #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vjik
wants to merge
76
commits into
master
Choose a base branch
from
refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,456
−69
Open
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
4b6d6fd
start
vjik cf6f77f
implement
vjik b4ec9a6
Apply PHP CS Fixer and Rector changes (CI)
vjik 1b7d137
rename
vjik ad3fcf6
Merge remote-tracking branch 'origin/refactor' into refactor
vjik 20e0eff
refactor
vjik f8c7f67
improve
vjik 67e783f
revert formatters
vjik 97f21aa
Rename formatter files and update namespaces to improve organization
vjik cdf773f
Add DataStream
vjik 7efb553
Apply PHP CS Fixer and Rector changes (CI)
vjik a831d66
improve
vjik 7677ccc
Merge remote-tracking branch 'origin/refactor' into refactor
vjik 46e5555
improve
vjik 4f09ea9
improve
vjik 873de7c
Apply PHP CS Fixer and Rector changes (CI)
vjik bff8592
improve
vjik 305e15e
Merge remote-tracking branch 'origin/refactor' into refactor
vjik 0f2a245
Apply PHP CS Fixer and Rector changes (CI)
vjik 102224c
improve
vjik 14c10c3
Merge remote-tracking branch 'origin/refactor' into refactor
vjik 043a332
improve
vjik fca3c4f
improve
vjik 75605b5
improve
vjik 7f7e146
Introduce `FormattedResponseFactoryInterface`
vjik cb1280b
Introduce `ContentNegotiator`
vjik a4d0e67
Introduce `LazyFormattingStream`
vjik e9ee3d9
Apply PHP CS Fixer and Rector changes (CI)
vjik eda5c26
improve
vjik 343f9f4
Fix properties
vjik cc5a83a
Improve `DataResponseFactory`
vjik 1603a94
Remove `FormattedResponseFactoryInterface`
vjik d913432
Improve `DataResponseFactory`
vjik 935eead
Merge branch 'master' into refactor
vjik 762efd8
Fix `JsonFormatted`
vjik d420ebb
Merge remote-tracking branch 'origin/refactor' into refactor
vjik b1d032f
move files
vjik 8180994
start tests
vjik 2fe60c9
Apply PHP CS Fixer and Rector changes (CI)
vjik 6b72757
tests
vjik 3880f9c
tests
vjik ea76d7d
tests
vjik 2ef792a
tests
vjik cad79a6
Merge remote-tracking branch 'origin/refactor' into refactor
vjik 5d66a9c
Apply PHP CS Fixer and Rector changes (CI)
vjik 0369bf1
deprecations
vjik 42a31b3
Merge remote-tracking branch 'origin/refactor' into refactor
vjik dfab4fd
Apply PHP CS Fixer and Rector changes (CI)
vjik 8f5b167
Add `DataEncodingException`
vjik a6fd488
fix psalm
vjik 7664bd0
Merge remote-tracking branch 'origin/refactor' into refactor
vjik c56c1e6
fix
vjik 1bf531f
Apply PHP CS Fixer and Rector changes (CI)
vjik bb61efd
phpdoc
vjik a6d2c03
config
vjik c98c582
Apply PHP CS Fixer and Rector changes (CI)
vjik 3e4ae11
docs
vjik 103332a
Merge remote-tracking branch 'origin/refactor' into refactor
vjik 93846b6
changelog
vjik 894834e
Merge branch 'master' into refactor
vjik 7081609
Allow use `RequestHandlerInterface` as fallback
vjik 4c6bafe
NotAcceptableRequestHandler
vjik 96e5565
rename
vjik 1ae5cd8
fix
vjik d20ecec
fix
vjik 06f6198
improve test
vjik 0f6a5a3
fix
vjik 8abcb19
improve test
vjik b288908
Apply PHP CS Fixer and Rector changes (CI)
vjik b085961
fix
vjik 9e144d2
fix
vjik 7e539a8
fix
vjik b5401f1
use stable yiisoft/test-support
vjik b0cb987
improve
vjik bb703f5
Merge remote-tracking branch 'origin/refactor' into refactor
vjik a5704a3
Apply PHP CS Fixer and Rector changes (CI)
vjik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Deprecated | ||
|
|
||
| > [!WARNING] | ||
| > The classes described in this document are deprecated and will be removed in a future version. | ||
|
|
||
| ## General usage | ||
|
|
||
| The package provides `DataResponseFactory` class that, given a [PSR-17](https://www.php-fig.org/psr/psr-17/) | ||
| response factory, is able to create data response. | ||
|
|
||
| Data response contains raw data to be processed later. | ||
|
|
||
| ```php | ||
| use Yiisoft\DataResponse\DataResponseFactory; | ||
|
|
||
| /** | ||
| * @var Psr\Http\Message\ResponseFactoryInterface $responseFactory | ||
| */ | ||
|
|
||
| $factory = new DataResponseFactory($responseFactory); | ||
| $dataResponse = $factory->createResponse('test'); | ||
| $dataResponse | ||
| ->getBody() | ||
| ->rewind(); | ||
|
|
||
| echo $dataResponse | ||
| ->getBody() | ||
| ->getContents(); // "test" | ||
| ``` | ||
|
|
||
| ## Formatters | ||
|
|
||
| Formatter purpose is to format a data response. In the following example we format data as JSON. | ||
|
|
||
| ```php | ||
| use Yiisoft\DataResponse\DataResponseFactory; | ||
| use Yiisoft\DataResponse\Formatter\JsonDataResponseFormatter; | ||
|
|
||
| /** | ||
| * @var Psr\Http\Message\ResponseFactoryInterface $responseFactory | ||
| */ | ||
|
|
||
| $factory = new DataResponseFactory($responseFactory); | ||
| $dataResponse = $factory->createResponse('test'); | ||
| $dataResponse = $dataResponse->withResponseFormatter(new JsonDataResponseFormatter()); | ||
| $dataResponse | ||
| ->getBody() | ||
| ->rewind(); | ||
|
|
||
| echo $dataResponse->getHeader('Content-Type'); // ["application/json; charset=UTF-8"] | ||
| echo $dataResponse | ||
| ->getBody() | ||
| ->getContents(); // "test" | ||
| ``` | ||
|
|
||
| The following formatters are available: | ||
|
|
||
| - `HtmlDataResponseFormatter` | ||
| - `JsonDataResponseFormatter` | ||
| - `XmlDataResponseFormatter` | ||
| - `PlainTextDataResponseFormatter` | ||
|
|
||
| ## Middleware | ||
|
|
||
| The package provides a [PSR-15](https://www.php-fig.org/psr/psr-15/) middleware that is able to format a data response. | ||
|
|
||
| ```php | ||
| use Yiisoft\DataResponse\Middleware\FormatDataResponse; | ||
| use Yiisoft\DataResponse\Formatter\JsonDataResponseFormatter; | ||
|
|
||
| $middleware = (new FormatDataResponse(new JsonDataResponseFormatter())); | ||
| //$middleware->process($request, $handler); | ||
| ``` | ||
|
|
||
| Also, the package provides [PSR-15](https://www.php-fig.org/psr/psr-15/) middleware for content negotiation: | ||
|
|
||
| ```php | ||
| use Yiisoft\DataResponse\Formatter\HtmlDataResponseFormatter; | ||
| use Yiisoft\DataResponse\Formatter\XmlDataResponseFormatter; | ||
| use Yiisoft\DataResponse\Formatter\JsonDataResponseFormatter; | ||
| use Yiisoft\DataResponse\Middleware\ContentNegotiator; | ||
|
|
||
| $middleware = new ContentNegotiator([ | ||
| 'text/html' => new HtmlDataResponseFormatter(), | ||
| 'application/xml' => new XmlDataResponseFormatter(), | ||
| 'application/json' => new JsonDataResponseFormatter(), | ||
| ]); | ||
| ``` | ||
|
|
||
| You can override middlewares with method `withContentFormatters()`: | ||
|
|
||
| ```php | ||
| $middleware->withContentFormatters([ | ||
| 'application/xml' => new XmlDataResponseFormatter(), | ||
| 'application/json' => new JsonDataResponseFormatter(), | ||
| ]); | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.