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 InvalidArgumentException; |
15
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Exception\AlreadyRegisteredDataTablesProviderException; |
16
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Exception\UnregisteredDataTablesProviderException; |
17
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesProviderInterface; |
18
|
|
|
use WBW\Library\Symfony\Manager\AbstractManager; |
19
|
|
|
use WBW\Library\Symfony\Manager\ManagerInterface; |
20
|
|
|
use WBW\Library\Symfony\Provider\ProviderInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* DataTables manager. |
24
|
|
|
* |
25
|
|
|
* @author webeweb <https://github.com/webeweb> |
26
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Manager |
27
|
|
|
*/ |
28
|
|
|
class DataTablesManager extends AbstractManager { |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Service name. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
const SERVICE_NAME = "wbw.jquery.datatables.manager"; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function addProvider(ProviderInterface $provider): ManagerInterface { |
41
|
|
|
|
42
|
|
|
if (false === ($provider instanceof DataTablesProviderInterface)) { |
43
|
|
|
throw new InvalidArgumentException("The provider must implements " . DataTablesProviderInterface::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** @var DataTablesProviderInterface $provider */ |
47
|
|
|
if (true === $this->containsProvider($provider)) { |
48
|
|
|
throw new AlreadyRegisteredDataTablesProviderException($provider->getName()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return parent::addProvider($provider); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get a provider. |
56
|
|
|
* |
57
|
|
|
* @param string $name The name. |
58
|
|
|
* @return DataTablesProviderInterface Returns the provider. |
59
|
|
|
* @throws UnregisteredDataTablesProviderException Throws an unregistered provider exception. |
60
|
|
|
*/ |
61
|
|
|
public function getProvider(string $name): DataTablesProviderInterface { |
62
|
|
|
|
63
|
|
|
/** @var DataTablesProviderInterface $current */ |
64
|
|
|
foreach ($this->getProviders() as $current) { |
65
|
|
|
if ($name === $current->getName()) { |
|
|
|
|
66
|
|
|
return $current; |
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
throw new UnregisteredDataTablesProviderException($name); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|