1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FSi\Bundle\AdminBundle\Factory\Worker; |
4
|
|
|
|
5
|
|
|
use FSi\Bundle\AdminBundle\Admin\CRUD\DataGridAwareInterface; |
6
|
|
|
use FSi\Bundle\AdminBundle\Admin\CRUD\DataSourceAwareInterface; |
7
|
|
|
use FSi\Bundle\AdminBundle\Admin\CRUD\ListElement; |
8
|
|
|
use FSi\Bundle\AdminBundle\Admin\Element; |
9
|
|
|
use FSi\Bundle\AdminBundle\Factory\Worker; |
10
|
|
|
use FSi\Component\DataGrid\DataGridFactoryInterface; |
11
|
|
|
use FSi\Component\DataSource\DataSourceFactoryInterface; |
12
|
|
|
|
13
|
|
|
class ListWorker implements Worker |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var DataSourceFactoryInterface |
17
|
|
|
*/ |
18
|
|
|
private $dataSourceFactory; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \FSi\Component\DataGrid\DataGridFactoryInterface |
22
|
|
|
*/ |
23
|
|
|
private $dataGridFactory; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param DataSourceFactoryInterface $dataSourceFactory |
27
|
|
|
*/ |
28
|
|
|
function __construct( |
|
|
|
|
29
|
|
|
DataSourceFactoryInterface $dataSourceFactory, |
30
|
|
|
DataGridFactoryInterface $dataGridFactory |
31
|
|
|
) { |
32
|
|
|
$this->dataSourceFactory = $dataSourceFactory; |
33
|
|
|
$this->dataGridFactory = $dataGridFactory; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritdoc |
38
|
|
|
*/ |
39
|
|
|
public function mount(Element $element) |
40
|
|
|
{ |
41
|
|
|
if ($element instanceof ListElement) { |
42
|
|
|
$element->setDataSourceFactory($this->dataSourceFactory); |
43
|
|
|
$element->setDataGridFactory($this->dataGridFactory); |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
if ($element instanceof DataSourceAwareInterface) { |
47
|
|
|
$element->setDataSourceFactory($this->dataSourceFactory); |
48
|
|
|
} |
49
|
|
|
if ($element instanceof DataGridAwareInterface) { |
50
|
|
|
$element->setDataGridFactory($this->dataGridFactory); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.