-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelResolver.php
More file actions
40 lines (34 loc) · 883 Bytes
/
ModelResolver.php
File metadata and controls
40 lines (34 loc) · 883 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Comhon\ModelResolverContract\Tests\Resolver;
use Comhon\ModelResolverContract\ModelResolverInterface;
/**
* A basic implementation of a model resolver
*/
class ModelResolver implements ModelResolverInterface
{
public function __construct(private $bindings = [])
{
//
}
/**
* Bind a unique name to a class.
*/
public function bind(string $uniqueName, string $class): ?string
{
return $this->bindings[$uniqueName] = $class;
}
/**
* Get unique name according given class.
*/
public function getUniqueName(string $class): ?string
{
return array_search($class, $this->bindings) ?: null;
}
/**
* Get class according given unique name.
*/
public function getClass(string $uniqueName): ?string
{
return $this->bindings[$uniqueName] ?? null;
}
}