-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntityImporterDefinition.php
140 lines (121 loc) · 3.83 KB
/
EntityImporterDefinition.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* Copyright © Fastbolt Schraubengroßhandels GmbH.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Fastbolt\EntityImporter;
use Doctrine\Persistence\ObjectRepository;
use Fastbolt\EntityImporter\Types\ImportSourceDefinition\ImportSourceDefinition;
/**
* @template T
*/
interface EntityImporterDefinition
{
/**
* Name displayed in console / used to execute command.
* Should not contain white spaces and special characters.
*
* @return string
*/
public function getName(): string;
/**
* Description displayed in "Available import types" overview.
*
* @return string
*/
public function getDescription(): string;
/**
* Full-qualified class-name of the entity to import.
*
* @return class-string
*/
public function getEntityClass(): string;
/**
* Factory method to create an entity instance. Must return null or callable.
* The callable will receive the importer-definition, the current entity-instance
* (if any) and the current import source row array as arguments.
* Must always return an entity instance.
*
* @return callable(EntityImporterDefinition<T>,T|null,array<string,mixed>):T|null
*/
public function getEntityFactory(): ?callable;
/**
* Get list of fields to import. Must always contain all fields available in input source.
*
* @return array<int,string>
*/
public function getFields(): array;
/**
* Get list of converters (callables) per field. Callable will recieve the current field value and must
* return the correct value / type for the field.
*
* @return array<string, callable>
*/
public function getFieldConverters(): array;
/**
* List of columns used as doctrine identifier, for loading existing items from database.
*
* @return array<int,string>
*/
public function getIdentifierColumns(): array;
/**
* Get modifier callable applied to identifier selection before loading entity from database.
* Can be used to add static columns to identifier selection or even modify selection array.
*
* @return callable(array<string,mixed>):array<string,mixed>|null
*/
public function getIdentifierModifier(): ?callable;
/**
* Import source definition to specify source data format.
*
* @return ImportSourceDefinition
*/
public function getImportSourceDefinition(): ImportSourceDefinition;
/**
* Repository instance to be used.
*
* @return ObjectRepository<T>
*/
public function getRepository(): ObjectRepository;
/**
* Interval - every n'th row will flush the entity manager.
*
* @return int
*/
public function getFlushInterval(): int;
/**
* Return list of skipped field names.
*
* @return array<int,string>
*/
public function getSkippedFields(): array;
/**
* Callable used for entity creation.
* Defaults to {@see \Fastbolt\EntityImporter\Factory\EntityInstantiator::getInstance()}.
*
* @return callable(array<string,mixed>):T|null
*/
public function getEntityInstantiator(): ?callable;
/**
* Callable used to modify entity before persisting.
*
* @return callable(T, array<mixed>)|null
*/
public function getEntityModifier(): ?callable;
/**
* Return list of mappings for differing field names between source and target.
*
* Example:
* ['name1' => 'lastname']
*
* @return array<string, string>
*/
public function getFieldNameMapping(): array;
/**
* Option to disable throwing an exception on unknown fields.
*
* @return bool
*/
public function isThrowExceptionOnUnknownField(): bool;
}