tuupola / http-factory
Lightweight autodiscovering PSR-17 HTTP factories
Installs: 3 130 546
Dependents: 15
Suggesters: 4
Security: 0
Stars: 17
Watchers: 3
Forks: 6
Open Issues: 2
Requires
- php: ^7.1|^8.0
- psr/http-factory: ^1.0
Requires (Dev)
- http-interop/http-factory-tests: ^0.9.0
- overtrue/phplint: ^3.0
- phpunit/phpunit: ^7.0|^8.0|^9.0
- squizlabs/php_codesniffer: ^3.0
Provides
Conflicts
- nyholm/psr7: <1.0
README
Install
Install the library using Composer.
$ composer require tuupola/http-factory
Usage
Let's assume you have Diactoros installed.
$ composer require zendframework/zend-diactoros
The factories will now automatically return Diactoros PSR-7 instances.
use Tuupola\Http\Factory\RequestFactory; $request = (new RequestFactory)->createRequest("GET", "https://example.com/"); print get_class($request); /* Zend\Diactoros\Request */
On the other hand if you have Slim frameworks installed.
$ composer remove zendframework/zend-diactoros
$ composer require slim/slim
The factories will now return Slim PSR-7 instances.
use Tuupola\Http\Factory\RequestFactory; $request = (new RequestFactory)->createRequest("GET", "https://example.com/"); print get_class($request); /* Slim\Http\Request */
This library currently automatically detects and supports laminas/laminas-diactoros, zendframework/zend-diactoros, slim/slim, slim/psr7, nyholm/psr7 and guzzle/psr7 PSR-7 implementations.
Testing
You can run tests either manually or automatically on every code change. Automatic tests require entr to work.
$ make test
$ brew install entr $ make watch
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email tuupola@appelsiini.net instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.