ObjectManagerNameInitializer::purge()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
     * {@inheritdoc}
28
     * @throws \Nnx\DoctrineFixtureModule\FixtureInitializer\Exception\RuntimeException
29
     */
30
    public function purge(FixtureEvent $event)
31
    {
32
        $this->injected($event);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     * @throws \Nnx\DoctrineFixtureModule\FixtureInitializer\Exception\RuntimeException
38
     */
39
    public function import(FixtureEvent $event)
40
    {
41
        $this->injected($event);
42
    }
43
44
    /**
45
     * Устанавливает зависимости в фикстуру
46
     *
47
     * @param FixtureEvent $event
48
     *
49
     * @throws \Nnx\DoctrineFixtureModule\FixtureInitializer\Exception\RuntimeException
50
     */
51
    protected function injected(FixtureEvent $event)
52
    {
53
        $fixture = $event->getFixture();
54
55
        if (! ($fixture instanceof ObjectManagerNameAwareInterface)) {
56
            return;
57
        }
58
59
        $objectManagerName = $this->getContextParam(static::OBJECT_MANAGER_NAME);
60
        $fixture->setObjectManagerName($objectManagerName);
61
    }
62
}
63