1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/doctrine-fixture-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\DoctrineFixtureModule\Listener; |
7
|
|
|
|
8
|
|
|
use Doctrine\Fixture\Event\BulkFixtureEvent; |
9
|
|
|
use Doctrine\Fixture\Event\BulkImportFixtureEventListener; |
10
|
|
|
use Doctrine\Fixture\Event\BulkPurgeFixtureEventListener; |
11
|
|
|
use Nnx\DoctrineFixtureModule\Event\FixtureExecutorEvent; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class PreExecuteEventSubscriber |
15
|
|
|
* |
16
|
|
|
* @package Nnx\DoctrineFixtureModule\Listener |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
class PreExecuteEventSubscriber |
|
|
|
|
19
|
|
|
extends AbstractExecuteEventSubscriber |
|
|
|
|
20
|
|
|
implements |
|
|
|
|
21
|
|
|
PreExecuteEventSubscriberInterface, |
|
|
|
|
22
|
|
|
BulkImportFixtureEventListener, |
|
|
|
|
23
|
|
|
BulkPurgeFixtureEventListener |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Идендфикатор для менеджера событий |
28
|
|
|
* |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $eventIdentifier = [ |
32
|
|
|
PreExecuteEventSubscriberInterface::class |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function getSubscribedEvents() |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
|
|
BulkImportFixtureEventListener::BULK_IMPORT, |
42
|
|
|
BulkPurgeFixtureEventListener::BULK_PURGE, |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
* @throws \Nnx\DoctrineFixtureModule\Executor\Exception\RuntimeException |
49
|
|
|
*/ |
50
|
|
|
public function bulkImport(BulkFixtureEvent $event) |
51
|
|
|
{ |
52
|
|
|
$workflowExecutorEvent = clone $this->getPrototypeEvent(); |
53
|
|
|
$workflowExecutorEvent->setName(FixtureExecutorEvent::START_EXECUTE_FIXTURES_EVENT); |
54
|
|
|
$workflowExecutorEvent->setMethod(FixtureExecutorEvent::IMPORT); |
55
|
|
|
$executor = $this->getExecutor(); |
56
|
|
|
$workflowExecutorEvent->setExecutor($executor); |
57
|
|
|
$workflowExecutorEvent->setTarget($executor); |
58
|
|
|
|
59
|
|
|
$this->getEventManager()->trigger($workflowExecutorEvent); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
* @throws \Nnx\DoctrineFixtureModule\Executor\Exception\RuntimeException |
66
|
|
|
*/ |
67
|
|
|
public function bulkPurge(BulkFixtureEvent $event) |
68
|
|
|
{ |
69
|
|
|
$workflowExecutorEvent = clone $this->getPrototypeEvent(); |
70
|
|
|
$workflowExecutorEvent->setName(FixtureExecutorEvent::START_EXECUTE_FIXTURES_EVENT); |
71
|
|
|
$workflowExecutorEvent->setMethod(FixtureExecutorEvent::PURGE); |
72
|
|
|
$executor = $this->getExecutor(); |
73
|
|
|
$workflowExecutorEvent->setExecutor($executor); |
74
|
|
|
$workflowExecutorEvent->setTarget($executor); |
75
|
|
|
|
76
|
|
|
$this->getEventManager()->trigger($workflowExecutorEvent); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.