Skip to content

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Jul 30, 2018

PSR-17 (HTTP factories) has just been accepted. We should support ANY PSR-7 implementation.

Since we are working with ServerRequests it is a little more tricky. PSR-17 does not really help much here. I've created a "helper package" so one easily can create server requests. See https://github.com/Nyholm/psr7-server


With this PR:

Install nyholm/psr7-server and any PSR7 and PSR17 implementation.

composer require nyholm/psr7-server nyholm/psr7
use PHPFastCGI\FastCGIDaemon\ApplicationFactory;
use PHPFastCGI\FastCGIDaemon\Http\Request;
use Nyholm\Psr7Server\ServerRequestCreator;

// Could be any PSR7 implementation
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Response;

$psr17Factory = new Psr17Factory();

Request::setServerRequestCreator(new ServerRequestCreator(
    $psr17Factory,   // ServerRequestFactoryInteface 
    $psr17Factory,   // UriFactoryInterface
    $psr17Factory,   // UploadedFileFactoryInterface
    $psr17Factory    // StreamFactoryInterface
));

$kernel = function (RequestInterface $request) {
    $psr7Request = $request->getServerRequest();

    return new Response('<h1>Url, '.$psr7Request->getUri().'</h1>');
};

$application = (new ApplicationFactory)->createApplication($kernel);

$application->run();

composer.json Outdated
"phpunit/phpunit": "^5.7.27",
"symfony/http-foundation": "^3.4 || ^4.0",
"zendframework/zend-diactoros": "^1.8",
"nyholm/psr7-server": "dev-interface",
Copy link
Member Author

Choose a reason for hiding this comment

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

Will be 0.1.2 shortly

composer.json Outdated
"symfony/http-foundation": "^3.4 || ^4.0",
"zendframework/zend-diactoros": "^1.8",
"nyholm/psr7-server": "dev-interface",
"http-interop/http-factory-diactoros": "dev-master",
Copy link
Member Author

Choose a reason for hiding this comment

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

I will release 1.0.0 when the psr for HTTP factories is released as a package (within few days)

@AndrewCarterUK
Copy link
Member

Looks good, but won't that clash with this line which uses Zend\Diactoros\createUploadedFile?

I'm also wondering if there's a sensible way for doing defaults, or some sort of helper function that removes the boiler plate.

@Nyholm
Copy link
Member Author

Nyholm commented Jul 30, 2018

Yes, that line is not needed anymore after this PR is merged.

I'm also wondering if there's a sensible way for doing defaults, or some sort of helper function that removes the boiler plate.

Im not sure. The ServerRequestCreator needs you to give it 4 factory implementations... And we cannot do a "default" value without being dependent on a PSR-17 implementation.

@coveralls
Copy link

coveralls commented Jul 30, 2018

Coverage Status

Coverage decreased (-0.4%) to 99.018% when pulling ae21ab3 on Nyholm:psr7-independent into 01a8f0b on PHPFastCGI:master.

@Nyholm Nyholm added this to the Release 0.11.0 milestone Jul 30, 2018
@Nyholm Nyholm force-pushed the psr7-independent branch from c419445 to ae21ab3 Compare August 1, 2018 07:37
@Nyholm
Copy link
Member Author

Nyholm commented Aug 1, 2018

PR is rebased and dependecies are updated

@AndrewCarterUK
Copy link
Member

Looks good - I'm happy to merge.

The README.md file will need updating too, or do that before tagging?

@Nyholm
Copy link
Member Author

Nyholm commented Aug 6, 2018

I vote for a merge now. I’ll update the docs before tagging.

Nyholm added a commit that referenced this pull request Aug 6, 2018
This will fix #47. Related to #39
@Nyholm Nyholm merged commit 071246d into PHPFastCGI:master Aug 6, 2018
@Nyholm Nyholm deleted the psr7-independent branch August 6, 2018 21:24
Nyholm added a commit that referenced this pull request Aug 7, 2018
This will fix #47. Related to #39
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.

3 participants