Completed
Pull Request — develop (#607)
by Tom
03:12 queued 01:40
created

EntityResolver::getEventManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Options;
6
7
use InvalidArgumentException;
8
use Laminas\Stdlib\AbstractOptions;
9
use function class_exists;
10
use function sprintf;
11
12
class EntityResolver extends AbstractOptions
13
{
14
    /**
15
     * Set the configuration key for the EventManager. Event manager key
16
     * is assembled as "doctrine.eventmanager.{key}" and pulled from
17
     * service locator.
18
     *
19
     * @var string
20
     */
21
    protected $eventManager = 'orm_default';
22
23
    /**
24
     * An array that maps a class name (or interface name) to another class
25
     * name
26
     *
27
     * @var mixed[]
28
     */
29
    protected $resolvers = [];
30
31
    public function setEventManager(string $eventManager) : self
32
    {
33
        $this->eventManager = $eventManager;
34
35
        return $this;
36
    }
37
38
    public function getEventManager() : string
39
    {
40
        return 'doctrine.eventmanager.' . $this->eventManager;
41
    }
42
43
    /**
44
     * @param  mixed[] $resolvers
45
     *
46
     * @throws InvalidArgumentException
47
     */
48
    public function setResolvers(array $resolvers) : void
49
    {
50
        foreach ($resolvers as $old => $new) {
51
            if (! class_exists($new)) {
52
                throw new InvalidArgumentException(
53
                    sprintf(
54
                        '%s is resolved to the entity %s, which does not exist',
55
                        $old,
56
                        $new
57
                    )
58
                );
59
            }
60
61
            $this->resolvers[$old] = $new;
62
        }
63
    }
64
65
    /**
66
     * @return mixed[]
67
     */
68
    public function getResolvers() : array
69
    {
70
        return $this->resolvers;
71
    }
72
}
73