1 | <?php |
||
18 | class DataSourceBuilder implements DataSourceBuilderInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var EventDispatcherInterface |
||
22 | */ |
||
23 | private $eventDispatcher; |
||
24 | |||
25 | /** |
||
26 | * @var Field[] |
||
27 | */ |
||
28 | private $fields = []; |
||
29 | |||
30 | /** |
||
31 | * @var TransformerInterface[] |
||
32 | */ |
||
33 | private $transformers = []; |
||
34 | |||
35 | /** |
||
36 | * @var Field[] |
||
37 | */ |
||
38 | private $nativeFields = []; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $entityClass; |
||
44 | |||
45 | /** |
||
46 | * @var ChoicesBuilder |
||
47 | */ |
||
48 | private $choicesBuilder; |
||
49 | |||
50 | /** |
||
51 | * @var DataSourceFactoryInterface |
||
52 | */ |
||
53 | private $dataSourceFactory; |
||
54 | |||
55 | /** |
||
56 | * @param string $entityClass |
||
57 | * @param EventDispatcherInterface $eventDispatcher |
||
58 | * @param DataSourceFactoryInterface $dataSourceFactory |
||
59 | * @param ChoicesBuilder $choicesBuilder |
||
60 | */ |
||
61 | public function __construct($entityClass, EventDispatcherInterface $eventDispatcher, DataSourceFactoryInterface $dataSourceFactory, ChoicesBuilder $choicesBuilder) |
||
68 | |||
69 | public function addField($name, $type, $field, array $options = []) |
||
75 | |||
76 | public function addNativeField($name, $type, $alias, array $options = []) |
||
82 | |||
83 | public function addVectorField($name, $type, $filteringField, array $aliasedFields, array $options = []) |
||
89 | |||
90 | public function addSearchField($name, $type) |
||
96 | |||
97 | public function removeField($name) |
||
108 | |||
109 | public function addTransformer(TransformerInterface $transformer) |
||
115 | |||
116 | public function addEventListener($eventName, $listener) |
||
122 | |||
123 | public function addEventSubscriber(EventSubscriberInterface $eventSubscriber) |
||
129 | |||
130 | public function build() |
||
139 | |||
140 | private function newField($name, $type, $field, $options) |
||
144 | |||
145 | private function getOption($options, $key, $default) |
||
153 | |||
154 | /** |
||
155 | * Helper function: matches a data type name given in the configuration to the needed |
||
156 | * DataType instance. |
||
157 | * |
||
158 | * @param $type |
||
159 | * |
||
160 | * @throws InvalidDataTypeException |
||
161 | * |
||
162 | * @return mixed |
||
163 | */ |
||
164 | private function getDataTypeByName($type) |
||
185 | |||
186 | private function newNativeField($name, $type, $alias, $options) |
||
190 | |||
191 | private function newRawField($name, $type, $field, $alias, $options) |
||
204 | |||
205 | private function parseChoices($choices) |
||
209 | } |
||
210 |