Completed
Push — ezp25946-migrate_files_to_othe... ( 3ba3f5...7b23be )
by
unknown
13:29
created

IdentifierBased::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
 * File containing the IdentifierBased class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandlerRegistry;
10
11
use eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandlerRegistry;
12
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
13
14
/**
15
 * A registry of MigrationHandlerInterfaces that uses an identifier string to identify the handler.
16
 */
17
class IdentifierBased implements MigrationHandlerRegistry
18
{
19
    /** @var \eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandlerInterface[] */
20
    private $registry = [];
21
22
    /**
23
     * @param \eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandlerInterface[] $items Hash of MigrationHandlerInterfaces, with identifier string as key.
24
     */
25
    public function __construct(array $items = [])
26
    {
27
        $this->registry = $items;
28
    }
29
30
    /**
31
     * Returns the MigrationHandlerInterface matching the argument.
32
     *
33
     * @param string $identifier An identifier string.
34
     *
35
     * @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException If no MigrationHandlerInterface exists with this identifier
36
     *
37
     * @return \eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandlerInterface The MigrationHandlerInterface given by the identifier.
38
     */
39
    public function getItem($identifier)
40
    {
41
        if (isset($this->registry[$identifier])) {
42
            return $this->registry[$identifier];
43
        }
44
45
        throw new NotFoundException('Migration handler', $identifier);
46
    }
47
48
    /**
49
     * Returns the identifiers of all registered MigrationHandlerInterfaces.
50
     *
51
     * @return string[] Array of identifier strings.
52
     */
53
    public function getIdentifiers()
54
    {
55
        return array_keys($this->registry);
56
    }
57
}
58