bentools/psr7-request-matcher

A PSR-7 RequestMatcher interface for use into several projects.

Maintainers

👁 bpolaszek

Package info

github.com/bpolaszek/psr7-request-matcher

pkg:composer/bentools/psr7-request-matcher

Statistics

Installs: 311 713

Dependents: 4

Suggesters: 0

Stars: 1

Open Issues: 0

1.1 2018-03-07 10:54 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT bf7db07be3474586a948fc52dee1214c67915552

  • bpolaszek <bpolaszek.woop@gmail.com>

This package is auto-updated.

Last update: 2026-06-15 04:46:34 UTC


README

👁 Latest Stable Version
👁 License
👁 Build Status
👁 Total Downloads

PSR-7 Request Matcher

This library is just composed of interfaces to implement, to check wether or not a request and/or a response match some arbitrary conditions.

These interfaces provide no return type-hint and is therefore compatible from PHP 5.3+.

Examples

Request matcher

namespace App;

use BenTools\Psr7\RequestMatcherInterface;
use Psr\Http\Message\RequestInterface;

class ExampleOrgRequestMatcher implements RequestMatcherInterface
{
 /**
 * @inheritdoc
 */
 public function matchRequest(RequestInterface $request)
 {
 return 'www.example.org' === $request->getUri()->getHost();
 }

}

Response matcher

namespace App;

use BenTools\Psr7\ResponseMatcherInterface;
use Psr\Http\Message\ResponseInterface;

class TeapotResponseMatcher implements ResponseMatcherInterface
{
 /**
 * @inheritdoc
 */
 public function matchResponse(ResponseInterface $response)
 {
 return 418 === $response->getStatusCode();
 }

}

Transfer matcher

namespace App;

use BenTools\Psr7\TransferMatcherInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class DummyTransferMatcher implements TransferMatcherInterface
{
 /**
 * @inheritdoc
 */
 public function matchTransfer(RequestInterface $request, ResponseInterface $response)
 {
 return $request->hasHeader('Authorization')
 && 'Welcome, human.' === (string) $response->getBody();
 }

}

Installation

composer require bentools/psr7-request-matcher

Tests

./vendor/bin/phpunit