1 | <?php |
||
11 | class ImportRegistry |
||
12 | { |
||
13 | /** |
||
14 | * @var ReaderTypeInterface[] |
||
15 | */ |
||
16 | private $readerTypes = []; |
||
17 | |||
18 | /** |
||
19 | * @var FeedTypeInterface[] |
||
20 | */ |
||
21 | private $feedTypes = []; |
||
22 | |||
23 | /** |
||
24 | * @var ImporterTypeInterface[] |
||
25 | */ |
||
26 | private $importerTypes = []; |
||
27 | |||
28 | /** |
||
29 | * @var HandlerInterface[] |
||
30 | */ |
||
31 | private $handlers = []; |
||
32 | |||
33 | /** |
||
34 | * @var ProcessorInterface[] |
||
35 | */ |
||
36 | private $processors = []; |
||
37 | |||
38 | /** |
||
39 | * @param string $name |
||
40 | * |
||
41 | * @throws \OutOfBoundsException If type with the name is registered |
||
42 | * @return ReaderTypeInterface |
||
43 | * |
||
44 | */ |
||
45 | 4 | public function getReaderType($name) |
|
46 | { |
||
47 | 4 | if (!array_key_exists($name, $this->readerTypes)) { |
|
48 | throw new \OutOfBoundsException( |
||
49 | sprintf( |
||
50 | 'Reader type "%s" is not supported. You can add it by creating a service which implements %s, ' . |
||
51 | 'and tag it with tree_house.io.reader_type', |
||
52 | ReaderTypeInterface::class, |
||
53 | $name |
||
54 | ) |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | 4 | return $this->readerTypes[$name]; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return ReaderTypeInterface[] |
||
63 | */ |
||
64 | public function getReaderTypes() |
||
68 | |||
69 | /** |
||
70 | * Registers a reader type. |
||
71 | * |
||
72 | * @param ReaderTypeInterface $type |
||
73 | * @param string $name |
||
74 | */ |
||
75 | 4 | public function registerReaderType(ReaderTypeInterface $type, $name) |
|
79 | |||
80 | /** |
||
81 | * @param string $name |
||
82 | * |
||
83 | * @throws \OutOfBoundsException If type with the name is registered |
||
84 | * @return FeedTypeInterface |
||
85 | * |
||
86 | */ |
||
87 | 4 | public function getFeedType($name) |
|
88 | { |
||
89 | 4 | if (!array_key_exists($name, $this->feedTypes)) { |
|
90 | throw new \OutOfBoundsException( |
||
91 | sprintf( |
||
92 | 'Feed type "%s" is not supported. You can add it by creating a service which implements %s, ' . |
||
93 | 'and tag it with tree_house.io.feed_type', |
||
94 | $name, |
||
95 | FeedTypeInterface::class |
||
96 | ) |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | 4 | return $this->feedTypes[$name]; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return FeedTypeInterface[] |
||
105 | */ |
||
106 | public function getFeedTypes() |
||
110 | |||
111 | /** |
||
112 | * Registers a feed type. |
||
113 | * |
||
114 | * @param FeedTypeInterface $type |
||
115 | * @param string $name |
||
116 | */ |
||
117 | 4 | public function registerFeedType(FeedTypeInterface $type, $name) |
|
121 | |||
122 | /** |
||
123 | * @param string $name |
||
124 | * |
||
125 | * @throws \OutOfBoundsException If no type with the name is registered |
||
126 | * @return ImporterTypeInterface |
||
127 | * |
||
128 | */ |
||
129 | 4 | public function getImporterType($name) |
|
130 | { |
||
131 | 4 | if (!array_key_exists($name, $this->importerTypes)) { |
|
132 | throw new \OutOfBoundsException( |
||
133 | sprintf( |
||
134 | 'Importer type "%s" is not supported. You can add it by creating a service which implements %s, ' . |
||
135 | 'and tag it with tree_house.io.importer_type', |
||
136 | $name, |
||
137 | ImporterTypeInterface::class |
||
138 | ) |
||
139 | ); |
||
140 | } |
||
141 | |||
142 | 4 | return $this->importerTypes[$name]; |
|
143 | } |
||
144 | |||
145 | /** |
||
146 | * @return ImporterTypeInterface[] |
||
147 | */ |
||
148 | public function getImporterTypes() |
||
152 | |||
153 | /** |
||
154 | * Registers an importer type. |
||
155 | * |
||
156 | * @param ImporterTypeInterface $type |
||
157 | * @param string $name |
||
158 | */ |
||
159 | 4 | public function registerImporterType(ImporterTypeInterface $type, $name) |
|
163 | |||
164 | /** |
||
165 | * @param string $name |
||
166 | * |
||
167 | * @throws \OutOfBoundsException If no handler with the name is registered |
||
168 | * @return HandlerInterface |
||
169 | * |
||
170 | */ |
||
171 | 4 | public function getHandler($name) |
|
172 | { |
||
173 | 4 | if (!array_key_exists($name, $this->handlers)) { |
|
174 | throw new \OutOfBoundsException( |
||
175 | sprintf( |
||
176 | 'Import handler "%s" is not supported. You can add it by creating a service which implements %s, ' . |
||
177 | 'and tag it with tree_house.io.import_handler', |
||
178 | $name, |
||
179 | HandlerInterface::class |
||
180 | ) |
||
181 | ); |
||
182 | } |
||
183 | |||
184 | 4 | return $this->handlers[$name]; |
|
185 | } |
||
186 | |||
187 | /** |
||
188 | * @return HandlerInterface[] |
||
189 | */ |
||
190 | public function getHandlers() |
||
194 | |||
195 | /** |
||
196 | * Registers a handler. |
||
197 | * |
||
198 | * @param HandlerInterface $handler |
||
199 | * @param string $name |
||
200 | */ |
||
201 | 4 | public function registerHandler(HandlerInterface $handler, $name) |
|
205 | |||
206 | /** |
||
207 | * @param string $name |
||
208 | * |
||
209 | * @throws \OutOfBoundsException If no processor with the name is registered |
||
210 | * @return ProcessorInterface |
||
211 | * |
||
212 | */ |
||
213 | 4 | public function getProcessor($name) |
|
214 | { |
||
215 | 4 | if (!array_key_exists($name, $this->processors)) { |
|
216 | throw new \OutOfBoundsException( |
||
217 | sprintf( |
||
218 | 'Import processor "%s" is not supported. You can add it by creating a service which implements %s, ' . |
||
219 | 'and tagging it with tree_house.io.import_processor', |
||
220 | $name, |
||
221 | ProcessorInterface::class |
||
222 | ) |
||
223 | ); |
||
224 | } |
||
225 | |||
226 | 4 | return $this->processors[$name]; |
|
227 | } |
||
228 | |||
229 | /** |
||
230 | * @return ProcessorInterface[] |
||
231 | */ |
||
232 | public function getProcessors() |
||
236 | |||
237 | /** |
||
238 | * Registers a processor. |
||
239 | * |
||
240 | * @param ProcessorInterface $processor |
||
241 | * @param string $name |
||
242 | */ |
||
243 | 4 | public function registerProcessor(ProcessorInterface $processor, $name) |
|
247 | } |
||
248 |