Skip to content
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

PSR-7 Decorators Migration #67

Merged
merged 30 commits into from
Oct 30, 2018
Merged

Conversation

l0gicgate
Copy link
Member

PSR-7 Decorators

This PR is to migrate the Slim-Http repo to a decoration library for PSR-7 objects instead of a PSR-7 Implementation as discussed in #66. The will be a PR on the Slim 4 branch to reflect these changes once this branch gets merged.

This will enable us to keep all of the existing functionality from the current Slim PSR-7 implementation that was Slim-Http but giving the end user flexibility as to what PSR-7 implementation they choose.

All the tests were written and tested with the following two PSR-7 Implementations:

The Decoration Repo Provides 3 Factories which instantiate the Decorators. They respectively return PSR-7 Compatible Interfaces

  • DecoratedResponseFactory
  • DecoratedServerRequestFactory
  • DecoratedUriFactory

Example For Instantiating a Decorated Nyholm/Psr7 Response

<?php

use Nyholm\Psr7\Factory\Psr17Factory;
use SlimPsr7Decorators\Factory\DecoratedResponseFactory;

$nyholmFactory = new Psr17Factory();

/**
 * DecoratedResponseFactory takes 2 parameters
 * @param \Psr\Http\Message\ResponseFactoryInterface which should be a ResponseFactory originating from the PSR-7 Implementation of your choice
 * @param \Psr\Http\Message\StreamFactoryInterface which should be a StreamFactory originating from the PSR-7 Implementation of your choice
 * Note: Nyholm/Psr17 has one factory which implements Both ResponseFactoryInterface and StreamFactoryInterface see https://github.com/Nyholm/psr7/blob/master/src/Factory/Psr17Factory.php
 */
$decoratedResponseFactory = new DecoratedResponseFactory($nyholmFactory, $nyholmFactory);

/**
 * @var \SlimPsr7Decorators\Decorators\DecoratedResponse $response
 * The returned variable is a DecoratedResponse which has methods like withJson()
 */
$response = $decoratedResponseFactory->createResponse(200, 'OK');
$response = $response->withJson(['data' => [1, 2, 3]]);

Example For Instantiating a Decorated Zend Diactoros Response

<?php

use Zend\Diactoros\ResponseFactory;
use Zend\Diactoros\StreamFactory;
use SlimPsr7Decorators\Factory\DecoratedResponseFactory;

$responseFactory = new ResponseFactory();
$streamFactory = new StreamFactory();

/**
 * DecoratedResponseFactory takes 2 parameters
 * @param \Psr\Http\Message\ResponseFactoryInterface which should be a ResponseFactory originating from the PSR-7 Implementation of your choice
 * @param \Psr\Http\Message\StreamFactoryInterface which should be a StreamFactory originating from the PSR-7 Implementation of your choice
 */
$decoratedResponseFactory = new DecoratedResponseFactory($responseFactory, $streamFactory);

/**
 * @var \SlimPsr7Decorators\Decorators\DecoratedResponse $response
 * The returned variable is a DecoratedResponse which has methods like withJson()
 */
$response = $decoratedResponseFactory->createResponse(200, 'OK');
$response = $response->withJson(['data' => [1, 2, 3]]);

@coveralls
Copy link

Coverage Status

Coverage increased (+2.2%) to 100.0% when pulling 6325430 on l0gicgate:Psr7-Decorators into 4c76c96 on slimphp:master.

l0gicgate and others added 3 commits October 17, 2018 02:45
Use phpstan.neon.dist to ignore the tests that are expected to fail
static analysis checks.

Fix other PHPStan errors.
@danopz danopz mentioned this pull request Oct 22, 2018
akrabat and others added 2 commits October 22, 2018 22:13
Belt and braces tests as our tests should cover everything here anyway.
Test against psr7-integration-tests
Copy link
Member

@danopz danopz left a comment

Choose a reason for hiding this comment

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

Just did a quick review.

For UriDecorator it is the same as for the others.

src/Decorators/ResponseDecorator.php Outdated Show resolved Hide resolved
src/Decorators/ResponseDecorator.php Outdated Show resolved Hide resolved
src/Decorators/ResponseDecorator.php Outdated Show resolved Hide resolved
src/Decorators/ServerRequestDecorator.php Outdated Show resolved Hide resolved
src/Decorators/ServerRequestDecorator.php Outdated Show resolved Hide resolved
src/Decorators/ServerRequestDecorator.php Outdated Show resolved Hide resolved
@akrabat akrabat merged commit 336f97c into slimphp:master Oct 30, 2018
akrabat added a commit that referenced this pull request Oct 30, 2018
@akrabat akrabat added this to the 0.5 milestone Nov 1, 2018
@l0gicgate l0gicgate deleted the Psr7-Decorators branch May 24, 2019 00:07
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.

4 participants