1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/doctrine-fixture-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\JmsSerializerModule\DoctrineObjectEngine; |
7
|
|
|
|
8
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
9
|
|
|
use Nnx\JmsSerializerModule\DataContainer; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DoctrineObjectEngine |
13
|
|
|
* |
14
|
|
|
* @package Nnx\JmsSerializerModule\DoctrineObjectEngine |
15
|
|
|
*/ |
16
|
|
|
class DoctrineObjectEngine implements DoctrineObjectEngineInterface |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Компонент отвечающий за сборку метаданных |
21
|
|
|
* |
22
|
|
|
* @var MetadataBuilderInterface |
23
|
|
|
*/ |
24
|
|
|
protected $metadataBuilder; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Движок отвечающий за заполнение базы данных |
28
|
|
|
* |
29
|
|
|
* @var ImportEngineInterface |
30
|
|
|
*/ |
31
|
|
|
protected $importEngine; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* DoctrineObjectEngine constructor. |
35
|
|
|
* |
36
|
|
|
* @param MetadataBuilderInterface $metadataBuilder |
37
|
|
|
* @param ImportEngineInterface $importEngine |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
MetadataBuilderInterface $metadataBuilder, |
41
|
|
|
ImportEngineInterface $importEngine |
42
|
|
|
) { |
43
|
|
|
$this->setMetadataBuilder($metadataBuilder); |
44
|
|
|
$this->setImportEngine($importEngine); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Возвращает компонент отвечающий за сборку метаданных |
49
|
|
|
* |
50
|
|
|
* @return MetadataBuilderInterface |
51
|
|
|
*/ |
52
|
|
|
public function getMetadataBuilder() |
53
|
|
|
{ |
54
|
|
|
return $this->metadataBuilder; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Возвращает движок, отвечающий за заполнение базы данных |
59
|
|
|
* |
60
|
|
|
* @return ImportEngineInterface |
61
|
|
|
*/ |
62
|
|
|
public function getImportEngine() |
63
|
|
|
{ |
64
|
|
|
return $this->importEngine; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Устанавливает движок отвечающий за заполнение базы данных |
69
|
|
|
* |
70
|
|
|
* @param ImportEngineInterface $importEngine |
71
|
|
|
* |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function setImportEngine(ImportEngineInterface $importEngine) |
75
|
|
|
{ |
76
|
|
|
$this->importEngine = $importEngine; |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Устанавливает компонент отвечающий за сборку метаданных |
84
|
|
|
* |
85
|
|
|
* @param MetadataBuilderInterface $metadataBuilder |
86
|
|
|
* |
87
|
|
|
* @return $this |
88
|
|
|
*/ |
89
|
|
|
public function setMetadataBuilder(MetadataBuilderInterface $metadataBuilder) |
90
|
|
|
{ |
91
|
|
|
$this->metadataBuilder = $metadataBuilder; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Загрузка данных |
99
|
|
|
* |
100
|
|
|
* @param DataContainer\DataContainerInterface $dataContainer |
101
|
|
|
* @param string $entityClassName |
102
|
|
|
* @param ObjectManager $objectManager |
103
|
|
|
* |
104
|
|
|
* @return $this |
105
|
|
|
* @throws \Nnx\JmsSerializerModule\DoctrineObjectEngine\Exception\InvalidContextException |
106
|
|
|
*/ |
107
|
|
|
public function import(DataContainer\DataContainerInterface $dataContainer, $entityClassName, ObjectManager $objectManager) |
108
|
|
|
{ |
109
|
|
|
$metadata = $this->getMetadataBuilder()->buildMetadata($dataContainer, $entityClassName, $objectManager); |
110
|
|
|
|
111
|
|
|
$this->getImportEngine()->run($dataContainer, $metadata, $objectManager); |
112
|
|
|
$objectManager->flush(); |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Получает сущность, которая соответствует контейнеру с данными |
118
|
|
|
* |
119
|
|
|
* @param DataContainer\EntityInterface $dataItem |
120
|
|
|
* |
121
|
|
|
* @return mixed |
122
|
|
|
* |
123
|
|
|
*/ |
124
|
|
|
public function getDoctrineEntityByDataContainer(DataContainer\EntityInterface $dataItem) |
125
|
|
|
{ |
126
|
|
|
return $this->getImportEngine()->getDoctrineEntityByDataContainer($dataItem); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Удаление данных |
131
|
|
|
* |
132
|
|
|
* @param DataContainer\DataContainerInterface $dataContainer |
133
|
|
|
* @param string $entityClassName |
134
|
|
|
* @param ObjectManager $objectManager |
135
|
|
|
* |
136
|
|
|
* @return $this |
137
|
|
|
*/ |
138
|
|
|
public function purge(DataContainer\DataContainerInterface $dataContainer, $entityClassName, ObjectManager $objectManager) |
139
|
|
|
{ |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|