Skip to content

Commit

Permalink
Merge pull request #3120 from solventt/new-psr17-factory
Browse files Browse the repository at this point in the history
Add a new PSR-17 factory to Psr17FactoryProvider
  • Loading branch information
l0gicgate authored Dec 2, 2021
2 parents 676b02f + 5b28d88 commit 0b6376b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ This will install Slim and all required dependencies. Slim requires PHP 7.4 or n

Before you can get up and running with Slim you will need to choose a PSR-7 implementation that best fits your application. A few notable ones:
- [Slim-Psr7](https://github.com/slimphp/Slim-Psr7) - This is the Slim Framework PSR-7 implementation
- [Nyholm/psr7](https://github.com/Nyholm/psr7) & [Nyholm/psr7-server](https://github.com/Nyholm/psr7-server) - This is the fastest, strictest and most lightweight implementation available
- [httpsoft/http-message](https://github.com/httpsoft/http-message) & [httpsoft/http-server-request](https://github.com/httpsoft/http-server-request) - This is the fastest, strictest and most lightweight implementation available
- [Nyholm/psr7](https://github.com/Nyholm/psr7) & [Nyholm/psr7-server](https://github.com/Nyholm/psr7-server) - Performance is almost the same as the HttpSoft implementation
- [Guzzle/psr7](https://github.com/guzzle/psr7) - This is the implementation used by the Guzzle Client, featuring extra functionality for stream and file handling
- [laminas-diactoros](https://github.com/laminas/laminas-diactoros) - This is the Laminas (Zend) PSR-7 implementation

Expand Down Expand Up @@ -53,6 +54,8 @@ $app = AppFactory::create();
## Hello World using AppFactory with PSR-7 auto-detection
In order for auto-detection to work and enable you to use `AppFactory::create()` and `App::run()` without having to manually create a `ServerRequest` you need to install one of the following implementations:
- [Slim-Psr7](https://github.com/slimphp/Slim-Psr7) - Install using `composer require slim/psr7`
- [httpsoft/http-message](https://github.com/httpsoft/http-message) & [httpsoft/http-server-request](https://github.com/httpsoft/http-server-request) - Install using:
`composer require httpsoft/http-message httpsoft/http-server-request`
- [Nyholm/psr7](https://github.com/Nyholm/psr7) & [Nyholm/psr7-server](https://github.com/Nyholm/psr7-server) - Install using `composer require nyholm/psr7 nyholm/psr7-server`
- [Guzzle/psr7](https://github.com/guzzle/psr7) - Install using `composer require guzzlehttp/psr7`
- [laminas-diactoros](https://github.com/laminas/laminas-diactoros) - Install using `composer require laminas/laminas-diactoros`
Expand Down
19 changes: 19 additions & 0 deletions Slim/Factory/Psr17/HttpSoftPsr17Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* Slim Framework (https://slimframework.com)
*
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
*/

declare(strict_types=1);

namespace Slim\Factory\Psr17;

class HttpSoftPsr17Factory extends Psr17Factory
{
protected static $responseFactoryClass = 'HttpSoft\Message\ResponseFactory';
protected static $streamFactoryClass = 'HttpSoft\Message\StreamFactory';
protected static $serverRequestCreatorClass = 'HttpSoft\ServerRequest\ServerRequestCreator';
protected static $serverRequestCreatorMethod = 'createFromGlobals';
}
1 change: 1 addition & 0 deletions Slim/Factory/Psr17/Psr17FactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Psr17FactoryProvider implements Psr17FactoryProviderInterface
*/
protected static $factories = [
SlimPsr17Factory::class,
HttpSoftPsr17Factory::class,
NyholmPsr17Factory::class,
LaminasDiactorosPsr17Factory::class,
GuzzlePsr17Factory::class,
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"ext-simplexml": "*",
"adriansuter/php-autoload-override": "^1.2",
"guzzlehttp/psr7": "^2.1",
"httpsoft/http-message": "^1.0",
"httpsoft/http-server-request": "^1.0",
"laminas/laminas-diactoros": "^2.8",
"nyholm/psr7": "^1.4",
"nyholm/psr7-server": "^1.0",
Expand Down
3 changes: 3 additions & 0 deletions tests/Factory/AppFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use GuzzleHttp\Psr7\HttpFactory;
use Laminas\Diactoros\ResponseFactory as LaminasDiactorosResponseFactory;
use HttpSoft\Message\ResponseFactory as HttpSoftResponseFactory;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
Expand All @@ -21,6 +22,7 @@
use RuntimeException;
use Slim\Factory\AppFactory;
use Slim\Factory\Psr17\GuzzlePsr17Factory;
use Slim\Factory\Psr17\HttpSoftPsr17Factory;
use Slim\Factory\Psr17\LaminasDiactorosPsr17Factory;
use Slim\Factory\Psr17\NyholmPsr17Factory;
use Slim\Factory\Psr17\Psr17FactoryProvider;
Expand Down Expand Up @@ -55,6 +57,7 @@ public function provideImplementations()
{
return [
[SlimPsr17Factory::class, SlimResponseFactory::class],
[HttpSoftPsr17Factory::class, HttpSoftResponseFactory::class],
[NyholmPsr17Factory::class, Psr17Factory::class],
[GuzzlePsr17Factory::class, HttpFactory::class],
[LaminasDiactorosPsr17Factory::class, LaminasDiactorosResponseFactory::class],
Expand Down
3 changes: 3 additions & 0 deletions tests/Factory/ServerRequestCreatorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
use GuzzleHttp\Psr7\ServerRequest as GuzzleServerRequest;
use Laminas\Diactoros\ServerRequest as LaminasDiactorosServerRequest;
use Nyholm\Psr7\ServerRequest as NyholmServerRequest;
use HttpSoft\Message\ServerRequest as HttpSoftServerRequest;
use Psr\Http\Message\ServerRequestInterface;
use RuntimeException;
use Slim\Factory\Psr17\GuzzlePsr17Factory;
use Slim\Factory\Psr17\HttpSoftPsr17Factory;
use Slim\Factory\Psr17\LaminasDiactorosPsr17Factory;
use Slim\Factory\Psr17\NyholmPsr17Factory;
use Slim\Factory\Psr17\Psr17FactoryProvider;
Expand All @@ -33,6 +35,7 @@ public function provideImplementations()
{
return [
[SlimPsr17Factory::class, SlimServerRequest::class],
[HttpSoftPsr17Factory::class, HttpSoftServerRequest::class],
[NyholmPsr17Factory::class, NyholmServerRequest::class],
[GuzzlePsr17Factory::class, GuzzleServerRequest::class],
[LaminasDiactorosPsr17Factory::class, LaminasDiactorosServerRequest::class],
Expand Down

0 comments on commit 0b6376b

Please sign in to comment.