aboutsummaryrefslogtreecommitdiff
path: root/tests/Fixtures/FakeResolver.php
blob: af6ec1f4f6921db92926fb89d2c5d3a9beb98ec8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

declare(strict_types=1);

namespace BrettParson\MiniRoute\Tests\Fixtures;

use BrettParson\MiniRoute\Controller\ControllerResolverInterface;
use RuntimeException;

final class FakeResolver implements ControllerResolverInterface
{
    /** @var array<string, object> */
    private array $bindings = [];

    public function bind(string $class, object $instance): void
    {
        $this->bindings[$class] = $instance;
    }

    public function resolve(string $class): object
    {
        if (!array_key_exists($class, $this->bindings)) {
            throw new RuntimeException("No binding for {$class}");
        }

        return $this->bindings[$class];
    }
}