1 | <?php |
||
14 | class MqManagementFactory |
||
15 | { |
||
16 | |||
17 | /** @var MqManagementConfig */ |
||
18 | private $config; |
||
19 | |||
20 | 39 | public function getConfig() : MqManagementConfig |
|
21 | { |
||
22 | 39 | return $this->config; |
|
23 | } |
||
24 | |||
25 | /** |
||
26 | * @var ContainerBuilder |
||
27 | */ |
||
28 | private $container; |
||
29 | |||
30 | |||
31 | public function __construct() |
||
32 | { |
||
33 | $container = new ContainerBuilder(); |
||
34 | $this->container = $container; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param MqManagementConfig $config |
||
39 | * @throws \Exception |
||
40 | */ |
||
41 | public function register(MqManagementConfig $config) |
||
52 | |||
53 | 1 | protected function registerMapper(BaseMapper $mapper, JobBase $job) |
|
54 | { |
||
61 | |||
62 | /** |
||
63 | * @return JobService |
||
64 | * @throws \Exception |
||
65 | */ |
||
66 | 39 | public function getJobService() : JobService |
|
78 | |||
79 | /** |
||
80 | * @param $result |
||
81 | * @return JobResult |
||
82 | */ |
||
83 | public function getJobResult($result) |
||
87 | |||
88 | /** |
||
89 | * Gets a mapper for the job, if non found it throws an NoMapperForJob exception |
||
90 | * |
||
91 | * @param JobBase $job |
||
92 | * @return BaseMapper |
||
93 | * @throws NoMapperForJob |
||
94 | * @throws WrongServiceContainerMappingException |
||
95 | * @throws \Exception |
||
96 | */ |
||
97 | 57 | public function getJobMapper(JobBase $job) : BaseMapper |
|
105 | |||
106 | /** |
||
107 | * @param JobBase $job |
||
108 | * @return BaseMapper |
||
109 | * @throws NoMapperForJob |
||
110 | * @throws WrongServiceContainerMappingException |
||
111 | * @throws \Exception |
||
112 | */ |
||
113 | 57 | private function getJobMapperFromContainer(JobBase $job) |
|
114 | { |
||
115 | 57 | $class = get_class($job); |
|
116 | |||
117 | 57 | if (false === $this->container->has($class)) { |
|
118 | 55 | throw new NoMapperForJob($job); |
|
119 | } |
||
120 | |||
121 | 2 | $mapper = $this->container->get($class); |
|
122 | 2 | if (!$mapper instanceof BaseMapper) { |
|
123 | 1 | throw WrongServiceContainerMappingException::expectedOtherMapping($job, BaseMapper::class); |
|
124 | } |
||
125 | |||
126 | 1 | return $mapper; |
|
127 | } |
||
128 | |||
129 | /** |
||
130 | * @param JobBase $job |
||
131 | * @return mixed |
||
132 | * @throws NoMapperForJob |
||
133 | */ |
||
134 | 55 | private function getJobMapperFromAutoload(JobBase $job) |
|
146 | } |
||
147 |