Completed
Pull Request — master (#233)
by De Cramer
10:00
created

ConfigUiManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerUi() 0 4 1
A getUiHandler() 0 14 4
1
<?php
2
3
namespace eXpansion\Framework\Config\Services;
4
5
use eXpansion\Framework\Config\Model\ConfigInterface;
6
use eXpansion\Framework\Config\Ui\Fields\UiInterface;
7
8
/**
9
 * Class ConfigUiManager
10
 *
11
 * @author    de Cramer Oliver<[email protected]>
12
 * @copyright 2018 Smile
13
 * @package eXpansion\Framework\Config\Services
14
 */
15
class ConfigUiManager
16
{
17
    /** @var UiInterface[] */
18
    protected $uiHandlers = [];
19
20
    /**
21
     * Register an ui handler for configurations.
22
     *
23
     * @param UiInterface $ui
24
     */
25
    public function registerUi(UiInterface $ui)
26
    {
27
        $this->uiHandlers[] = $ui;
28
    }
29
30
    /**
31
     * Get proper handler to generate ui for a config element.
32
     *
33
     * @param ConfigInterface $config
34
     *
35
     * @return UiInterface|null
36
     */
37
    public function getUiHandler(ConfigInterface $config)
38
    {
39
        if ($config->isHidden()) {
40
            return null;
41
        }
42
43
        foreach ($this->uiHandlers as $ui) {
44
            if ($ui->isCompatible($config)) {
45
                return $ui;
46
            }
47
        }
48
49
        return null;
50
    }
51
}