for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Damax\ChargeableApi\Bridge\Symfony\HttpFoundation;
use Damax\ChargeableApi\Product\Product;
use Damax\ChargeableApi\Product\ProductResolutionFailed;
use Damax\ChargeableApi\Product\Resolver;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
final class ProductResolver implements Resolver
{
private $products = [];
public function addProduct(Product $product, RequestMatcherInterface $matcher): void
$this->products[$product->name()] = [$product, $matcher];
}
/**
* @param Request $request
*
* @throws ProductResolutionFailed
*/
public function resolve($request): Product
foreach ($this->products as list($product, $matcher)) {
if ($matcher->matches($request)) {
return $product;
throw ProductResolutionFailed::unresolved();