Completed
Pull Request — master (#120)
by De Cramer
02:35
created

ItemBuilder::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 6
1
<?php
2
3
namespace eXpansion\Bundle\Menu\Services;
4
5
use eXpansion\Bundle\Menu\Model\Menu\ItemInterface;
6
use FML\Controls\Quad;
7
8
/**
9
 * Class ItemFactory
10
 *
11
 * @author    de Cramer Oliver<[email protected]>
12
 * @copyright 2017 Smile
13
 * @package eXpansion\Bundle\Menu\Services
14
 */
15
class ItemBuilder
16
{
17
    /** @var ItemFactoryInterface[] */
18
    protected $itemFactories = [];
19
20
    /**
21
     * @param ItemFactoryInterface $itemFactory
22
     */
23
    public function addItemFactory(ItemFactoryInterface $itemFactory)
24
    {
25
        $this->itemFactories[] = $itemFactory;
26
    }
27
28
    /**
29
     * @param string $class
30
     * @param string $id
31
     * @param string $path
32
     * @param string $label
33
     * @param string $permission
34
     * @param array $options
35
     *
36
     * @return ItemInterface
37
     */
38
    public function create($class, $id, $path, $label, $permission, $options =[])
39
    {
40
        foreach ($this->itemFactories as $itemFactory) {
41
            if ($itemFactory->supports($class)) {
42
                return $itemFactory->build($class, $id, $path, $label, $permission, $options);
43
            }
44
        }
45
    }
46
}
47