1 | <?php |
||
23 | class ImportManager |
||
24 | { |
||
25 | /** |
||
26 | * @var FileImport |
||
27 | */ |
||
28 | private $fileImport; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private $locales; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | private $domains; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | private $formats; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | private $translations = []; |
||
49 | |||
50 | /** |
||
51 | * @var Manager |
||
52 | */ |
||
53 | private $esManager; |
||
54 | |||
55 | /** |
||
56 | * @param FileImport $fileImport |
||
57 | * @param Manager $esManager |
||
58 | */ |
||
59 | public function __construct( |
||
66 | |||
67 | /** |
||
68 | * @return mixed |
||
69 | */ |
||
70 | public function getDomains() |
||
74 | |||
75 | /** |
||
76 | * @param mixed $domains |
||
77 | */ |
||
78 | public function setDomains($domains) |
||
82 | |||
83 | /** |
||
84 | * @return mixed |
||
85 | */ |
||
86 | public function getLocales() |
||
90 | |||
91 | /** |
||
92 | * @param mixed $locales |
||
93 | */ |
||
94 | public function setLocales($locales) |
||
98 | |||
99 | /** |
||
100 | * @return mixed |
||
101 | */ |
||
102 | public function getFormats() |
||
106 | |||
107 | /** |
||
108 | * @param mixed $formats |
||
109 | */ |
||
110 | public function setFormats($formats) |
||
114 | |||
115 | /** |
||
116 | * Write translations to storage. |
||
117 | */ |
||
118 | public function writeToStorage() |
||
119 | { |
||
120 | foreach ($this->translations as $domain => $keys) { |
||
121 | foreach ($keys as $key => $transMeta) { |
||
122 | $document = new Translation(); |
||
123 | $document->setDomain($domain); |
||
124 | $document->setKey($key); |
||
125 | $document->setPath($transMeta['path']); |
||
126 | $document->setFormat($transMeta['format']); |
||
127 | foreach ($transMeta['messages'] as $locale => $text) { |
||
128 | $message = new Message(); |
||
129 | $message->setLocale($locale); |
||
130 | $message->setMessage($text); |
||
131 | $document->addMessage($message); |
||
132 | } |
||
133 | $this->esManager->persist($document); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | $this->esManager->commit(); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Imports translation files from a directory. |
||
142 | * @param string $dir |
||
143 | */ |
||
144 | public function importDirTranslationFiles($dir) |
||
149 | |||
150 | /** |
||
151 | * Imports translation files form all bundles. |
||
152 | * |
||
153 | * @param array $bundles |
||
154 | * @param bool $isBundle |
||
155 | */ |
||
156 | public function importBundlesTranslationFiles($bundles, $isBundle = false) |
||
157 | { |
||
158 | foreach ($bundles as $bundle) { |
||
159 | $dir = $isBundle? |
||
160 | dir($bundle->getPath())->path : |
||
161 | dirname((new \ReflectionClass($bundle))->getFileName()); |
||
162 | |||
163 | $this->importDirTranslationFiles($dir); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * Return a Finder object if $path has a Resources/translations folder. |
||
169 | * |
||
170 | * @param string $path |
||
171 | * |
||
172 | * @return Finder |
||
173 | */ |
||
174 | protected function findTranslationsFiles($path) |
||
195 | |||
196 | /** |
||
197 | * @return string |
||
198 | */ |
||
199 | protected function getFileNamePattern() |
||
218 | |||
219 | /** |
||
220 | * Imports some translations files. |
||
221 | * |
||
222 | * @param Finder $finder |
||
223 | */ |
||
224 | protected function importTranslationFiles($finder) |
||
232 | } |
||
233 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..