Completed
Push — dev ( 1d55ed...662a5b )
by Андрей
03:01
created

getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ObjectManagerNameInitializer::purge() 0 4 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine-fixture-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\DoctrineFixtureModule\FixtureInitializer;
7
8
use Doctrine\Fixture\Event\FixtureEvent;
9
10
11
/**
12
 * Class ObjectManagerNameInitializer
13
 *
14
 * @package Nnx\DoctrineFixtureModule\FixtureInitializer
15
 */
16
class ObjectManagerNameInitializer extends AbstractContextInitializer
17
{
18
19
    /**
20
     * Имя параметра из контекста, значение которого содержит имя ObjectManager'a
21
     *
22
     * @var string
23
     */
24
    const OBJECT_MANAGER_NAME = 'objectManagerName';
25
26
    /**
27
     * ObjectManagerNameInitializer constructor.
28
     *
29
     * @param array $contextData
30
     */
31
    public function __construct(array $contextData = [])
32
    {
33
        $this->setContextData($contextData);
34
    }
35
36
37
    /**
38
     * {@inheritdoc}
39
     * @throws \Nnx\DoctrineFixtureModule\FixtureInitializer\Exception\RuntimeException
40
     */
41
    public function purge(FixtureEvent $event)
42
    {
43
        $this->injected($event);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     * @throws \Nnx\DoctrineFixtureModule\FixtureInitializer\Exception\RuntimeException
49
     */
50
    public function import(FixtureEvent $event)
51
    {
52
        $this->injected($event);
53
    }
54
55
    /**
56
     * Устанавливает зависимости в фикстуру
57
     *
58
     * @param FixtureEvent $event
59
     *
60
     * @throws \Nnx\DoctrineFixtureModule\FixtureInitializer\Exception\RuntimeException
61
     */
62
    protected function injected(FixtureEvent $event)
63
    {
64
        $fixture = $event->getFixture();
65
66
        if (! ($fixture instanceof ObjectManagerNameAwareInterface)) {
67
            return;
68
        }
69
70
        $objectManagerName = $this->getContextParam(static::OBJECT_MANAGER_NAME);
71
        $fixture->setObjectManagerName($objectManagerName);
72
    }
73
}
74