@@ -11,5 +11,5 @@ |
||
11 | 11 | * |
12 | 12 | * @return bool |
13 | 13 | */ |
14 | - public function thereAreErrors( $segmentId, $segment, $translation, array $dataRefMap = [] ); |
|
14 | + public function thereAreErrors($segmentId, $segment, $translation, array $dataRefMap = []); |
|
15 | 15 | } |
@@ -18,13 +18,13 @@ |
||
18 | 18 | * |
19 | 19 | * @return SdlXliffSAXTranslationReplacer|XliffSAXTranslationReplacer |
20 | 20 | */ |
21 | - public static function getInstance( $originalXliffPath, &$data, &$transUnits, $targetLang, $outputFilePath, $setSourceInTarget, LoggerInterface $logger = null, XliffReplacerCallbackInterface $callback = null ) { |
|
22 | - $info = XliffProprietaryDetect::getInfo( $originalXliffPath ); |
|
21 | + public static function getInstance($originalXliffPath, &$data, &$transUnits, $targetLang, $outputFilePath, $setSourceInTarget, LoggerInterface $logger = null, XliffReplacerCallbackInterface $callback = null) { |
|
22 | + $info = XliffProprietaryDetect::getInfo($originalXliffPath); |
|
23 | 23 | |
24 | - if ( $info[ 'proprietary_short_name' ] !== 'trados' ) { |
|
25 | - return new XliffSAXTranslationReplacer( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
24 | + if ($info['proprietary_short_name'] !== 'trados') { |
|
25 | + return new XliffSAXTranslationReplacer($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
26 | 26 | } |
27 | 27 | |
28 | - return new SdlXliffSAXTranslationReplacer( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
28 | + return new SdlXliffSAXTranslationReplacer($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
29 | 29 | } |
30 | 30 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param LoggerInterface $logger |
26 | 26 | */ |
27 | - public function __construct( LoggerInterface $logger = null ) { |
|
27 | + public function __construct(LoggerInterface $logger = null) { |
|
28 | 28 | $this->logger = $logger; |
29 | 29 | } |
30 | 30 | |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | * @param bool $setSourceInTarget |
40 | 40 | * @param XliffReplacerCallbackInterface|null $callback |
41 | 41 | */ |
42 | - public function replaceTranslation( $originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null ) { |
|
42 | + public function replaceTranslation($originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null) { |
|
43 | 43 | try { |
44 | - $parser = XliffReplacerFactory::getInstance( $originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback ); |
|
44 | + $parser = XliffReplacerFactory::getInstance($originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback); |
|
45 | 45 | $parser->replaceTranslation(); |
46 | - } catch ( \Exception $exception ) { |
|
46 | + } catch (\Exception $exception) { |
|
47 | 47 | // do nothing |
48 | 48 | } |
49 | 49 | } |
@@ -61,29 +61,29 @@ discard block |
||
61 | 61 | * @throws Exception\NotValidFileException |
62 | 62 | * @throws Exception\XmlParsingException |
63 | 63 | */ |
64 | - public function xliffToArray( $xliffContent, $collapseEmptyTags = false ) { |
|
64 | + public function xliffToArray($xliffContent, $collapseEmptyTags = false) { |
|
65 | 65 | $xliff = []; |
66 | - $xliffContent = self::forceUft8Encoding( $xliffContent, $xliff ); |
|
67 | - $xliffVersion = XliffVersionDetector::detect( $xliffContent ); |
|
68 | - $info = XliffProprietaryDetect::getInfoFromXliffContent( $xliffContent ); |
|
66 | + $xliffContent = self::forceUft8Encoding($xliffContent, $xliff); |
|
67 | + $xliffVersion = XliffVersionDetector::detect($xliffContent); |
|
68 | + $info = XliffProprietaryDetect::getInfoFromXliffContent($xliffContent); |
|
69 | 69 | |
70 | - if ( $xliffVersion === 1 ) { |
|
71 | - $xliffContent = self::removeInternalFileTagFromContent( $xliffContent, $xliff ); |
|
70 | + if ($xliffVersion === 1) { |
|
71 | + $xliffContent = self::removeInternalFileTagFromContent($xliffContent, $xliff); |
|
72 | 72 | } |
73 | 73 | |
74 | - if ( $xliffVersion === 2 ) { |
|
75 | - $xliffContent = self::escapeDataInOriginalMap( $xliffContent ); |
|
74 | + if ($xliffVersion === 2) { |
|
75 | + $xliffContent = self::escapeDataInOriginalMap($xliffContent); |
|
76 | 76 | } |
77 | 77 | |
78 | - if ( $collapseEmptyTags === false ) { |
|
79 | - $xliffContent = self::insertPlaceholderInEmptyTags( $xliffContent ); |
|
78 | + if ($collapseEmptyTags === false) { |
|
79 | + $xliffContent = self::insertPlaceholderInEmptyTags($xliffContent); |
|
80 | 80 | } |
81 | 81 | |
82 | - $xliffProprietary = ( isset( $info[ 'proprietary_short_name' ] ) && null !== $info[ 'proprietary_short_name' ] ) ? $info[ 'proprietary_short_name' ] : null; |
|
83 | - $parser = XliffParserFactory::getInstance( $xliffVersion, $xliffProprietary, $this->logger ); |
|
84 | - $dom = XmlParser::parse( $xliffContent ); |
|
82 | + $xliffProprietary = (isset($info['proprietary_short_name']) && null !== $info['proprietary_short_name']) ? $info['proprietary_short_name'] : null; |
|
83 | + $parser = XliffParserFactory::getInstance($xliffVersion, $xliffProprietary, $this->logger); |
|
84 | + $dom = XmlParser::parse($xliffContent); |
|
85 | 85 | |
86 | - return $parser->parse( $dom, $xliff ); |
|
86 | + return $parser->parse($dom, $xliff); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string |
97 | 97 | */ |
98 | - private static function forceUft8Encoding( $xliffContent, &$xliff ) { |
|
99 | - $enc = mb_detect_encoding( $xliffContent ); |
|
98 | + private static function forceUft8Encoding($xliffContent, &$xliff) { |
|
99 | + $enc = mb_detect_encoding($xliffContent); |
|
100 | 100 | |
101 | - if ( $enc !== 'UTF-8' ) { |
|
102 | - $xliff[ 'parser-warnings' ][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only"; |
|
103 | - $s = iconv( $enc, 'UTF-8', $xliffContent ); |
|
101 | + if ($enc !== 'UTF-8') { |
|
102 | + $xliff['parser-warnings'][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only"; |
|
103 | + $s = iconv($enc, 'UTF-8', $xliffContent); |
|
104 | 104 | $xliffContent = $s !== false ? $s : ""; |
105 | 105 | } |
106 | 106 | |
@@ -117,24 +117,24 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return mixed|string |
119 | 119 | */ |
120 | - private static function removeInternalFileTagFromContent( $xliffContent, &$xliff ) { |
|
120 | + private static function removeInternalFileTagFromContent($xliffContent, &$xliff) { |
|
121 | 121 | $index = 1; |
122 | - $a = Strings::preg_split( '|<internal-file[\s>]|si', $xliffContent ); |
|
122 | + $a = Strings::preg_split('|<internal-file[\s>]|si', $xliffContent); |
|
123 | 123 | |
124 | 124 | // no match, return original string |
125 | - if ( count( $a ) === 1 ) { |
|
126 | - return $a[ 0 ]; |
|
125 | + if (count($a) === 1) { |
|
126 | + return $a[0]; |
|
127 | 127 | } |
128 | 128 | |
129 | - $b = Strings::preg_split( '|</internal-file>|si', $a[ 1 ] ); |
|
130 | - $strippedContent = $a[ 0 ] . $b[ 1 ]; |
|
131 | - $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $b[ 0 ] ); |
|
129 | + $b = Strings::preg_split('|</internal-file>|si', $a[1]); |
|
130 | + $strippedContent = $a[0] . $b[1]; |
|
131 | + $xliff['files'][$index]['reference'][] = self::extractBase64($b[0]); |
|
132 | 132 | $index++; |
133 | 133 | |
134 | - if ( isset( $a[ 2 ] ) ) { |
|
135 | - $c = Strings::preg_split( '|</internal-file[\s>]|si', $a[ 2 ] ); |
|
136 | - $strippedContent .= $c[ 1 ]; |
|
137 | - $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $c[ 0 ] ); |
|
134 | + if (isset($a[2])) { |
|
135 | + $c = Strings::preg_split('|</internal-file[\s>]|si', $a[2]); |
|
136 | + $strippedContent .= $c[1]; |
|
137 | + $xliff['files'][$index]['reference'][] = self::extractBase64($c[0]); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return $strippedContent; |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return array |
147 | 147 | */ |
148 | - private static function extractBase64( $base64 ) { |
|
148 | + private static function extractBase64($base64) { |
|
149 | 149 | return [ |
150 | 150 | 'form-type' => 'base64', |
151 | - 'base64' => trim( str_replace( 'form="base64">', '', $base64 ) ), |
|
151 | + 'base64' => trim(str_replace('form="base64">', '', $base64)), |
|
152 | 152 | ]; |
153 | 153 | } |
154 | 154 | |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - private static function escapeDataInOriginalMap( $xliffContent ) { |
|
172 | - $xliffContent = preg_replace_callback( '/<data(.*?)>(.*?)<\/data>/iU', [ XliffParser::class, 'replaceSpace' ], $xliffContent ); |
|
173 | - $xliffContent = preg_replace_callback( '/<data(.*?)>(.*?)<\/data>/iU', [ XliffParser::class, 'replaceXliffTags' ], $xliffContent ); |
|
171 | + private static function escapeDataInOriginalMap($xliffContent) { |
|
172 | + $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceSpace'], $xliffContent); |
|
173 | + $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceXliffTags'], $xliffContent); |
|
174 | 174 | |
175 | 175 | return $xliffContent; |
176 | 176 | } |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - private static function insertPlaceholderInEmptyTags( $xliffContent ) { |
|
193 | - preg_match_all( '/<([a-zA-Z0-9._-]+)[^>]*><\/\1>/sm', $xliffContent, $emptyTagMatches ); |
|
192 | + private static function insertPlaceholderInEmptyTags($xliffContent) { |
|
193 | + preg_match_all('/<([a-zA-Z0-9._-]+)[^>]*><\/\1>/sm', $xliffContent, $emptyTagMatches); |
|
194 | 194 | |
195 | - if ( !empty( $emptyTagMatches[ 0 ] ) ) { |
|
196 | - foreach ( $emptyTagMatches[ 0 ] as $index => $emptyTagMatch ) { |
|
197 | - $matchedTag = $emptyTagMatches[ 1 ][ $index ]; |
|
195 | + if (!empty($emptyTagMatches[0])) { |
|
196 | + foreach ($emptyTagMatches[0] as $index => $emptyTagMatch) { |
|
197 | + $matchedTag = $emptyTagMatches[1][$index]; |
|
198 | 198 | $subst = Placeholder::EMPTY_TAG_PLACEHOLDER . '</' . $matchedTag . '>'; |
199 | - $replacedTag = str_replace( '</' . $matchedTag . '>', $subst, $emptyTagMatch ); |
|
200 | - $xliffContent = str_replace( $emptyTagMatch, $replacedTag, $xliffContent ); |
|
199 | + $replacedTag = str_replace('</' . $matchedTag . '>', $subst, $emptyTagMatch); |
|
200 | + $xliffContent = str_replace($emptyTagMatch, $replacedTag, $xliffContent); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
@@ -211,12 +211,12 @@ discard block |
||
211 | 211 | * |
212 | 212 | * @return string |
213 | 213 | */ |
214 | - private static function replaceSpace( $matches ) { |
|
215 | - $content = str_replace( ' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[ 2 ] ); |
|
216 | - $content = str_replace( '\n', Placeholder::NEW_LINE_PLACEHOLDER, $content ); |
|
217 | - $content = str_replace( '\t', Placeholder::TAB_PLACEHOLDER, $content ); |
|
214 | + private static function replaceSpace($matches) { |
|
215 | + $content = str_replace(' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[2]); |
|
216 | + $content = str_replace('\n', Placeholder::NEW_LINE_PLACEHOLDER, $content); |
|
217 | + $content = str_replace('\t', Placeholder::TAB_PLACEHOLDER, $content); |
|
218 | 218 | |
219 | - return '<data' . $matches[ 1 ] . '>' . $content . '</data>'; |
|
219 | + return '<data' . $matches[1] . '>' . $content . '</data>'; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -224,15 +224,15 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - private static function replaceXliffTags( $matches ) { |
|
227 | + private static function replaceXliffTags($matches) { |
|
228 | 228 | $xliffTags = XliffTags::$tags; |
229 | - $content = $matches[ 2 ]; |
|
229 | + $content = $matches[2]; |
|
230 | 230 | |
231 | - foreach ( $xliffTags as $xliffTag ) { |
|
232 | - $content = preg_replace( '|<(' . $xliffTag . '.*?)>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content ); |
|
233 | - $content = preg_replace( '|<(/' . $xliffTag . ')>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content ); |
|
231 | + foreach ($xliffTags as $xliffTag) { |
|
232 | + $content = preg_replace('|<(' . $xliffTag . '.*?)>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content); |
|
233 | + $content = preg_replace('|<(/' . $xliffTag . ')>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content); |
|
234 | 234 | } |
235 | 235 | |
236 | - return '<data' . $matches[ 1 ] . '>' . $content . '</data>'; |
|
236 | + return '<data' . $matches[1] . '>' . $content . '</data>'; |
|
237 | 237 | } |
238 | 238 | } |
@@ -8,14 +8,14 @@ |
||
8 | 8 | * https://stackoverflow.com/questions/11427398/how-to-implode-array-with-key-and-value-without-foreach-in-php |
9 | 9 | */ |
10 | 10 | class FlatData { |
11 | - public static function flatArray( array $input = [], $separator_elements = ', ', $separator = ': ' ) { |
|
12 | - return implode( $separator_elements, array_map( |
|
13 | - function ( $v, $k, $s ) { |
|
14 | - return sprintf( "%s{$s}\"%s\"", $k, $v ); |
|
11 | + public static function flatArray(array $input = [], $separator_elements = ', ', $separator = ': ') { |
|
12 | + return implode($separator_elements, array_map( |
|
13 | + function($v, $k, $s) { |
|
14 | + return sprintf("%s{$s}\"%s\"", $k, $v); |
|
15 | 15 | }, |
16 | 16 | $input, |
17 | - array_keys( $input ), |
|
18 | - array_fill( 0, count( $input ), $separator ) |
|
19 | - ) ); |
|
17 | + array_keys($input), |
|
18 | + array_fill(0, count($input), $separator) |
|
19 | + )); |
|
20 | 20 | } |
21 | 21 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | * |
13 | 13 | * @return AbstractXliffParser |
14 | 14 | */ |
15 | - public static function getInstance( $xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null ) { |
|
15 | + public static function getInstance($xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null) { |
|
16 | 16 | $parserClass = 'Matecat\\XliffParser\\XliffParser\\XliffParserV' . $xliffVersion; |
17 | 17 | |
18 | 18 | /** @var AbstractXliffParser $parser */ |
19 | - return new $parserClass( $xliffVersion, $xliffProprietary, $logger ); |
|
19 | + return new $parserClass($xliffVersion, $xliffProprietary, $logger); |
|
20 | 20 | } |
21 | 21 | } |
@@ -16,33 +16,33 @@ discard block |
||
16 | 16 | * @inheritDoc |
17 | 17 | * @throws Exception |
18 | 18 | */ |
19 | - public function parse( DOMDocument $dom, $output = [] ) { |
|
19 | + public function parse(DOMDocument $dom, $output = []) { |
|
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( $file ); |
|
25 | + $output['files'][$i]['attr'] = $this->extractMetadata($file); |
|
26 | 26 | |
27 | 27 | // reference |
28 | - if ( !empty( $this->extractReference( $file ) ) ) { |
|
29 | - $output[ 'files' ][ $i ][ 'reference' ] = $this->extractReference( $file ); |
|
28 | + if (!empty($this->extractReference($file))) { |
|
29 | + $output['files'][$i]['reference'] = $this->extractReference($file); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | // trans-units |
33 | 33 | $transUnitIdArrayForUniquenessCheck = []; |
34 | 34 | $j = 1; |
35 | - foreach ( $file->childNodes as $body ) { |
|
36 | - if ( $body->nodeName === 'body' ) { |
|
37 | - foreach ( $body->childNodes as $childNode ) { |
|
38 | - $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j ); |
|
35 | + foreach ($file->childNodes as $body) { |
|
36 | + if ($body->nodeName === 'body') { |
|
37 | + foreach ($body->childNodes as $childNode) { |
|
38 | + $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | // trans-unit re-count check |
42 | - $totalTransUnitsId = count( $transUnitIdArrayForUniquenessCheck ); |
|
43 | - $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) ); |
|
44 | - if ( $totalTransUnitsId != $transUnitsUniqueId ) { |
|
45 | - throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 ); |
|
42 | + $totalTransUnitsId = count($transUnitIdArrayForUniquenessCheck); |
|
43 | + $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck)); |
|
44 | + if ($totalTransUnitsId != $transUnitsUniqueId) { |
|
45 | + throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $i++; |
@@ -58,50 +58,50 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - private function extractMetadata( DOMElement $file ) { |
|
61 | + private function extractMetadata(DOMElement $file) { |
|
62 | 62 | $metadata = []; |
63 | 63 | $customAttr = []; |
64 | 64 | |
65 | 65 | /** @var DOMAttr $attribute */ |
66 | - foreach ( $file->attributes as $attribute ) { |
|
67 | - switch ( $attribute->localName ) { |
|
66 | + foreach ($file->attributes as $attribute) { |
|
67 | + switch ($attribute->localName) { |
|
68 | 68 | // original |
69 | 69 | case 'original': |
70 | - $metadata[ 'original' ] = $attribute->value; |
|
70 | + $metadata['original'] = $attribute->value; |
|
71 | 71 | break; |
72 | 72 | |
73 | 73 | // source-language |
74 | 74 | case 'source-language': |
75 | - $metadata[ 'source-language' ] = $attribute->value; |
|
75 | + $metadata['source-language'] = $attribute->value; |
|
76 | 76 | break; |
77 | 77 | |
78 | 78 | // data-type |
79 | 79 | case 'datatype': |
80 | - $metadata[ 'data-type' ] = $attribute->value; |
|
80 | + $metadata['data-type'] = $attribute->value; |
|
81 | 81 | break; |
82 | 82 | |
83 | 83 | // target-language |
84 | 84 | case 'target-language': |
85 | - $metadata[ 'target-language' ] = $attribute->value; |
|
85 | + $metadata['target-language'] = $attribute->value; |
|
86 | 86 | break; |
87 | 87 | } |
88 | 88 | |
89 | 89 | // Custom MateCat x-Attribute |
90 | - preg_match( '|x-(.*?)|si', $attribute->localName, $temp ); |
|
91 | - if ( isset( $temp[ 1 ] ) ) { |
|
92 | - $customAttr[ $attribute->localName ] = $attribute->value; |
|
90 | + preg_match('|x-(.*?)|si', $attribute->localName, $temp); |
|
91 | + if (isset($temp[1])) { |
|
92 | + $customAttr[$attribute->localName] = $attribute->value; |
|
93 | 93 | } |
94 | - unset( $temp ); |
|
94 | + unset($temp); |
|
95 | 95 | |
96 | 96 | // Custom MateCat namespace Attribute mtc: |
97 | - preg_match( '|mtc:(.*?)|si', $attribute->nodeName, $temp ); |
|
98 | - if ( isset( $temp[ 1 ] ) ) { |
|
99 | - $customAttr[ $attribute->nodeName ] = $attribute->value; |
|
97 | + preg_match('|mtc:(.*?)|si', $attribute->nodeName, $temp); |
|
98 | + if (isset($temp[1])) { |
|
99 | + $customAttr[$attribute->nodeName] = $attribute->value; |
|
100 | 100 | } |
101 | - unset( $temp ); |
|
101 | + unset($temp); |
|
102 | 102 | |
103 | - if ( !empty( $customAttr ) ) { |
|
104 | - $metadata[ 'custom' ] = $customAttr; |
|
103 | + if (!empty($customAttr)) { |
|
104 | + $metadata['custom'] = $customAttr; |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return array |
115 | 115 | */ |
116 | - private function extractReference( DOMElement $file ) { |
|
116 | + private function extractReference(DOMElement $file) { |
|
117 | 117 | $reference = []; |
118 | 118 | |
119 | 119 | $order = 0; |
120 | - foreach ( $file->getElementsByTagName( 'reference' ) as $ref ) { |
|
120 | + foreach ($file->getElementsByTagName('reference') as $ref) { |
|
121 | 121 | /** @var DOMNode $childNode */ |
122 | - foreach ( $ref->childNodes as $childNode ) { |
|
123 | - if ( $childNode->nodeName === 'internal-file' ) { |
|
124 | - $reference[ $order ][ 'form-type' ] = $childNode->attributes->getNamedItem( 'form' )->nodeValue; |
|
125 | - $reference[ $order ][ 'base64' ] = trim( $childNode->nodeValue ); |
|
122 | + foreach ($ref->childNodes as $childNode) { |
|
123 | + if ($childNode->nodeName === 'internal-file') { |
|
124 | + $reference[$order]['form-type'] = $childNode->attributes->getNamedItem('form')->nodeValue; |
|
125 | + $reference[$order]['base64'] = trim($childNode->nodeValue); |
|
126 | 126 | $order++; |
127 | 127 | } |
128 | 128 | } |
@@ -143,53 +143,53 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @throws Exception |
145 | 145 | */ |
146 | - protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j ) { |
|
146 | + protected function extractTransUnit($transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j) { |
|
147 | 147 | // metadata |
148 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck ); |
|
148 | + $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck); |
|
149 | 149 | |
150 | 150 | // notes |
151 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $dom, $transUnit ); |
|
151 | + $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($dom, $transUnit); |
|
152 | 152 | |
153 | 153 | // content |
154 | 154 | /** @var DOMElement $childNode */ |
155 | - foreach ( $transUnit->childNodes as $childNode ) { |
|
155 | + foreach ($transUnit->childNodes as $childNode) { |
|
156 | 156 | // source |
157 | - if ( $childNode->nodeName === 'source' ) { |
|
158 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ] = $this->extractContent( $dom, $childNode ); |
|
157 | + if ($childNode->nodeName === 'source') { |
|
158 | + $output['files'][$i]['trans-units'][$j]['source'] = $this->extractContent($dom, $childNode); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | // seg-source |
162 | - if ( $childNode->nodeName === 'seg-source' ) { |
|
163 | - $rawSegment = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ][ 'raw-content' ]; |
|
164 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $rawSegment ); |
|
162 | + if ($childNode->nodeName === 'seg-source') { |
|
163 | + $rawSegment = $output['files'][$i]['trans-units'][$j]['source']['raw-content']; |
|
164 | + $output['files'][$i]['trans-units'][$j]['seg-source'] = $this->extractContentWithMarksAndExtTags($dom, $childNode, $rawSegment); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // target |
168 | - if ( $childNode->nodeName === 'target' ) { |
|
169 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ] = $this->extractContent( $dom, $childNode ); |
|
168 | + if ($childNode->nodeName === 'target') { |
|
169 | + $output['files'][$i]['trans-units'][$j]['target'] = $this->extractContent($dom, $childNode); |
|
170 | 170 | |
171 | 171 | // seg-target |
172 | - $targetRawContent = @$output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ][ 'raw-content' ]; |
|
173 | - $segSource = @$output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ]; |
|
174 | - if ( isset( $targetRawContent ) && !empty( $targetRawContent ) && isset( $segSource ) && count( $segSource ) > 0 ) { |
|
175 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $targetRawContent ); |
|
172 | + $targetRawContent = @$output['files'][$i]['trans-units'][$j]['target']['raw-content']; |
|
173 | + $segSource = @$output['files'][$i]['trans-units'][$j]['seg-source']; |
|
174 | + if (isset($targetRawContent) && !empty($targetRawContent) && isset($segSource) && count($segSource) > 0) { |
|
175 | + $output['files'][$i]['trans-units'][$j]['seg-target'] = $this->extractContentWithMarksAndExtTags($dom, $childNode, $targetRawContent); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | 179 | // locked |
180 | - if ( $childNode->nodeName === 'sdl:seg' ) { |
|
181 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'locked' ] = $this->extractLocked( $childNode ); |
|
180 | + if ($childNode->nodeName === 'sdl:seg') { |
|
181 | + $output['files'][$i]['trans-units'][$j]['locked'] = $this->extractLocked($childNode); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | 185 | // context-group |
186 | - foreach ( $transUnit->getElementsByTagName( 'context-group' ) as $contextGroup ) { |
|
187 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'context-group' ][] = $this->extractTransUnitContextGroup( $dom, $contextGroup ); |
|
186 | + foreach ($transUnit->getElementsByTagName('context-group') as $contextGroup) { |
|
187 | + $output['files'][$i]['trans-units'][$j]['context-group'][] = $this->extractTransUnitContextGroup($dom, $contextGroup); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // alt-trans |
191 | - foreach ( $transUnit->getElementsByTagName( 'alt-trans' ) as $altTrans ) { |
|
192 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'alt-trans' ][] = $this->extractTransUnitAltTrans( $altTrans ); |
|
191 | + foreach ($transUnit->getElementsByTagName('alt-trans') as $altTrans) { |
|
192 | + $output['files'][$i]['trans-units'][$j]['alt-trans'][] = $this->extractTransUnitAltTrans($altTrans); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | $j++; |
@@ -202,41 +202,41 @@ discard block |
||
202 | 202 | * @return array |
203 | 203 | * @throws Exception |
204 | 204 | */ |
205 | - private function extractTransUnitMetadata( DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck ) { |
|
205 | + private function extractTransUnitMetadata(DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck) { |
|
206 | 206 | $metadata = []; |
207 | 207 | |
208 | 208 | // id MUST NOT be null |
209 | - if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) { |
|
210 | - throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 ); |
|
209 | + if (null === $transUnit->attributes->getNamedItem('id')) { |
|
210 | + throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | 214 | * @var DOMAttr $element |
215 | 215 | */ |
216 | - foreach ( $transUnit->attributes as $element ) { |
|
216 | + foreach ($transUnit->attributes as $element) { |
|
217 | 217 | |
218 | - if ( $element->nodeName === "id" ) { |
|
218 | + if ($element->nodeName === "id") { |
|
219 | 219 | |
220 | 220 | $id = $element->nodeValue; |
221 | 221 | |
222 | - if ( strlen( $id ) > 100 ) { |
|
223 | - throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 ); |
|
222 | + if (strlen($id) > 100) { |
|
223 | + throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | $transUnitIdArrayForUniquenessCheck[] = $id; |
227 | - $metadata[ 'id' ] = $id; |
|
227 | + $metadata['id'] = $id; |
|
228 | 228 | |
229 | - } elseif ( $element->nodeName === "approved" ) { |
|
229 | + } elseif ($element->nodeName === "approved") { |
|
230 | 230 | // approved as BOOLEAN |
231 | 231 | // http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#approved |
232 | - $metadata[ $element->nodeName ] = filter_var( $element->nodeValue, FILTER_VALIDATE_BOOLEAN ); |
|
233 | - } elseif ( $element->nodeName === "maxwidth" ) { |
|
232 | + $metadata[$element->nodeName] = filter_var($element->nodeValue, FILTER_VALIDATE_BOOLEAN); |
|
233 | + } elseif ($element->nodeName === "maxwidth") { |
|
234 | 234 | // we ignore ( but we get ) the attribute size-unit="char" assuming that a restriction is everytime done by character |
235 | 235 | // we duplicate the info to allow Xliff V1 and V2 to work the same |
236 | - $metadata[ 'sizeRestriction' ] = filter_var( $element->nodeValue, FILTER_SANITIZE_NUMBER_INT ); |
|
237 | - $metadata[ $element->nodeName ] = filter_var( $element->nodeValue, FILTER_SANITIZE_NUMBER_INT ); |
|
236 | + $metadata['sizeRestriction'] = filter_var($element->nodeValue, FILTER_SANITIZE_NUMBER_INT); |
|
237 | + $metadata[$element->nodeName] = filter_var($element->nodeValue, FILTER_SANITIZE_NUMBER_INT); |
|
238 | 238 | } else { |
239 | - $metadata[ $element->nodeName ] = $element->nodeValue; |
|
239 | + $metadata[$element->nodeName] = $element->nodeValue; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | } |
@@ -250,19 +250,19 @@ discard block |
||
250 | 250 | * @return array |
251 | 251 | * @throws Exception |
252 | 252 | */ |
253 | - private function extractTransUnitNotes( DOMDocument $dom, DOMElement $transUnit ) { |
|
253 | + private function extractTransUnitNotes(DOMDocument $dom, DOMElement $transUnit) { |
|
254 | 254 | $notes = []; |
255 | - foreach ( $transUnit->getElementsByTagName( 'note' ) as $note ) { |
|
255 | + foreach ($transUnit->getElementsByTagName('note') as $note) { |
|
256 | 256 | |
257 | - $noteValue = $this->extractTagContent( $dom, $note ); |
|
257 | + $noteValue = $this->extractTagContent($dom, $note); |
|
258 | 258 | |
259 | - if ( '' !== $noteValue ) { |
|
259 | + if ('' !== $noteValue) { |
|
260 | 260 | |
261 | - $extractedNote = $this->JSONOrRawContentArray( $noteValue ); |
|
261 | + $extractedNote = $this->JSONOrRawContentArray($noteValue); |
|
262 | 262 | |
263 | 263 | // extract all the attributes |
264 | - foreach ( $note->attributes as $attribute ) { |
|
265 | - $extractedNote[ $attribute->name ] = $attribute->value; |
|
264 | + foreach ($note->attributes as $attribute) { |
|
265 | + $extractedNote[$attribute->name] = $attribute->value; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $notes[] = $extractedNote; |
@@ -277,14 +277,14 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @return array |
279 | 279 | */ |
280 | - private function extractTransUnitContextGroup( DOMDocument $dom, DOMElement $contextGroup ) { |
|
280 | + private function extractTransUnitContextGroup(DOMDocument $dom, DOMElement $contextGroup) { |
|
281 | 281 | $cg = []; |
282 | - $cg[ 'attr' ] = $this->extractTagAttributes( $contextGroup ); |
|
282 | + $cg['attr'] = $this->extractTagAttributes($contextGroup); |
|
283 | 283 | |
284 | 284 | /** @var DOMNode $context */ |
285 | - foreach ( $contextGroup->childNodes as $context ) { |
|
286 | - if ( $context->nodeName === 'context' ) { |
|
287 | - $cg[ 'contexts' ][] = $this->extractContent( $dom, $context ); |
|
285 | + foreach ($contextGroup->childNodes as $context) { |
|
286 | + if ($context->nodeName === 'context') { |
|
287 | + $cg['contexts'][] = $this->extractContent($dom, $context); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
@@ -296,16 +296,16 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return array |
298 | 298 | */ |
299 | - private function extractTransUnitAltTrans( DOMElement $altTrans ) { |
|
299 | + private function extractTransUnitAltTrans(DOMElement $altTrans) { |
|
300 | 300 | $at = []; |
301 | - $at[ 'attr' ] = $this->extractTagAttributes( $altTrans ); |
|
301 | + $at['attr'] = $this->extractTagAttributes($altTrans); |
|
302 | 302 | |
303 | - if ( $altTrans->getElementsByTagName( 'source' )->length > 0 ) { |
|
304 | - $at[ 'source' ] = $altTrans->getElementsByTagName( 'source' )->item( 0 )->nodeValue; |
|
303 | + if ($altTrans->getElementsByTagName('source')->length > 0) { |
|
304 | + $at['source'] = $altTrans->getElementsByTagName('source')->item(0)->nodeValue; |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( $altTrans->getElementsByTagName( 'target' ) ) { |
|
308 | - $at[ 'target' ] = $altTrans->getElementsByTagName( 'target' )->item( 0 )->nodeValue; |
|
307 | + if ($altTrans->getElementsByTagName('target')) { |
|
308 | + $at['target'] = $altTrans->getElementsByTagName('target')->item(0)->nodeValue; |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | return $at; |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @return bool |
318 | 318 | */ |
319 | - private function extractLocked( DOMElement $locked ) { |
|
320 | - return null !== $locked->getAttribute( 'locked' ); |
|
319 | + private function extractLocked(DOMElement $locked) { |
|
320 | + return null !== $locked->getAttribute('locked'); |
|
321 | 321 | } |
322 | 322 | } |
@@ -7401,7 +7401,7 @@ |
||
7401 | 7401 | ' |