Skip to content

Commit

Permalink
Merge pull request #4 from tbreuss/feat-upgrade
Browse files Browse the repository at this point in the history
Support for PHP 7.4, 8.0, 8.1, replace zend framework with laminas
  • Loading branch information
tbreuss committed Oct 1, 2022
2 parents 65d082c + a2e9b30 commit 123b3e8
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.idea
/.phpunit.result.cache
/composer.lock
/vendor
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php
php:
- '7.1'
- '7.2'
- '7.4'
- '8.0'
- '8.1'
install: composer install
script: composer test
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
[![License](https://img.shields.io/github/license/tbreuss/http-factory.svg)](https://github.com/tbreuss/http-factory/blob/master/LICENSE)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/tebe/http-factory.svg)](https://packagist.org/packages/tebe/http-factory)


HTTP-Factory is a PHP package that implements [PSR-17 HTTP factories](https://www.php-fig.org/psr/psr-17/) interface.
It offers auto-discovering support and acts as a simple facade to allow easy access to concrete HTTP Factory packages.
It acts as a simple facade to provide easy access to concrete HTTP factory packets.
As its main feature it offers support for auto-discovery of the supported factories.

All PSR-17 interfaces are implemented:

Expand All @@ -19,27 +19,26 @@ All PSR-17 interfaces are implemented:
- Psr\Http\Message\UploadedFileFactoryInterface
- Psr\Http\Message\UriFactoryInterface

Additionally it implements a createServerRequestFromGlobals method, which is not part of PSR-17.
Additionally, it implements a createServerRequestFromGlobals method, which is not part of PSR-17.

## Auto-discovering PSR-7 packages

The package features auto-discovery support for the following PSR-7 packages:

1. zendframework/zend-diactoros
1. laminas/laminas-diactoros
2. guzzlehttp/psr7
3. slim/slim
4. nyholm/psr7

The auto-discovery mechanism assumes that you are using one (and only one) of the above PSR-7 packages in your project.
The first detected PSR-17 package will then be used for all interface factory methods.


## Installation

When starting a new project one of the following PSR-7 packages must be installed.

~~~bash
$ composer require zendframework/zend-diactoros
$ composer require laminas/laminas-diactoros
$ composer require guzzlehttp/psr7
$ composer require slim/slim
$ composer require nyholm/psr7
Expand Down Expand Up @@ -95,7 +94,6 @@ $factory->createUploadedFile(
);
~~~


## Usage

### Using constructor
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tebe/http-factory",
"type": "library",
"description": "HTTP-Factory with auto-discovery support implementing PSR-17",
"description": "HTTP Factory provides automatic detection for Composer packages implementing the PSR-17 standard",
"license": "MIT",
"keywords": [
"psr-7",
Expand All @@ -12,18 +12,18 @@
"http"
],
"require": {
"php": "^7.1",
"php": ">=7.4",
"psr/http-message": "^1.0",
"psr/http-factory": "^1.0"
},
"require-dev": {
"zendframework/zend-diactoros": "^1.8",
"slim/slim": "^3.10",
"guzzlehttp/psr7": "^1.4",
"squizlabs/php_codesniffer": "^3.3",
"phpunit/phpunit": "^6.5",
"laminas/laminas-diactoros": "^2.0",
"slim/slim": "^3.0",
"squizlabs/php_codesniffer": "^3.0",
"nyholm/psr7": "^1.0",
"nyholm/psr7-server": "^0.3.0"
"phpunit/phpunit": "^9.0",
"nyholm/psr7-server": "^1.0",
"guzzlehttp/psr7": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 11 additions & 11 deletions src/Factory/DiactorosFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@

namespace Tebe\HttpFactory\Factory;

use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\Stream;
use Laminas\Diactoros\UploadedFile;
use Laminas\Diactoros\Uri;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\UriInterface;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Stream;
use Zend\Diactoros\UploadedFile;
use Zend\Diactoros\Uri;

/**
* Simple class to create response instances of PSR-7 classes.
*/
class DiactorosFactory implements FactoryInterface
{
/**
* Check whether Zend Diactoros is available
* Check whether Laminas Diactoros is available
*/
public static function isInstalled(): bool
{
return class_exists('Zend\\Diactoros\\Response')
&& class_exists('Zend\\Diactoros\\ServerRequest')
&& class_exists('Zend\\Diactoros\\Stream')
&& class_exists('Zend\\Diactoros\\Uri');
return class_exists('Laminas\\Diactoros\\Response')
&& class_exists('Laminas\\Diactoros\\ServerRequest')
&& class_exists('Laminas\\Diactoros\\Stream')
&& class_exists('Laminas\\Diactoros\\Uri');
}

/**
Expand Down
11 changes: 5 additions & 6 deletions tests/Factory/DiactorosFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace Tests\Tebe\HttpFactory;

use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\Stream;
use Laminas\Diactoros\Uri;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UploadedFileInterface;
use Tebe\HttpFactory\Factory\DiactorosFactory;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Stream;
use Zend\Diactoros\UploadedFile;
use Zend\Diactoros\Uri;

class DiactorosFactoryTest extends TestCase
{
Expand All @@ -18,7 +17,7 @@ class DiactorosFactoryTest extends TestCase
*/
private $factory;

public function setUp()
protected function setUp(): void
{
$this->factory = new DiactorosFactory();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Factory/GuzzleFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GuzzleFactoryTest extends TestCase
*/
private $factory;

public function setUp()
protected function setUp(): void
{
$this->factory = new GuzzleFactory();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Factory/NyholmFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NyholmFactoryTest extends TestCase
*/
private $factory;

public function setUp()
protected function setUp(): void
{
$this->factory = new NyholmFactory();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Factory/SlimFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SlimeFactoryTest extends TestCase
*/
private $factory;

public function setUp()
protected function setUp(): void
{
$this->factory = new SlimFactory();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/HttpFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HttpFactoryTest extends TestCase
*/
private $factory;

public function setUp()
protected function setUp(): void
{
HttpFactory::setStrategies([
DiactorosFactory::class,
Expand Down

0 comments on commit 123b3e8

Please sign in to comment.