1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TreeHouse\IoBundle\Import; |
4
|
|
|
|
5
|
|
|
use TreeHouse\IoBundle\Import\Feed\Type\FeedTypeInterface; |
6
|
|
|
use TreeHouse\IoBundle\Import\Handler\HandlerInterface; |
7
|
|
|
use TreeHouse\IoBundle\Import\Importer\Type\ImporterTypeInterface; |
8
|
|
|
use TreeHouse\IoBundle\Import\Processor\ProcessorInterface; |
9
|
|
|
use TreeHouse\IoBundle\Import\Reader\Type\ReaderTypeInterface; |
10
|
|
|
|
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() |
65
|
|
|
{ |
66
|
|
|
return $this->readerTypes; |
67
|
|
|
} |
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) |
76
|
|
|
{ |
77
|
4 |
|
$this->readerTypes[$name] = $type; |
78
|
4 |
|
} |
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() |
107
|
|
|
{ |
108
|
|
|
return $this->feedTypes; |
109
|
|
|
} |
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) |
118
|
|
|
{ |
119
|
4 |
|
$this->feedTypes[$name] = $type; |
120
|
4 |
|
} |
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() |
149
|
|
|
{ |
150
|
|
|
return $this->importerTypes; |
151
|
|
|
} |
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) |
160
|
|
|
{ |
161
|
4 |
|
$this->importerTypes[$name] = $type; |
162
|
4 |
|
} |
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() |
191
|
|
|
{ |
192
|
|
|
return $this->handlers; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Registers a handler. |
197
|
|
|
* |
198
|
|
|
* @param HandlerInterface $handler |
199
|
|
|
* @param string $name |
200
|
|
|
*/ |
201
|
4 |
|
public function registerHandler(HandlerInterface $handler, $name) |
202
|
|
|
{ |
203
|
4 |
|
$this->handlers[$name] = $handler; |
204
|
4 |
|
} |
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() |
233
|
|
|
{ |
234
|
|
|
return $this->processors; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Registers a processor. |
239
|
|
|
* |
240
|
|
|
* @param ProcessorInterface $processor |
241
|
|
|
* @param string $name |
242
|
|
|
*/ |
243
|
4 |
|
public function registerProcessor(ProcessorInterface $processor, $name) |
244
|
|
|
{ |
245
|
4 |
|
$this->processors[$name] = $processor; |
246
|
4 |
|
} |
247
|
|
|
} |
248
|
|
|
|