1 | <?php |
||
20 | abstract class GenericListElement extends AbstractElement implements ListElement |
||
21 | { |
||
22 | /** |
||
23 | * @var \FSi\Component\DataSource\DataSourceFactoryInterface |
||
24 | */ |
||
25 | protected $datasourceFactory; |
||
26 | |||
27 | /** |
||
28 | * @var \FSi\Component\DataGrid\DataGridFactoryInterface |
||
29 | */ |
||
30 | protected $datagridFactory; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function getRoute() |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function configureOptions(OptionsResolver $resolver) |
||
44 | { |
||
45 | $resolver->setDefaults([ |
||
46 | 'template_list' => null, |
||
47 | ]); |
||
48 | |||
49 | $resolver->setAllowedTypes('template_list', ['null', 'string']); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function setDataGridFactory(DataGridFactoryInterface $factory) |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | public function setDataSourceFactory(DataSourceFactoryInterface $factory) |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function createDataGrid() |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function createDataSource() |
||
86 | { |
||
87 | $datasource = $this->initDataSource($this->datasourceFactory); |
||
88 | |||
89 | if (!is_object($datasource) || !$datasource instanceof DataSourceInterface) { |
||
90 | throw new RuntimeException('initDataSource should return instanceof FSi\\Component\\DataSource\\DataSourceInterface'); |
||
91 | } |
||
92 | |||
93 | return $datasource; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Initialize DataGrid. |
||
98 | * |
||
99 | * @param \FSi\Component\DataGrid\DataGridFactoryInterface $factory |
||
100 | * @return \FSi\Component\DataGrid\DataGridInterface |
||
101 | */ |
||
102 | abstract protected function initDataGrid(DataGridFactoryInterface $factory); |
||
103 | |||
104 | /** |
||
105 | * Initialize DataSource. |
||
106 | * |
||
107 | * @param \FSi\Component\DataSource\DataSourceFactoryInterface $factory |
||
108 | * @return \FSi\Component\DataSource\DataSourceInterface |
||
109 | */ |
||
110 | abstract protected function initDataSource(DataSourceFactoryInterface $factory); |
||
111 | } |
||
112 |