1 | <?php |
||
14 | final class HttplugFactory |
||
15 | { |
||
16 | /** |
||
17 | * @var Discovery |
||
18 | */ |
||
19 | private $discovery; |
||
20 | |||
21 | /** |
||
22 | * @param Discovery $discovery |
||
23 | */ |
||
24 | 11 | public function __construct(Discovery $discovery) |
|
28 | |||
29 | /** |
||
30 | * Creates a class of type. |
||
31 | * |
||
32 | * @param string $type |
||
33 | * |
||
34 | * @return object |
||
35 | */ |
||
36 | 11 | public function find($type) |
|
37 | { |
||
38 | 11 | $class = $this->findOneByType($type); |
|
39 | |||
40 | 6 | return new $class(); |
|
41 | 1 | } |
|
42 | |||
43 | /** |
||
44 | * Finds a class of type and resolves optional dependency conditions. |
||
45 | * |
||
46 | * @param string $type |
||
47 | * |
||
48 | * @return string |
||
49 | * |
||
50 | * @throws \RuntimeException if no class is found. |
||
51 | */ |
||
52 | 11 | private function findOneByType($type) |
|
74 | |||
75 | /** |
||
76 | * Evaluates conditions to boolean. |
||
77 | * |
||
78 | * @param mixed $condition |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | 10 | protected function evaluateCondition($condition) |
|
104 | } |
||
105 |