gacela-project /
router
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Gacela\Router\Configure; |
||
| 6 | |||
| 7 | use Gacela\Router\Entities\Request; |
||
| 8 | |||
| 9 | final class Bindings |
||
| 10 | { |
||
| 11 | /** @var array<class-string, callable|class-string|object> */ |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 12 | private array $bindings = []; |
||
| 13 | |||
| 14 | 112 | public function __construct() |
|
| 15 | { |
||
| 16 | 112 | $this->addBuiltInBindings(); |
|
| 17 | } |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param class-string $name |
||
| 21 | * @param callable|class-string|object $instance |
||
| 22 | */ |
||
| 23 | 112 | public function bind(string $name, mixed $instance): self |
|
| 24 | { |
||
| 25 | 112 | $this->bindings[$name] = $instance; |
|
| 26 | 112 | return $this; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @return array<class-string, callable|class-string|object> |
||
|
0 ignored issues
–
show
|
|||
| 31 | */ |
||
| 32 | 70 | public function getAllBindings(): array |
|
| 33 | { |
||
| 34 | 70 | return $this->bindings; |
|
| 35 | } |
||
| 36 | |||
| 37 | 112 | private function addBuiltInBindings(): void |
|
| 38 | { |
||
| 39 | 112 | $this->bind(Request::class, Request::fromGlobals()); |
|
| 40 | } |
||
| 41 | } |
||
| 42 |