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\AlreadyRegisteredProviderException; |
15
|
|
|
use WBW\Bundle\JQuery\DatatablesBundle\Exception\UnregisteredProviderException; |
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
|
|
|
* @final |
24
|
|
|
*/ |
25
|
|
|
final class DataTablesManager { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Service name. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
const SERVICE_NAME = "webeweb.bundle.datatablesbundle.manager.datatables"; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Providers. |
36
|
|
|
* |
37
|
|
|
* @var DataTablesProviderInterface[] |
38
|
|
|
*/ |
39
|
|
|
private $providers; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor. |
43
|
|
|
*/ |
44
|
|
|
public function __construct() { |
45
|
|
|
$this->setProviders([]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get a provider. |
50
|
|
|
* |
51
|
|
|
* @param string $name The provider name. |
52
|
|
|
* @return DataTablesProviderInterface Returns the DataTables provider. |
53
|
|
|
* @throws UnregisteredProviderException Throws an unregistered provider exception. |
54
|
|
|
*/ |
55
|
|
|
public function getProvider($name) { |
56
|
|
|
if (false === array_key_exists($name, $this->providers)) { |
57
|
|
|
throw new UnregisteredProviderException($name); |
58
|
|
|
} |
59
|
|
|
return $this->providers[$name]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the providers. |
64
|
|
|
* |
65
|
|
|
* @return DataTablesProviderInterface[] Returns the providers. |
66
|
|
|
*/ |
67
|
|
|
public function getProviders() { |
68
|
|
|
return $this->providers; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Register a provider. |
73
|
|
|
* |
74
|
|
|
* @param DataTablesProviderInterface $provider The provider. |
75
|
|
|
* @throws AlreadyRegisteredProviderException Throws an already registered provider exception. |
76
|
|
|
*/ |
77
|
|
|
public function registerProvider(DataTablesProviderInterface $provider) { |
78
|
|
|
if (true === array_key_exists($provider->getName(), $this->providers)) { |
79
|
|
|
throw new AlreadyRegisteredProviderException($provider->getName()); |
80
|
|
|
} |
81
|
|
|
$this->providers[$provider->getName()] = $provider; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Set the providers. |
86
|
|
|
* |
87
|
|
|
* @param DataTablesProviderInterface[] $providers The providers. |
88
|
|
|
*/ |
89
|
|
|
private function setProviders(array $providers) { |
90
|
|
|
$this->providers = $providers; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|