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

4.x - Improve AppFactory & ServerRequestCreatorFactory Automatic Decoration #2716

Merged
merged 4 commits into from Jun 6, 2019

Conversation

@l0gicgate
Copy link
Contributor

commented Jun 6, 2019

AppFactory's New Behavior
AppFactory will attempt to decorate ResponseFactory instances passed via AppFactory::create() or set via AppFactory::setResponseFactory() given that a StreamFactoryInterface has been set via AppFactory::setStreamFactory() given that Slim\Http is present.

Note that the AppFactory setters will override any of the PSR-17 factory provider automatically detected implementations.

<?php
use Slim\Factory\AppFactory;
use Your\Psr7\CustomResponseFactory;
use Your\Psr7\CustomStreamFactory;

// Set your custom StreamFactory first
$myStreamFactory = new CustomStreamFactory();
AppFactory::setStreamFactory($myStreamFactory);

// You can use a setter for your ResponseFactory
$myCustomResponseFactory = new CustomResponseFactory();
AppFactory::setResponseFactory($myCustomResponseFactory);
$app = AppFactory::create();

// Or you can use the AppFactory::create() constructor parameter
$app = AppFactory::create($myCustomResponseFactory);

ServerRequestCreatorFactory's New Behavior
Similarly to AppFactory you can set a default ServerRequestCreator which implements ServerRequestCreatorInterface that will override the automatically detected server request creators present in the PSR-17 factory provider.

<?php
use Slim\Factory\AppFactory;
use Slim\Factory\ServerRequestCreatorFactory;
use Your\Psr7\CustomServerRequestCreator;

$myCustomServerRequestCreator = new CustomServerRequestCreator();
ServerRequestCreatorFactory::setServerRequestCreator($myCustomServerRequestCreator);

$app = AppFactory::create();
$app->run();

This PR effectively closes #2709, #2710, #2712 and #2713

@l0gicgate l0gicgate added the Slim 4 label Jun 6, 2019

@l0gicgate l0gicgate added this to the 4.0.0 milestone Jun 6, 2019

@l0gicgate l0gicgate force-pushed the l0gicgate:4.x-ImproveAutomaticDecoration branch from b979123 to 22f7157 Jun 6, 2019

@coveralls

This comment has been minimized.

Copy link

commented Jun 6, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 22f7157 on l0gicgate:4.x-ImproveAutomaticDecoration into 8dfa32d on slimphp:4.x.

@l0gicgate l0gicgate merged commit d9c8356 into slimphp:4.x Jun 6, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 100.0%
Details
@adriansuter

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

Cool.

@l0gicgate l0gicgate referenced this pull request Aug 1, 2019

Merged

Slim 4 Release #2769

@l0gicgate l0gicgate deleted the l0gicgate:4.x-ImproveAutomaticDecoration branch Aug 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.