Completed
Push — master ( e78d8a...96e91a )
by WEBEWEB
01:20
created

DataTablesManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 69
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getProvider() 0 6 2
A getProviders() 0 3 1
A registerProvider() 0 6 2
A setProviders() 0 3 1
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