1 | <?php |
||
2 | |||
3 | namespace Bankiru\Doctrine\DiType; |
||
4 | |||
5 | use Doctrine\DBAL\Types\Type; |
||
6 | |||
7 | final class DiTypeFactory |
||
8 | { |
||
9 | private $classes = []; |
||
10 | |||
11 | public function addType($type, $class) |
||
12 | { |
||
13 | $this->classes[$type] = $class; |
||
14 | } |
||
15 | |||
16 | public function create($type) |
||
17 | { |
||
18 | if (!array_key_exists($type, $this->classes)) { |
||
19 | throw new \OutOfBoundsException(sprintf('Type "%s" is not registered it DI Type Factory', $type)); |
||
20 | } |
||
21 | |||
22 | if (Type::hasType($type)) { |
||
23 | Type::overrideType($type, $this->classes[$type]); |
||
24 | } else { |
||
25 | Type::addType($type, $this->classes[$type]); |
||
26 | } |
||
27 | |||
28 | return Type::getType($type); |
||
29 | } |
||
30 | } |
||
31 |