|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\JQuery\DataTablesBundle\Manager; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Exception\AlreadyRegisteredDataTablesProviderException; |
|
15
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Exception\UnregisteredDataTablesProviderException; |
|
16
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesProviderInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* DataTables manager. |
|
20
|
|
|
* |
|
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
22
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Manager |
|
23
|
|
|
*/ |
|
24
|
|
|
class DataTablesManager { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Service name. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
const SERVICE_NAME = "webeweb.bundle.datatablesbundle.manager.datatables"; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Providers. |
|
35
|
|
|
* |
|
36
|
|
|
* @var DataTablesProviderInterface[] |
|
37
|
|
|
*/ |
|
38
|
|
|
private $providers; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct() { |
|
44
|
|
|
$this->setProviders([]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get a provider. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $name The provider name. |
|
51
|
|
|
* @return DataTablesProviderInterface Returns the DataTables provider. |
|
52
|
|
|
* @throws UnregisteredDataTablesProviderException Throws an unregistered DataTables provider exception. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getProvider($name) { |
|
55
|
|
|
if (false === array_key_exists($name, $this->providers)) { |
|
56
|
|
|
throw new UnregisteredDataTablesProviderException($name); |
|
57
|
|
|
} |
|
58
|
|
|
return $this->providers[$name]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get the providers. |
|
63
|
|
|
* |
|
64
|
|
|
* @return DataTablesProviderInterface[] Returns the providers. |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getProviders() { |
|
67
|
|
|
return $this->providers; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Register a provider. |
|
72
|
|
|
* |
|
73
|
|
|
* @param DataTablesProviderInterface $provider The provider. |
|
74
|
|
|
* @throws AlreadyRegisteredDataTablesProviderException Throws an already registered DataTables provider exception. |
|
75
|
|
|
*/ |
|
76
|
|
|
public function registerProvider(DataTablesProviderInterface $provider) { |
|
77
|
|
|
if (true === array_key_exists($provider->getName(), $this->providers)) { |
|
78
|
|
|
throw new AlreadyRegisteredDataTablesProviderException($provider->getName()); |
|
79
|
|
|
} |
|
80
|
|
|
$this->providers[$provider->getName()] = $provider; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Set the providers. |
|
85
|
|
|
* |
|
86
|
|
|
* @param DataTablesProviderInterface[] $providers The providers. |
|
87
|
|
|
*/ |
|
88
|
|
|
private function setProviders(array $providers) { |
|
89
|
|
|
$this->providers = $providers; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|