Completed
Push — master ( 3a8823...81c6e7 )
by Piotr
02:46
created

ContextManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A addContext() 0 4 1
A createContext() 0 11 3
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace FSi\Bundle\AdminBundle\Admin\Context;
11
12
use FSi\Bundle\AdminBundle\Admin\Element;
13
14
/**
15
 * @author Norbert Orzechowicz <[email protected]>
16
 */
17
class ContextManager
18
{
19
    /**
20
     * @var \FSi\Bundle\AdminBundle\Admin\Context\ContextInterface[]
21
     */
22
    protected $contexts;
23
24
    /**
25
     * @param \FSi\Bundle\AdminBundle\Admin\Context\ContextInterface[] $contexts
26
     */
27
    public function __construct($contexts = array())
28
    {
29
        $this->contexts = array();
30
31
        foreach($contexts as $context) {
32
            $this->addContext($context);
33
        }
34
    }
35
36
    /**
37
     * @param \FSi\Bundle\AdminBundle\Admin\Context\ContextInterface $builder
38
     */
39
    public function addContext(ContextInterface $builder)
40
    {
41
        $this->contexts[] = $builder;
42
    }
43
44
    /**
45
     * @param string $route
46
     * @param \FSi\Bundle\AdminBundle\Admin\Element $element
47
     * @return \FSi\Bundle\AdminBundle\Admin\Context\ContextInterface|null
48
     */
49
    public function createContext($route, Element $element)
50
    {
51
        foreach ($this->contexts as $context) {
52
            if ($context->supports($route, $element)) {
53
                $context->setElement($element);
54
                return $context;
55
            }
56
        }
57
58
        return null;
59
    }
60
}
61