Completed
Push — master ( 0b54a3...329231 )
by
unknown
61:37 queued 48:02
created

ConfigurableRegistry::getItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishIOBundle\Migration\FileListerRegistry;
8
9
use eZ\Bundle\EzPublishIOBundle\Migration\FileListerRegistry;
10
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
11
12
/**
13
 * A registry of FileListerInterfaces which is configurable via the array passed to its constructor.
14
 */
15
final class ConfigurableRegistry implements FileListerRegistry
16
{
17
    /** @var \eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface[] */
18
    private $registry = [];
19
20
    /**
21
     * @param \eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface[] $items Hash of FileListerInterfaces, with identifier string as key.
22
     */
23
    public function __construct(array $items = [])
24
    {
25
        $this->registry = $items;
26
    }
27
28
    /**
29
     * Returns the FileListerInterface matching the argument.
30
     *
31
     * @param string $identifier An identifier string.
32
     *
33
     * @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException If no FileListerInterface exists with this identifier
34
     *
35
     * @return \eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface The FileListerInterface given by the identifier.
36
     */
37
    public function getItem($identifier)
38
    {
39
        if (isset($this->registry[$identifier])) {
40
            return $this->registry[$identifier];
41
        }
42
43
        throw new NotFoundException('Migration file lister', $identifier);
44
    }
45
46
    /**
47
     * Returns the identifiers of all registered FileListerInterfaces.
48
     *
49
     * @return string[] Array of identifier strings.
50
     */
51
    public function getIdentifiers()
52
    {
53
        return array_keys($this->registry);
54
    }
55
}
56