Skip to content

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

Merged
l0gicgate merged 4 commits into
slimphp:4.xfrom
l0gicgate:4.x-ImproveAutomaticDecoration
Jun 6, 2019
Merged

4.x - Improve AppFactory & ServerRequestCreatorFactory Automatic Decoration#2716
l0gicgate merged 4 commits into
slimphp:4.xfrom
l0gicgate:4.x-ImproveAutomaticDecoration

Conversation

@l0gicgate

Copy link
Copy Markdown
Member

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 this to the 4.0.0 milestone Jun 6, 2019
@l0gicgate
l0gicgate force-pushed the 4.x-ImproveAutomaticDecoration branch from b979123 to 22f7157 Compare June 6, 2019 03:40
@coveralls

Copy link
Copy Markdown

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
@adriansuter

Copy link
Copy Markdown
Contributor

Cool.

@l0gicgate l0gicgate mentioned this pull request Aug 1, 2019
@l0gicgate
l0gicgate deleted the 4.x-ImproveAutomaticDecoration branch August 6, 2019 21:00
chriscct7 pushed a commit to awesomemotive/aioseo-slim-v3-php-8.1 that referenced this pull request Sep 3, 2025
…coration

 4.x - Improve AppFactory & ServerRequestCreatorFactory Automatic Decoration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants