fansipan / request-matcher
PSR Request matcher
Requires
- php: ^7.2.5|^8.0
- psr/http-message: ^1.0|^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- nyholm/psr7: ^1.8
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^8.0|^9.0
- webmozart/glob: ^4.1
This package is auto-updated.
Last update: 2024-11-25 02:43:55 UTC
README
PSR-7 request matcher equivalent of Symfony's RequestMatcher.
Installation
You may use Composer to install this package:
composer require fansipan/request-matcher
Usage
To create a matcher instance with your assertions, you can use the following example to match the request host:
use Fansipan\RequestMatcher\HostRequestMatcher; use Psr\Http\Message\RequestInterface; $matcher = new HostRequestMatcher('localhost'); // Matches http://localhost /** @var RequestInterface $request */ $matcher->matches($request);
Customer Request Matcher
You can also create a matcher using a callback. For instance:
use Fansipan\RequestMatcher\CallbackRequestMatcher; use Psr\Http\Message\RequestInterface; $matcher = new CallbackRequestMatcher(static fn (RequestInterface $request) => $request->getUri()->getScheme() === 'https' && $request->getUri()->getHost() === 'my.app');
Chain Request Matcher
The example above can be grouped by using ChainRequestMatcher
use Fansipan\RequestMatcher\CallbackRequestMatcher; use Fansipan\RequestMatcher\HostRequestMatcher; use Fansipan\RequestMatcher\SchemeRequestMatcher; use Psr\Http\Message\RequestInterface; $matcher = new ChainRequestMatcher([ new SchemeRequestMatcher('https'), new HostRequestMatcher('my.app'), ]);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email contact@lynh.me instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.