@@ -16,30 +16,30 @@ discard block |
||
16 | 16 | * @inheritDoc |
17 | 17 | * @throws Exception |
18 | 18 | */ |
19 | - public function parse( DOMDocument $dom, ?array $output = [] ): array { |
|
19 | + public function parse(DOMDocument $dom, ?array $output = []): array { |
|
20 | 20 | $i = 1; |
21 | 21 | /** @var DOMElement $file */ |
22 | - foreach ( $dom->getElementsByTagName( 'file' ) as $file ) { |
|
22 | + foreach ($dom->getElementsByTagName('file') as $file) { |
|
23 | 23 | |
24 | 24 | // metadata |
25 | - $output[ 'files' ][ $i ][ 'attr' ] = $this->extractMetadata( $dom ); |
|
25 | + $output['files'][$i]['attr'] = $this->extractMetadata($dom); |
|
26 | 26 | |
27 | 27 | // notes |
28 | - $output[ 'files' ][ $i ][ 'notes' ] = $this->extractNotes( $file ); |
|
28 | + $output['files'][$i]['notes'] = $this->extractNotes($file); |
|
29 | 29 | |
30 | 30 | // trans-units |
31 | 31 | $transUnitIdArrayForUniquenessCheck = []; |
32 | 32 | $j = 1; |
33 | 33 | /** @var DOMElement $transUnit */ |
34 | - foreach ( $file->childNodes as $childNode ) { |
|
35 | - $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j ); |
|
34 | + foreach ($file->childNodes as $childNode) { |
|
35 | + $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | // trans-unit re-count check |
39 | - $totalTransUnitsId = count( $transUnitIdArrayForUniquenessCheck ); |
|
40 | - $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) ); |
|
41 | - if ( $totalTransUnitsId != $transUnitsUniqueId ) { |
|
42 | - throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 ); |
|
39 | + $totalTransUnitsId = count($transUnitIdArrayForUniquenessCheck); |
|
40 | + $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck)); |
|
41 | + if ($totalTransUnitsId != $transUnitsUniqueId) { |
|
42 | + throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | $i++; |
@@ -53,23 +53,23 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return array |
55 | 55 | */ |
56 | - private function extractMetadata( DOMDocument $dom ): array { |
|
56 | + private function extractMetadata(DOMDocument $dom): array { |
|
57 | 57 | $metadata = []; |
58 | 58 | |
59 | - $xliffNode = $dom->getElementsByTagName( 'xliff' )->item( 0 ); |
|
60 | - $fileNode = $dom->getElementsByTagName( 'file' )->item( 0 ); |
|
59 | + $xliffNode = $dom->getElementsByTagName('xliff')->item(0); |
|
60 | + $fileNode = $dom->getElementsByTagName('file')->item(0); |
|
61 | 61 | |
62 | 62 | // original |
63 | - $metadata[ 'original' ] = ( null !== $fileNode->attributes->getNamedItem( 'original' ) ) ? $fileNode->attributes->getNamedItem( 'original' )->nodeValue : 'no-name'; |
|
63 | + $metadata['original'] = (null !== $fileNode->attributes->getNamedItem('original')) ? $fileNode->attributes->getNamedItem('original')->nodeValue : 'no-name'; |
|
64 | 64 | |
65 | 65 | // source-language |
66 | - $metadata[ 'source-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'srcLang' ) ) ? $xliffNode->attributes->getNamedItem( 'srcLang' )->nodeValue : 'en-US'; |
|
66 | + $metadata['source-language'] = (null !== $xliffNode->attributes->getNamedItem('srcLang')) ? $xliffNode->attributes->getNamedItem('srcLang')->nodeValue : 'en-US'; |
|
67 | 67 | |
68 | 68 | // datatype |
69 | 69 | // @TODO to be implemented |
70 | 70 | |
71 | 71 | // target-language |
72 | - $metadata[ 'target-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'trgLang' ) ) ? $xliffNode->attributes->getNamedItem( 'trgLang' )->nodeValue : 'en-US'; |
|
72 | + $metadata['target-language'] = (null !== $xliffNode->attributes->getNamedItem('trgLang')) ? $xliffNode->attributes->getNamedItem('trgLang')->nodeValue : 'en-US'; |
|
73 | 73 | |
74 | 74 | // custom MateCat x-attribute |
75 | 75 | // @TODO to be implemented |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | * @return array |
84 | 84 | * @throws Exception |
85 | 85 | */ |
86 | - private function extractNotes( DOMElement $file ): array { |
|
86 | + private function extractNotes(DOMElement $file): array { |
|
87 | 87 | $notes = []; |
88 | 88 | |
89 | 89 | // loop <notes> to get nested <note> tag |
90 | - foreach ( $file->childNodes as $childNode ) { |
|
91 | - if ( $childNode->nodeName === 'notes' ) { |
|
92 | - foreach ( $childNode->childNodes as $note ) { |
|
93 | - $noteValue = trim( $note->nodeValue ); |
|
94 | - if ( '' !== $noteValue ) { |
|
95 | - $notes[] = $this->JSONOrRawContentArray( $noteValue ); |
|
90 | + foreach ($file->childNodes as $childNode) { |
|
91 | + if ($childNode->nodeName === 'notes') { |
|
92 | + foreach ($childNode->childNodes as $note) { |
|
93 | + $noteValue = trim($note->nodeValue); |
|
94 | + if ('' !== $noteValue) { |
|
95 | + $notes[] = $this->JSONOrRawContentArray($noteValue); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | } |
@@ -114,32 +114,32 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @throws Exception |
116 | 116 | */ |
117 | - protected function extractTransUnit( DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck, DomDocument $dom, array &$output, int &$i, int &$j, ?array $contextGroups = [] ) { |
|
117 | + protected function extractTransUnit(DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck, DomDocument $dom, array &$output, int &$i, int &$j, ?array $contextGroups = []) { |
|
118 | 118 | // metadata |
119 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck ); |
|
119 | + $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck); |
|
120 | 120 | |
121 | 121 | // notes |
122 | 122 | // merge <notes> with key and key-note contained in metadata <mda:metaGroup> |
123 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $transUnit ); |
|
123 | + $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($transUnit); |
|
124 | 124 | |
125 | 125 | // uuid |
126 | - foreach ( $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] as $note ) { |
|
127 | - if ( isset( $note[ 'raw-content' ] ) && Strings::isAValidUuid( $note[ 'raw-content' ] ) ) { |
|
128 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ][ 'uuid' ] = $note[ 'raw-content' ]; |
|
126 | + foreach ($output['files'][$i]['trans-units'][$j]['notes'] as $note) { |
|
127 | + if (isset($note['raw-content']) && Strings::isAValidUuid($note['raw-content'])) { |
|
128 | + $output['files'][$i]['trans-units'][$j]['attr']['uuid'] = $note['raw-content']; |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | 132 | // original-data (exclusive for V2) |
133 | 133 | // http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html#originaldata |
134 | - $originalData = $this->extractTransUnitOriginalData( $transUnit ); |
|
135 | - if ( !empty( $originalData ) ) { |
|
136 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'original-data' ] = $originalData; |
|
134 | + $originalData = $this->extractTransUnitOriginalData($transUnit); |
|
135 | + if (!empty($originalData)) { |
|
136 | + $output['files'][$i]['trans-units'][$j]['original-data'] = $originalData; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | // additionalTagData (exclusive for V2) |
140 | - $additionalTagData = $this->extractTransUnitAdditionalTagData( $transUnit ); |
|
141 | - if ( !empty( $additionalTagData ) ) { |
|
142 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'additional-tag-data' ] = $additionalTagData; |
|
140 | + $additionalTagData = $this->extractTransUnitAdditionalTagData($transUnit); |
|
141 | + if (!empty($additionalTagData)) { |
|
142 | + $output['files'][$i]['trans-units'][$j]['additional-tag-data'] = $additionalTagData; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | // content |
@@ -159,54 +159,54 @@ discard block |
||
159 | 159 | |
160 | 160 | /** @var DOMElement $segment */ |
161 | 161 | $c = 0; |
162 | - foreach ( $transUnit->childNodes as $segment ) { |
|
163 | - if ( $segment->nodeName === 'segment' ) { |
|
162 | + foreach ($transUnit->childNodes as $segment) { |
|
163 | + if ($segment->nodeName === 'segment') { |
|
164 | 164 | |
165 | 165 | // check segment id consistency |
166 | - $attr = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ]; |
|
167 | - $this->checkSegmentIdConsistency( $segment, $attr ); |
|
166 | + $attr = $output['files'][$i]['trans-units'][$j]['attr']; |
|
167 | + $this->checkSegmentIdConsistency($segment, $attr); |
|
168 | 168 | |
169 | 169 | // loop <segment> to get nested <source> and <target> tag |
170 | - foreach ( $segment->childNodes as $childNode ) { |
|
171 | - if ( $childNode->nodeName === 'source' ) { |
|
172 | - $extractedSource = $this->extractContent( $dom, $childNode ); |
|
173 | - $source[ 'raw-content' ][ $c ] = $extractedSource[ 'raw-content' ]; |
|
170 | + foreach ($segment->childNodes as $childNode) { |
|
171 | + if ($childNode->nodeName === 'source') { |
|
172 | + $extractedSource = $this->extractContent($dom, $childNode); |
|
173 | + $source['raw-content'][$c] = $extractedSource['raw-content']; |
|
174 | 174 | |
175 | - if ( !empty( $extractedSource[ 'attr' ] ) ) { |
|
176 | - $source[ 'attr' ][ $c ] = $extractedSource[ 'attr' ]; |
|
175 | + if (!empty($extractedSource['attr'])) { |
|
176 | + $source['attr'][$c] = $extractedSource['attr']; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | // append value to 'seg-source' |
180 | - if ( $this->stringContainsMarks( $extractedSource[ 'raw-content' ] ) ) { |
|
181 | - $segSource = $this->extractContentWithMarksAndExtTags( $dom, $childNode ); |
|
180 | + if ($this->stringContainsMarks($extractedSource['raw-content'])) { |
|
181 | + $segSource = $this->extractContentWithMarksAndExtTags($dom, $childNode); |
|
182 | 182 | } else { |
183 | 183 | $segSource[] = [ |
184 | - 'attr' => $this->extractTagAttributes( $segment ), |
|
185 | - 'mid' => count( $segSource ) > 0 ? count( $segSource ) : 0, |
|
184 | + 'attr' => $this->extractTagAttributes($segment), |
|
185 | + 'mid' => count($segSource) > 0 ? count($segSource) : 0, |
|
186 | 186 | 'ext-prec-tags' => '', |
187 | - 'raw-content' => $extractedSource[ 'raw-content' ], |
|
187 | + 'raw-content' => $extractedSource['raw-content'], |
|
188 | 188 | 'ext-succ-tags' => '', |
189 | 189 | ]; |
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | - if ( $childNode->nodeName === 'target' ) { |
|
194 | - $extractedTarget = $this->extractContent( $dom, $childNode ); |
|
195 | - $target[ 'raw-content' ][ $c ] = $extractedTarget[ 'raw-content' ]; |
|
193 | + if ($childNode->nodeName === 'target') { |
|
194 | + $extractedTarget = $this->extractContent($dom, $childNode); |
|
195 | + $target['raw-content'][$c] = $extractedTarget['raw-content']; |
|
196 | 196 | |
197 | - if ( !empty( $extractedTarget[ 'attr' ] ) ) { |
|
198 | - $target[ 'attr' ][ $c ] = $extractedTarget[ 'attr' ]; |
|
197 | + if (!empty($extractedTarget['attr'])) { |
|
198 | + $target['attr'][$c] = $extractedTarget['attr']; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | // append value to 'seg-target' |
202 | - if ( $this->stringContainsMarks( $extractedTarget[ 'raw-content' ] ) ) { |
|
203 | - $segTarget = $this->extractContentWithMarksAndExtTags( $dom, $childNode ); |
|
202 | + if ($this->stringContainsMarks($extractedTarget['raw-content'])) { |
|
203 | + $segTarget = $this->extractContentWithMarksAndExtTags($dom, $childNode); |
|
204 | 204 | } else { |
205 | 205 | $segTarget[] = [ |
206 | - 'attr' => $this->extractTagAttributes( $segment ), |
|
207 | - 'mid' => count( $segTarget ) > 0 ? count( $segTarget ) : 0, |
|
206 | + 'attr' => $this->extractTagAttributes($segment), |
|
207 | + 'mid' => count($segTarget) > 0 ? count($segTarget) : 0, |
|
208 | 208 | 'ext-prec-tags' => '', |
209 | - 'raw-content' => $extractedTarget[ 'raw-content' ], |
|
209 | + 'raw-content' => $extractedTarget['raw-content'], |
|
210 | 210 | 'ext-succ-tags' => '', |
211 | 211 | ]; |
212 | 212 | } |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ] = $source; |
|
221 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ] = $target; |
|
222 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $segSource; |
|
223 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $segTarget; |
|
220 | + $output['files'][$i]['trans-units'][$j]['source'] = $source; |
|
221 | + $output['files'][$i]['trans-units'][$j]['target'] = $target; |
|
222 | + $output['files'][$i]['trans-units'][$j]['seg-source'] = $segSource; |
|
223 | + $output['files'][$i]['trans-units'][$j]['seg-target'] = $segTarget; |
|
224 | 224 | |
225 | 225 | $j++; |
226 | 226 | } |
@@ -231,46 +231,46 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return array |
233 | 233 | */ |
234 | - private function extractTransUnitMetadata( DOMElement $transUnit, ?array &$transUnitIdArrayForUniquenessCheck = [] ): array { |
|
234 | + private function extractTransUnitMetadata(DOMElement $transUnit, ?array &$transUnitIdArrayForUniquenessCheck = []): array { |
|
235 | 235 | $metadata = []; |
236 | 236 | |
237 | 237 | // id |
238 | - if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) { |
|
239 | - throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 ); |
|
238 | + if (null === $transUnit->attributes->getNamedItem('id')) { |
|
239 | + throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400); |
|
240 | 240 | } |
241 | 241 | |
242 | - $id = $transUnit->attributes->getNamedItem( 'id' )->nodeValue; |
|
242 | + $id = $transUnit->attributes->getNamedItem('id')->nodeValue; |
|
243 | 243 | |
244 | - if ( strlen( $id ) > 100 ) { |
|
245 | - throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 ); |
|
244 | + if (strlen($id) > 100) { |
|
245 | + throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | $transUnitIdArrayForUniquenessCheck[] = $id; |
249 | - $metadata[ 'id' ] = $id; |
|
249 | + $metadata['id'] = $id; |
|
250 | 250 | |
251 | 251 | // name |
252 | - if ( null !== $transUnit->attributes->getNamedItem( 'name' ) ) { |
|
253 | - $metadata[ 'name' ] = $transUnit->attributes->getNamedItem( 'name' )->nodeValue; |
|
252 | + if (null !== $transUnit->attributes->getNamedItem('name')) { |
|
253 | + $metadata['name'] = $transUnit->attributes->getNamedItem('name')->nodeValue; |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | // translate |
257 | - if ( null !== $transUnit->attributes->getNamedItem( 'translate' ) ) { |
|
258 | - $metadata[ 'translate' ] = $transUnit->attributes->getNamedItem( 'translate' )->nodeValue; |
|
257 | + if (null !== $transUnit->attributes->getNamedItem('translate')) { |
|
258 | + $metadata['translate'] = $transUnit->attributes->getNamedItem('translate')->nodeValue; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | // tGroupBegin |
262 | - if ( null !== $transUnit->attributes->getNamedItem( 'tGroupBegin' ) ) { |
|
263 | - $metadata[ 'tGroupBegin' ] = $transUnit->attributes->getNamedItem( 'tGroupBegin' )->nodeValue; |
|
262 | + if (null !== $transUnit->attributes->getNamedItem('tGroupBegin')) { |
|
263 | + $metadata['tGroupBegin'] = $transUnit->attributes->getNamedItem('tGroupBegin')->nodeValue; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // tGroupEnd |
267 | - if ( null !== $transUnit->attributes->getNamedItem( 'tGroupEnd' ) ) { |
|
268 | - $metadata[ 'tGroupEnd' ] = $transUnit->attributes->getNamedItem( 'tGroupEnd' )->nodeValue; |
|
267 | + if (null !== $transUnit->attributes->getNamedItem('tGroupEnd')) { |
|
268 | + $metadata['tGroupEnd'] = $transUnit->attributes->getNamedItem('tGroupEnd')->nodeValue; |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | // sizeRestriction |
272 | - if ( null !== $transUnit->attributes->getNamedItem( 'sizeRestriction' ) && '' !== $transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue ) { |
|
273 | - $metadata[ 'sizeRestriction' ] = (int)$transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue; |
|
272 | + if (null !== $transUnit->attributes->getNamedItem('sizeRestriction') && '' !== $transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue) { |
|
273 | + $metadata['sizeRestriction'] = (int)$transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | return $metadata; |
@@ -282,31 +282,31 @@ discard block |
||
282 | 282 | * @return array |
283 | 283 | * @throws Exception |
284 | 284 | */ |
285 | - private function extractTransUnitOriginalData( DOMElement $transUnit ): array { |
|
285 | + private function extractTransUnitOriginalData(DOMElement $transUnit): array { |
|
286 | 286 | $originalData = []; |
287 | 287 | |
288 | 288 | // loop <originalData> to get nested content |
289 | - foreach ( $transUnit->childNodes as $childNode ) { |
|
290 | - if ( $childNode->nodeName === 'originalData' ) { |
|
291 | - foreach ( $childNode->childNodes as $data ) { |
|
292 | - if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) { |
|
293 | - $dataId = $data->attributes->getNamedItem( 'id' )->nodeValue; |
|
289 | + foreach ($transUnit->childNodes as $childNode) { |
|
290 | + if ($childNode->nodeName === 'originalData') { |
|
291 | + foreach ($childNode->childNodes as $data) { |
|
292 | + if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) { |
|
293 | + $dataId = $data->attributes->getNamedItem('id')->nodeValue; |
|
294 | 294 | |
295 | - $dataValue = str_replace( Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue ); |
|
296 | - $dataValue = str_replace( Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue ); |
|
297 | - $dataValue = str_replace( Placeholder::TAB_PLACEHOLDER, '\t', $dataValue ); |
|
295 | + $dataValue = str_replace(Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue); |
|
296 | + $dataValue = str_replace(Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue); |
|
297 | + $dataValue = str_replace(Placeholder::TAB_PLACEHOLDER, '\t', $dataValue); |
|
298 | 298 | |
299 | - if ( '' !== $dataValue ) { |
|
299 | + if ('' !== $dataValue) { |
|
300 | 300 | |
301 | - $jsonOrRawContentArray = $this->JSONOrRawContentArray( $dataValue, false ); |
|
301 | + $jsonOrRawContentArray = $this->JSONOrRawContentArray($dataValue, false); |
|
302 | 302 | |
303 | 303 | // restore xliff tags |
304 | - if ( isset( $jsonOrRawContentArray[ 'json' ] ) ) { |
|
305 | - $jsonOrRawContentArray[ 'json' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '<', '>' ], $jsonOrRawContentArray[ 'json' ] ); |
|
304 | + if (isset($jsonOrRawContentArray['json'])) { |
|
305 | + $jsonOrRawContentArray['json'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['<', '>'], $jsonOrRawContentArray['json']); |
|
306 | 306 | } |
307 | 307 | |
308 | - if ( isset( $jsonOrRawContentArray[ 'raw-content' ] ) ) { |
|
309 | - $jsonOrRawContentArray[ 'raw-content' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '<', '>' ], $jsonOrRawContentArray[ 'raw-content' ] ); |
|
308 | + if (isset($jsonOrRawContentArray['raw-content'])) { |
|
309 | + $jsonOrRawContentArray['raw-content'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['<', '>'], $jsonOrRawContentArray['raw-content']); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $originalData[] = array_merge( |
@@ -331,41 +331,41 @@ discard block |
||
331 | 331 | * |
332 | 332 | * @return array |
333 | 333 | */ |
334 | - private function extractTransUnitAdditionalTagData( DOMElement $transUnit ): array { |
|
334 | + private function extractTransUnitAdditionalTagData(DOMElement $transUnit): array { |
|
335 | 335 | $additionalTagData = []; |
336 | 336 | |
337 | 337 | // loop <originalData> to get nested content |
338 | - foreach ( $transUnit->childNodes as $childNode ) { |
|
339 | - if ( $childNode->nodeName === 'memsource:additionalTagData' ) { |
|
340 | - foreach ( $childNode->childNodes as $data ) { |
|
338 | + foreach ($transUnit->childNodes as $childNode) { |
|
339 | + if ($childNode->nodeName === 'memsource:additionalTagData') { |
|
340 | + foreach ($childNode->childNodes as $data) { |
|
341 | 341 | $dataArray = []; |
342 | 342 | |
343 | 343 | // id |
344 | - if ( $data->nodeName === 'memsource:tag' ) { |
|
345 | - if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) { |
|
346 | - $dataId = $data->attributes->getNamedItem( 'id' )->nodeValue; |
|
347 | - $dataArray[ 'attr' ][ 'id' ] = $dataId; |
|
344 | + if ($data->nodeName === 'memsource:tag') { |
|
345 | + if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) { |
|
346 | + $dataId = $data->attributes->getNamedItem('id')->nodeValue; |
|
347 | + $dataArray['attr']['id'] = $dataId; |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 | |
351 | 351 | // in PHP 7.4 $data->childNodes is an empty DomNodeList, it is iterable with size 0 |
352 | 352 | // PHP 5.6 check: in php 5.6 $data->childNodes can be null |
353 | - if ( $data->childNodes != null ) { |
|
353 | + if ($data->childNodes != null) { |
|
354 | 354 | |
355 | 355 | // content |
356 | - foreach ( $data->childNodes as $datum ) { |
|
357 | - if ( $datum->nodeName === 'memsource:tagId' ) { |
|
358 | - $dataArray[ 'raw-content' ][ 'tagId' ] = $datum->nodeValue; |
|
356 | + foreach ($data->childNodes as $datum) { |
|
357 | + if ($datum->nodeName === 'memsource:tagId') { |
|
358 | + $dataArray['raw-content']['tagId'] = $datum->nodeValue; |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( $datum->nodeName === 'memsource:type' ) { |
|
362 | - $dataArray[ 'raw-content' ][ 'type' ] = $datum->nodeValue; |
|
361 | + if ($datum->nodeName === 'memsource:type') { |
|
362 | + $dataArray['raw-content']['type'] = $datum->nodeValue; |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | |
366 | 366 | } |
367 | 367 | |
368 | - if ( !empty( $dataArray ) ) { |
|
368 | + if (!empty($dataArray)) { |
|
369 | 369 | $additionalTagData[] = $dataArray; |
370 | 370 | } |
371 | 371 | } |
@@ -381,15 +381,15 @@ discard block |
||
381 | 381 | * @param DOMElement $segment |
382 | 382 | * @param array $attr |
383 | 383 | */ |
384 | - private function checkSegmentIdConsistency( DOMElement $segment, array $attr ) { |
|
385 | - if ( isset( $attr[ 'tGroupBegin' ] ) && isset( $attr[ 'tGroupEnd' ] ) && $segment->attributes->getNamedItem( 'id' ) ) { |
|
386 | - $id = $segment->attributes->getNamedItem( 'id' )->nodeValue; |
|
387 | - $min = (int)$attr[ 'tGroupBegin' ]; |
|
388 | - $max = (int)$attr[ 'tGroupEnd' ]; |
|
389 | - |
|
390 | - if ( false === ( ( $min <= $id ) && ( $id <= $max ) ) ) { |
|
391 | - if ( $this->logger ) { |
|
392 | - $this->logger->warning( 'Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd' ); |
|
384 | + private function checkSegmentIdConsistency(DOMElement $segment, array $attr) { |
|
385 | + if (isset($attr['tGroupBegin']) && isset($attr['tGroupEnd']) && $segment->attributes->getNamedItem('id')) { |
|
386 | + $id = $segment->attributes->getNamedItem('id')->nodeValue; |
|
387 | + $min = (int)$attr['tGroupBegin']; |
|
388 | + $max = (int)$attr['tGroupEnd']; |
|
389 | + |
|
390 | + if (false === (($min <= $id) && ($id <= $max))) { |
|
391 | + if ($this->logger) { |
|
392 | + $this->logger->warning('Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd'); |
|
393 | 393 | } |
394 | 394 | } |
395 | 395 | } |
@@ -401,31 +401,31 @@ discard block |
||
401 | 401 | * @return array |
402 | 402 | * @throws Exception |
403 | 403 | */ |
404 | - private function extractTransUnitNotes( DOMElement $transUnit ): array { |
|
404 | + private function extractTransUnitNotes(DOMElement $transUnit): array { |
|
405 | 405 | $notes = []; |
406 | 406 | |
407 | 407 | // loop <notes> to get nested <note> tag |
408 | - foreach ( $transUnit->childNodes as $childNode ) { |
|
409 | - if ( $childNode->nodeName == 'notes' ) { |
|
410 | - foreach ( $childNode->childNodes as $note ) { |
|
411 | - $noteValue = trim( $note->nodeValue ); |
|
412 | - if ( '' !== $noteValue ) { |
|
413 | - $notes[] = $this->JSONOrRawContentArray( $noteValue ); |
|
408 | + foreach ($transUnit->childNodes as $childNode) { |
|
409 | + if ($childNode->nodeName == 'notes') { |
|
410 | + foreach ($childNode->childNodes as $note) { |
|
411 | + $noteValue = trim($note->nodeValue); |
|
412 | + if ('' !== $noteValue) { |
|
413 | + $notes[] = $this->JSONOrRawContentArray($noteValue); |
|
414 | 414 | } |
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | - if ( $childNode->nodeName === 'mda:metadata' ) { |
|
419 | - foreach ( $childNode->childNodes as $metadata ) { |
|
420 | - if ( $metadata->nodeName === 'mda:metaGroup' ) { |
|
421 | - foreach ( $metadata->childNodes as $meta ) { |
|
422 | - if ( null !== $meta->attributes && null !== $meta->attributes->getNamedItem( 'type' ) ) { |
|
423 | - $type = $meta->attributes->getNamedItem( 'type' )->nodeValue; |
|
424 | - $metaValue = trim( $meta->nodeValue ); |
|
418 | + if ($childNode->nodeName === 'mda:metadata') { |
|
419 | + foreach ($childNode->childNodes as $metadata) { |
|
420 | + if ($metadata->nodeName === 'mda:metaGroup') { |
|
421 | + foreach ($metadata->childNodes as $meta) { |
|
422 | + if (null !== $meta->attributes && null !== $meta->attributes->getNamedItem('type')) { |
|
423 | + $type = $meta->attributes->getNamedItem('type')->nodeValue; |
|
424 | + $metaValue = trim($meta->nodeValue); |
|
425 | 425 | |
426 | - if ( '' !== $metaValue ) { |
|
426 | + if ('' !== $metaValue) { |
|
427 | 427 | $notes[] = array_merge( |
428 | - $this->JSONOrRawContentArray( $metaValue ), |
|
428 | + $this->JSONOrRawContentArray($metaValue), |
|
429 | 429 | [ |
430 | 430 | 'attr' => [ |
431 | 431 | 'type' => $type |