fansipan/request-matcher

1.0.0 2024-11-11 05:15 UTC

This package is auto-updated.

Last update: 2024-11-11 06:27:53 UTC


README

Latest Version on Packagist Github Actions Codecov Total Downloads Software License

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.