1 | <?php |
||
26 | abstract class AbstractCRUD extends AbstractElement implements CRUDElement |
||
27 | { |
||
28 | /** |
||
29 | * @var \FSi\Component\DataSource\DataSourceFactoryInterface |
||
30 | */ |
||
31 | protected $datasourceFactory; |
||
32 | |||
33 | /** |
||
34 | * @var \FSi\Component\DataGrid\DataGridFactoryInterface |
||
35 | */ |
||
36 | protected $datagridFactory; |
||
37 | |||
38 | /** |
||
39 | * @var \Symfony\Component\Form\FormFactoryInterface |
||
40 | */ |
||
41 | protected $formFactory; |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function getRoute() |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function getSuccessRoute() |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | public function getSuccessRouteParameters() |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public function setDefaultOptions(OptionsResolver $resolver) |
||
104 | |||
105 | /** |
||
106 | * @inheritdoc |
||
107 | */ |
||
108 | public function apply($object) |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function setDataGridFactory(DataGridFactoryInterface $factory) |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function setDataSourceFactory(DataSourceFactoryInterface $factory) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function setFormFactory(FormFactoryInterface $factory) |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | public function createDataGrid() |
||
165 | |||
166 | /** |
||
167 | * {@inheritdoc} |
||
168 | */ |
||
169 | public function createDataSource() |
||
170 | { |
||
171 | $datasource = $this->initDataSource($this->datasourceFactory); |
||
172 | |||
173 | if (!is_object($datasource) || !$datasource instanceof DataSourceInterface) { |
||
174 | throw new RuntimeException('initDataSource should return instanceof FSi\\Component\\DataSource\\DataSourceInterface'); |
||
175 | } |
||
176 | |||
177 | return $datasource; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * {@inheritdoc} |
||
182 | */ |
||
183 | public function createForm($data = null) |
||
184 | { |
||
185 | $form = $this->initForm($this->formFactory, $data); |
||
186 | |||
187 | if (!is_object($form) || !$form instanceof FormInterface) { |
||
188 | throw new RuntimeException('initForm should return instanceof Symfony\\Component\\Form\\FormInterface'); |
||
189 | } |
||
190 | |||
191 | return $form; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Initialize DataGrid. |
||
196 | * |
||
197 | * @param \FSi\Component\DataGrid\DataGridFactoryInterface $factory |
||
198 | * @return \FSi\Component\DataGrid\DataGridInterface |
||
199 | */ |
||
200 | abstract protected function initDataGrid(DataGridFactoryInterface $factory); |
||
201 | |||
202 | /** |
||
203 | * Initialize DataSource. |
||
204 | * |
||
205 | * @param \FSi\Component\DataSource\DataSourceFactoryInterface $factory |
||
206 | * @return \FSi\Component\DataSource\DataSourceInterface |
||
207 | */ |
||
208 | abstract protected function initDataSource(DataSourceFactoryInterface $factory); |
||
209 | |||
210 | /** |
||
211 | * Initialize create Form. This form will be used in createAction in CRUDController. |
||
212 | * |
||
213 | * @param \Symfony\Component\Form\FormFactoryInterface $factory |
||
214 | * @param mixed $data |
||
215 | * @return \Symfony\Component\Form\FormInterface |
||
216 | */ |
||
217 | abstract protected function initForm(FormFactoryInterface $factory, $data = null); |
||
218 | } |
||
219 |