@@ -7,5 +7,5 @@ |
||
7 | 7 | /** |
8 | 8 | * List of allowed Xliff tags |
9 | 9 | */ |
10 | - public static $tags = [ 'g', 'x', 'bx', 'ex', 'bpt', 'ept', 'ph', 'pc', 'ec', 'sc', 'it', 'mrk' ]; |
|
10 | + public static $tags = ['g', 'x', 'bx', 'ex', 'bpt', 'ept', 'ph', 'pc', 'ec', 'sc', 'it', 'mrk']; |
|
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -53,7 +53,7 @@ |
||
53 | 53 | self::STATUS_REBUTTED |
54 | 54 | ]; |
55 | 55 | |
56 | - public static function isReviewedStatus( $status ) { |
|
57 | - return in_array( $status, TranslationStatus::$REVISION_STATUSES ); |
|
56 | + public static function isReviewedStatus($status) { |
|
57 | + return in_array($status, TranslationStatus::$REVISION_STATUSES); |
|
58 | 58 | } |
59 | 59 | } |
@@ -27,65 +27,65 @@ discard block |
||
27 | 27 | * @throws InvalidXmlException When parsing of XML with schema or callable produces any errors unrelated to the XML parsing itself |
28 | 28 | * @throws RuntimeException When DOM extension is missing |
29 | 29 | */ |
30 | - public static function parse( $content, $schemaOrCallable = null ) { |
|
31 | - if ( !extension_loaded( 'dom' ) ) { |
|
32 | - throw new RuntimeException( 'Extension DOM is required.' ); |
|
30 | + public static function parse($content, $schemaOrCallable = null) { |
|
31 | + if (!extension_loaded('dom')) { |
|
32 | + throw new RuntimeException('Extension DOM is required.'); |
|
33 | 33 | } |
34 | 34 | |
35 | - $internalErrors = libxml_use_internal_errors( true ); |
|
36 | - $disableEntities = libxml_disable_entity_loader( true ); |
|
35 | + $internalErrors = libxml_use_internal_errors(true); |
|
36 | + $disableEntities = libxml_disable_entity_loader(true); |
|
37 | 37 | libxml_clear_errors(); |
38 | 38 | |
39 | - $dom = new DOMDocument( '1.0', 'UTF-8' ); |
|
39 | + $dom = new DOMDocument('1.0', 'UTF-8'); |
|
40 | 40 | $dom->validateOnParse = true; |
41 | - if ( !$dom->loadXML( $content, LIBXML_NONET | ( defined( 'LIBXML_COMPACT' ) ? LIBXML_COMPACT : 0 ) ) ) { |
|
42 | - libxml_disable_entity_loader( $disableEntities ); |
|
41 | + if (!$dom->loadXML($content, LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { |
|
42 | + libxml_disable_entity_loader($disableEntities); |
|
43 | 43 | |
44 | - throw new XmlParsingException( implode( "\n", static::getXmlErrors( $internalErrors ) ) ); |
|
44 | + throw new XmlParsingException(implode("\n", static::getXmlErrors($internalErrors))); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $dom->normalizeDocument(); |
48 | 48 | |
49 | - libxml_use_internal_errors( $internalErrors ); |
|
50 | - libxml_disable_entity_loader( $disableEntities ); |
|
49 | + libxml_use_internal_errors($internalErrors); |
|
50 | + libxml_disable_entity_loader($disableEntities); |
|
51 | 51 | |
52 | - foreach ( $dom->childNodes as $child ) { |
|
53 | - if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) { |
|
54 | - throw new XmlParsingException( 'Document types are not allowed.' ); |
|
52 | + foreach ($dom->childNodes as $child) { |
|
53 | + if (XML_DOCUMENT_TYPE_NODE === $child->nodeType) { |
|
54 | + throw new XmlParsingException('Document types are not allowed.'); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - if ( null !== $schemaOrCallable ) { |
|
59 | - $internalErrors = libxml_use_internal_errors( true ); |
|
58 | + if (null !== $schemaOrCallable) { |
|
59 | + $internalErrors = libxml_use_internal_errors(true); |
|
60 | 60 | libxml_clear_errors(); |
61 | 61 | |
62 | 62 | $e = null; |
63 | - if ( is_callable( $schemaOrCallable ) ) { |
|
63 | + if (is_callable($schemaOrCallable)) { |
|
64 | 64 | try { |
65 | - $valid = call_user_func( $schemaOrCallable, $dom, $internalErrors ); |
|
66 | - } catch ( Exception $e ) { |
|
65 | + $valid = call_user_func($schemaOrCallable, $dom, $internalErrors); |
|
66 | + } catch (Exception $e) { |
|
67 | 67 | $valid = false; |
68 | 68 | } |
69 | - } elseif ( !is_array( $schemaOrCallable ) && is_file( (string)$schemaOrCallable ) ) { |
|
70 | - $schemaSource = file_get_contents( (string)$schemaOrCallable ); |
|
71 | - $valid = @$dom->schemaValidateSource( $schemaSource ); |
|
69 | + } elseif (!is_array($schemaOrCallable) && is_file((string)$schemaOrCallable)) { |
|
70 | + $schemaSource = file_get_contents((string)$schemaOrCallable); |
|
71 | + $valid = @$dom->schemaValidateSource($schemaSource); |
|
72 | 72 | } else { |
73 | - libxml_use_internal_errors( $internalErrors ); |
|
73 | + libxml_use_internal_errors($internalErrors); |
|
74 | 74 | |
75 | - throw new XmlParsingException( 'The schemaOrCallable argument has to be a valid path to XSD file or callable.' ); |
|
75 | + throw new XmlParsingException('The schemaOrCallable argument has to be a valid path to XSD file or callable.'); |
|
76 | 76 | } |
77 | 77 | |
78 | - if ( !$valid ) { |
|
79 | - $messages = static::getXmlErrors( $internalErrors ); |
|
80 | - if ( empty( $messages ) ) { |
|
81 | - throw new InvalidXmlException( 'The XML is not valid.', 0, $e ); |
|
78 | + if (!$valid) { |
|
79 | + $messages = static::getXmlErrors($internalErrors); |
|
80 | + if (empty($messages)) { |
|
81 | + throw new InvalidXmlException('The XML is not valid.', 0, $e); |
|
82 | 82 | } |
83 | - throw new XmlParsingException( implode( "\n", $messages ), 0, $e ); |
|
83 | + throw new XmlParsingException(implode("\n", $messages), 0, $e); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | 87 | libxml_clear_errors(); |
88 | - libxml_use_internal_errors( $internalErrors ); |
|
88 | + libxml_use_internal_errors($internalErrors); |
|
89 | 89 | |
90 | 90 | return $dom; |
91 | 91 | } |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return array |
97 | 97 | */ |
98 | - private static function getXmlErrors( $internalErrors ) { |
|
98 | + private static function getXmlErrors($internalErrors) { |
|
99 | 99 | $errors = []; |
100 | - foreach ( libxml_get_errors() as $error ) { |
|
100 | + foreach (libxml_get_errors() as $error) { |
|
101 | 101 | $errors[] = sprintf( |
102 | 102 | '[%s %s] %s (in %s - line %d, column %d)', |
103 | 103 | LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR', |
104 | 104 | $error->code, |
105 | - trim( $error->message ), |
|
105 | + trim($error->message), |
|
106 | 106 | $error->file ?: 'n/a', |
107 | 107 | $error->line, |
108 | 108 | $error->column |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | libxml_clear_errors(); |
113 | - libxml_use_internal_errors( $internalErrors ); |
|
113 | + libxml_use_internal_errors($internalErrors); |
|
114 | 114 | |
115 | 115 | return $errors; |
116 | 116 | } |
@@ -8,28 +8,28 @@ discard block |
||
8 | 8 | abstract class AbstractXliffReplacer { |
9 | 9 | protected $originalFP; |
10 | 10 | |
11 | - protected $tuTagName; // <trans-unit> (forXliff v 1.*) or <unit> (forXliff v 2.*) |
|
12 | - protected $inTU = false; // flag to check whether we are in a <trans-unit> |
|
13 | - protected $inTarget = false; // flag to check whether we are in a <target>, to ignore everything |
|
14 | - protected $isEmpty = false; // flag to check whether we are in an empty tag (<tag/>) |
|
15 | - protected $targetWasWritten = false; // flag to check is <target> was written in the current unit |
|
16 | - protected $segmentPositionInTu = -1; // the current position of segment in the current <unit> (forXliff v 2.*) |
|
17 | - |
|
18 | - protected $CDATABuffer = ""; // buffer for special tag |
|
19 | - protected $bufferIsActive = false; // buffer for special tag |
|
20 | - |
|
21 | - protected $offset = 0; // offset for SAX pointer |
|
22 | - protected $outputFP; // output stream pointer |
|
23 | - protected $currentBuffer; // the current piece of text it's been parsed |
|
24 | - protected $len; // length of the currentBuffer |
|
25 | - protected $segments; // array of translations |
|
11 | + protected $tuTagName; // <trans-unit> (forXliff v 1.*) or <unit> (forXliff v 2.*) |
|
12 | + protected $inTU = false; // flag to check whether we are in a <trans-unit> |
|
13 | + protected $inTarget = false; // flag to check whether we are in a <target>, to ignore everything |
|
14 | + protected $isEmpty = false; // flag to check whether we are in an empty tag (<tag/>) |
|
15 | + protected $targetWasWritten = false; // flag to check is <target> was written in the current unit |
|
16 | + protected $segmentPositionInTu = -1; // the current position of segment in the current <unit> (forXliff v 2.*) |
|
17 | + |
|
18 | + protected $CDATABuffer = ""; // buffer for special tag |
|
19 | + protected $bufferIsActive = false; // buffer for special tag |
|
20 | + |
|
21 | + protected $offset = 0; // offset for SAX pointer |
|
22 | + protected $outputFP; // output stream pointer |
|
23 | + protected $currentBuffer; // the current piece of text it's been parsed |
|
24 | + protected $len; // length of the currentBuffer |
|
25 | + protected $segments; // array of translations |
|
26 | 26 | protected $lastTransUnit = []; |
27 | - protected $currentTransUnitId; // id of current <trans-unit> |
|
27 | + protected $currentTransUnitId; // id of current <trans-unit> |
|
28 | 28 | protected $currentTransUnitTranslate; // 'translate' attribute of current <trans-unit> |
29 | - protected $currentSegmentArray = []; // id of current <segment> (forXliff v 2.*) |
|
30 | - protected $unitContainsMda = false; // check if <unit> already contains a <mda:metadata> (forXliff v 2.*) |
|
31 | - protected $hasWrittenCounts = false; // check if <unit> already wrote segment counts (forXliff v 2.*) |
|
32 | - protected $sourceAttributes = []; // current <source> attributes (needed when handling xliff files without <target>) |
|
29 | + protected $currentSegmentArray = []; // id of current <segment> (forXliff v 2.*) |
|
30 | + protected $unitContainsMda = false; // check if <unit> already contains a <mda:metadata> (forXliff v 2.*) |
|
31 | + protected $hasWrittenCounts = false; // check if <unit> already wrote segment counts (forXliff v 2.*) |
|
32 | + protected $sourceAttributes = []; // current <source> attributes (needed when handling xliff files without <target>) |
|
33 | 33 | |
34 | 34 | protected $targetLang; |
35 | 35 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | XliffReplacerCallbackInterface $callback = null |
77 | 77 | ) { |
78 | 78 | self::$INTERNAL_TAG_PLACEHOLDER = $this->getInternalTagPlaceholder(); |
79 | - $this->createOutputFileIfDoesNotExist( $outputFilePath ); |
|
80 | - $this->setFileDescriptors( $originalXliffPath, $outputFilePath ); |
|
79 | + $this->createOutputFileIfDoesNotExist($outputFilePath); |
|
80 | + $this->setFileDescriptors($originalXliffPath, $outputFilePath); |
|
81 | 81 | $this->xliffVersion = $xliffVersion; |
82 | 82 | $this->setTuTagName(); |
83 | 83 | $this->segments = $segments; |
@@ -95,19 +95,19 @@ discard block |
||
95 | 95 | return "§" . |
96 | 96 | substr( |
97 | 97 | str_replace( |
98 | - [ '+', '/' ], |
|
98 | + ['+', '/'], |
|
99 | 99 | '', |
100 | - base64_encode( openssl_random_pseudo_bytes( 10, $_crypto_strong ) ) |
|
100 | + base64_encode(openssl_random_pseudo_bytes(10, $_crypto_strong)) |
|
101 | 101 | ), |
102 | 102 | 0, |
103 | 103 | 4 |
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
107 | - private function createOutputFileIfDoesNotExist( $outputFilePath ) { |
|
107 | + private function createOutputFileIfDoesNotExist($outputFilePath) { |
|
108 | 108 | // create output file |
109 | - if ( !file_exists( $outputFilePath ) ) { |
|
110 | - touch( $outputFilePath ); |
|
109 | + if (!file_exists($outputFilePath)) { |
|
110 | + touch($outputFilePath); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | * @param $originalXliffPath |
116 | 116 | * @param $outputFilePath |
117 | 117 | */ |
118 | - private function setFileDescriptors( $originalXliffPath, $outputFilePath ) { |
|
119 | - $this->outputFP = fopen( $outputFilePath, 'w+' ); |
|
118 | + private function setFileDescriptors($originalXliffPath, $outputFilePath) { |
|
119 | + $this->outputFP = fopen($outputFilePath, 'w+'); |
|
120 | 120 | |
121 | 121 | $streamArgs = null; |
122 | 122 | |
123 | - if ( !( $this->originalFP = fopen( $originalXliffPath, "r", false, stream_context_create( $streamArgs ) ) ) ) { |
|
124 | - throw new RuntimeException( "could not open XML input" ); |
|
123 | + if (!($this->originalFP = fopen($originalXliffPath, "r", false, stream_context_create($streamArgs)))) { |
|
124 | + throw new RuntimeException("could not open XML input"); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * <trans-unit> (xliff v1.*) || <unit> (xliff v2.*) |
131 | 131 | */ |
132 | 132 | private function setTuTagName() { |
133 | - $this->tuTagName = ( $this->xliffVersion === 2 ) ? 'unit' : 'trans-unit'; |
|
133 | + $this->tuTagName = ($this->xliffVersion === 2) ? 'unit' : 'trans-unit'; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | public function __destruct() { |
140 | 140 | //this stream can be closed outside the class |
141 | 141 | //to permit multiple concurrent downloads, so suppress warnings |
142 | - @fclose( $this->originalFP ); |
|
143 | - fclose( $this->outputFP ); |
|
142 | + @fclose($this->originalFP); |
|
143 | + fclose($this->outputFP); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | abstract public function replaceTranslation(); |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | * @return resource |
152 | 152 | */ |
153 | 153 | protected function initSaxParser() { |
154 | - $xmlSaxParser = xml_parser_create( 'UTF-8' ); |
|
155 | - xml_set_object( $xmlSaxParser, $this ); |
|
156 | - xml_parser_set_option( $xmlSaxParser, XML_OPTION_CASE_FOLDING, false ); |
|
157 | - xml_set_element_handler( $xmlSaxParser, 'tagOpen', 'tagClose' ); |
|
158 | - xml_set_character_data_handler( $xmlSaxParser, 'characterData' ); |
|
154 | + $xmlSaxParser = xml_parser_create('UTF-8'); |
|
155 | + xml_set_object($xmlSaxParser, $this); |
|
156 | + xml_parser_set_option($xmlSaxParser, XML_OPTION_CASE_FOLDING, false); |
|
157 | + xml_set_element_handler($xmlSaxParser, 'tagOpen', 'tagClose'); |
|
158 | + xml_set_character_data_handler($xmlSaxParser, 'characterData'); |
|
159 | 159 | |
160 | 160 | return $xmlSaxParser; |
161 | 161 | } |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | /** |
164 | 164 | * @param resource $xmlSaxParser |
165 | 165 | */ |
166 | - protected function closeSaxParser( $xmlSaxParser ) { |
|
167 | - xml_parser_free( $xmlSaxParser ); |
|
166 | + protected function closeSaxParser($xmlSaxParser) { |
|
167 | + xml_parser_free($xmlSaxParser); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @return mixed |
176 | 176 | */ |
177 | - abstract protected function tagOpen( $parser, $name, $attr ); |
|
177 | + abstract protected function tagOpen($parser, $name, $attr); |
|
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @param $parser |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return mixed |
184 | 184 | */ |
185 | - abstract protected function tagClose( $parser, $name ); |
|
185 | + abstract protected function tagClose($parser, $name); |
|
186 | 186 | |
187 | 187 | /** |
188 | 188 | * @param $parser |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return mixed |
192 | 192 | */ |
193 | - abstract protected function characterData( $parser, $data ); |
|
193 | + abstract protected function characterData($parser, $data); |
|
194 | 194 | |
195 | 195 | /** |
196 | 196 | * postprocess escaped data and write to disk |
@@ -199,18 +199,18 @@ discard block |
||
199 | 199 | * @param string $data |
200 | 200 | * @param bool $treatAsCDATA |
201 | 201 | */ |
202 | - protected function postProcAndFlush( $fp, $data, $treatAsCDATA = false ) { |
|
202 | + protected function postProcAndFlush($fp, $data, $treatAsCDATA = false) { |
|
203 | 203 | //postprocess string |
204 | - $data = preg_replace( "/" . self::$INTERNAL_TAG_PLACEHOLDER . '(.*?)' . self::$INTERNAL_TAG_PLACEHOLDER . "/", '&$1;', $data ); |
|
205 | - $data = str_replace( ' ', ' ', $data ); |
|
206 | - if ( !$treatAsCDATA ) { |
|
204 | + $data = preg_replace("/" . self::$INTERNAL_TAG_PLACEHOLDER . '(.*?)' . self::$INTERNAL_TAG_PLACEHOLDER . "/", '&$1;', $data); |
|
205 | + $data = str_replace(' ', ' ', $data); |
|
206 | + if (!$treatAsCDATA) { |
|
207 | 207 | //unix2dos |
208 | - $data = str_replace( "\r\n", "\r", $data ); |
|
209 | - $data = str_replace( "\n", "\r", $data ); |
|
210 | - $data = str_replace( "\r", "\r\n", $data ); |
|
208 | + $data = str_replace("\r\n", "\r", $data); |
|
209 | + $data = str_replace("\n", "\r", $data); |
|
210 | + $data = str_replace("\r", "\r\n", $data); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | //flush to disk |
214 | - fwrite( $fp, $data ); |
|
214 | + fwrite($fp, $data); |
|
215 | 215 | } |
216 | 216 | } |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return array|mixed |
20 | 20 | */ |
21 | - public static function pathInfo( $path, $options = 15 ) { |
|
22 | - $rawPath = explode( DIRECTORY_SEPARATOR, $path ); |
|
21 | + public static function pathInfo($path, $options = 15) { |
|
22 | + $rawPath = explode(DIRECTORY_SEPARATOR, $path); |
|
23 | 23 | |
24 | - $basename = array_pop( $rawPath ); |
|
25 | - $dirname = implode( DIRECTORY_SEPARATOR, $rawPath ); |
|
24 | + $basename = array_pop($rawPath); |
|
25 | + $dirname = implode(DIRECTORY_SEPARATOR, $rawPath); |
|
26 | 26 | |
27 | - $explodedFileName = explode( ".", $basename ); |
|
28 | - $extension = strtolower( array_pop( $explodedFileName ) ); |
|
29 | - $filename = implode( ".", $explodedFileName ); |
|
27 | + $explodedFileName = explode(".", $basename); |
|
28 | + $extension = strtolower(array_pop($explodedFileName)); |
|
29 | + $filename = implode(".", $explodedFileName); |
|
30 | 30 | |
31 | 31 | $returnArray = []; |
32 | 32 | |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | |
40 | 40 | // foreach flag, add in $return_array the corresponding field, |
41 | 41 | // obtained by variable name correspondence |
42 | - foreach ( $flagMap as $field => $i ) { |
|
42 | + foreach ($flagMap as $field => $i) { |
|
43 | 43 | //binary AND |
44 | - if ( ( $options & $i ) > 0 ) { |
|
44 | + if (($options & $i) > 0) { |
|
45 | 45 | //variable substitution: $field can be one between 'dirname', 'basename', 'extension', 'filename' |
46 | 46 | // $$field gets the value of the variable named $field |
47 | - $returnArray[ $field ] = $$field; |
|
47 | + $returnArray[$field] = $$field; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | - if ( count( $returnArray ) == 1 ) { |
|
52 | - $returnArray = array_pop( $returnArray ); |
|
51 | + if (count($returnArray) == 1) { |
|
52 | + $returnArray = array_pop($returnArray); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return $returnArray; |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return false|string |
62 | 62 | */ |
63 | - public static function getExtension( $path ) { |
|
64 | - $pathInfo = self::pathInfo( $path ); |
|
63 | + public static function getExtension($path) { |
|
64 | + $pathInfo = self::pathInfo($path); |
|
65 | 65 | |
66 | - if ( empty( $pathInfo ) ) { |
|
66 | + if (empty($pathInfo)) { |
|
67 | 67 | return false; |
68 | 68 | } |
69 | 69 | |
70 | - return strtolower( $pathInfo[ 'extension' ] ); |
|
70 | + return strtolower($pathInfo['extension']); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | - public static function isXliff( $path ) { |
|
79 | - $extension = self::getExtension( $path ); |
|
78 | + public static function isXliff($path) { |
|
79 | + $extension = self::getExtension($path); |
|
80 | 80 | |
81 | - if ( !$extension ) { |
|
81 | + if (!$extension) { |
|
82 | 82 | return false; |
83 | 83 | } |
84 | 84 | |
85 | - switch ( $extension ) { |
|
85 | + switch ($extension) { |
|
86 | 86 | case 'xliff': |
87 | 87 | case 'sdlxliff': |
88 | 88 | case 'tmx': |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @return bool|string |
100 | 100 | */ |
101 | - public static function getMemoryFileType( $path ) { |
|
102 | - $pathInfo = self::pathInfo( $path ); |
|
101 | + public static function getMemoryFileType($path) { |
|
102 | + $pathInfo = self::pathInfo($path); |
|
103 | 103 | |
104 | - if ( empty( $pathInfo ) ) { |
|
104 | + if (empty($pathInfo)) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
108 | - switch ( strtolower( $pathInfo[ 'extension' ] ) ) { |
|
108 | + switch (strtolower($pathInfo['extension'])) { |
|
109 | 109 | case 'tmx': |
110 | 110 | return 'tmx'; |
111 | 111 | case 'g': |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return bool |
122 | 122 | */ |
123 | - public static function isTMXFile( $path ) { |
|
124 | - return self::getMemoryFileType( $path ) === 'tmx'; |
|
123 | + public static function isTMXFile($path) { |
|
124 | + return self::getMemoryFileType($path) === 'tmx'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return bool |
131 | 131 | */ |
132 | - public static function isGlossaryFile( $path ) { |
|
133 | - return self::getMemoryFileType( $path ) === 'glossary'; |
|
132 | + public static function isGlossaryFile($path) { |
|
133 | + return self::getMemoryFileType($path) === 'glossary'; |
|
134 | 134 | } |
135 | 135 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param $tmp |
22 | 22 | */ |
23 | - public function __construct( $tmp ) { |
|
23 | + public function __construct($tmp) { |
|
24 | 24 | $this->tmp = $tmp; |
25 | 25 | $this->steps = []; |
26 | 26 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param CheckInterface $step |
30 | 30 | */ |
31 | - public function addCheck( CheckInterface $step ) { |
|
31 | + public function addCheck(CheckInterface $step) { |
|
32 | 32 | $this->steps[] = $step; |
33 | 33 | } |
34 | 34 | |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | $fileType = []; |
40 | 40 | |
41 | 41 | /** @var CheckInterface $step */ |
42 | - foreach ( $this->steps as $step ) { |
|
43 | - if ( null !== $step->check( $this->tmp ) ) { |
|
44 | - $fileType = $step->check( $this->tmp ); |
|
42 | + foreach ($this->steps as $step) { |
|
43 | + if (null !== $step->check($this->tmp)) { |
|
44 | + $fileType = $step->check($this->tmp); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | - if ( !empty( $fileType ) && $this->isValid( $fileType ) ) { |
|
48 | + if (!empty($fileType) && $this->isValid($fileType)) { |
|
49 | 49 | return $fileType; |
50 | 50 | } |
51 | 51 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return bool |
64 | 64 | */ |
65 | - private function isValid( $fileType ) { |
|
65 | + private function isValid($fileType) { |
|
66 | 66 | $mandatoryKeys = [ |
67 | 67 | 'proprietary', |
68 | 68 | 'proprietary_name', |
@@ -70,6 +70,6 @@ discard block |
||
70 | 70 | 'converter_version', |
71 | 71 | ]; |
72 | 72 | |
73 | - return array_keys( $fileType ) === $mandatoryKeys; |
|
73 | + return array_keys($fileType) === $mandatoryKeys; |
|
74 | 74 | } |
75 | 75 | } |
@@ -22,11 +22,11 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @return array |
24 | 24 | */ |
25 | - public static function getInfoFromXliffContent( $xliffContent ) { |
|
25 | + public static function getInfoFromXliffContent($xliffContent) { |
|
26 | 26 | self::reset(); |
27 | - $tmp = self::getFirst1024CharsFromXliff( $xliffContent, null ); |
|
27 | + $tmp = self::getFirst1024CharsFromXliff($xliffContent, null); |
|
28 | 28 | |
29 | - return self::getInfoFromTmp( $tmp ); |
|
29 | + return self::getInfoFromTmp($tmp); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return array |
36 | 36 | */ |
37 | - public static function getInfo( $fullPathToFile ) { |
|
37 | + public static function getInfo($fullPathToFile) { |
|
38 | 38 | self::reset(); |
39 | - $tmp = self::getFirst1024CharsFromXliff( null, $fullPathToFile ); |
|
40 | - self::$fileType[ 'info' ] = Files::pathInfo( $fullPathToFile ); |
|
39 | + $tmp = self::getFirst1024CharsFromXliff(null, $fullPathToFile); |
|
40 | + self::$fileType['info'] = Files::pathInfo($fullPathToFile); |
|
41 | 41 | |
42 | - return self::getInfoFromTmp( $tmp ); |
|
42 | + return self::getInfoFromTmp($tmp); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -47,21 +47,21 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return array |
49 | 49 | */ |
50 | - private static function getInfoFromTmp( $tmp ) { |
|
50 | + private static function getInfoFromTmp($tmp) { |
|
51 | 51 | try { |
52 | - self::checkVersion( $tmp ); |
|
53 | - } catch ( Exception $ignore ) { |
|
52 | + self::checkVersion($tmp); |
|
53 | + } catch (Exception $ignore) { |
|
54 | 54 | // do nothing |
55 | 55 | // self::$fileType[ 'version' ] is left empty |
56 | 56 | } |
57 | 57 | |
58 | 58 | // run CheckXliffProprietaryPipeline |
59 | - $pipeline = self::runPipeline( $tmp ); |
|
59 | + $pipeline = self::runPipeline($tmp); |
|
60 | 60 | |
61 | - self::$fileType[ 'proprietary' ] = $pipeline[ 'proprietary' ]; |
|
62 | - self::$fileType[ 'proprietary_name' ] = $pipeline[ 'proprietary_name' ]; |
|
63 | - self::$fileType[ 'proprietary_short_name' ] = $pipeline[ 'proprietary_short_name' ]; |
|
64 | - self::$fileType[ 'converter_version' ] = $pipeline[ 'converter_version' ]; |
|
61 | + self::$fileType['proprietary'] = $pipeline['proprietary']; |
|
62 | + self::$fileType['proprietary_name'] = $pipeline['proprietary_name']; |
|
63 | + self::$fileType['proprietary_short_name'] = $pipeline['proprietary_short_name']; |
|
64 | + self::$fileType['converter_version'] = $pipeline['converter_version']; |
|
65 | 65 | |
66 | 66 | return self::$fileType; |
67 | 67 | } |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return array |
73 | 73 | */ |
74 | - private static function runPipeline( $tmp ) { |
|
75 | - $pipeline = new CheckXliffProprietaryPipeline( $tmp ); |
|
76 | - $pipeline->addCheck( new CheckSDL() ); |
|
77 | - $pipeline->addCheck( new CheckGlobalSight() ); |
|
78 | - $pipeline->addCheck( new CheckMateCATConverter() ); |
|
79 | - $pipeline->addCheck( new CheckXliffVersion2() ); |
|
74 | + private static function runPipeline($tmp) { |
|
75 | + $pipeline = new CheckXliffProprietaryPipeline($tmp); |
|
76 | + $pipeline->addCheck(new CheckSDL()); |
|
77 | + $pipeline->addCheck(new CheckGlobalSight()); |
|
78 | + $pipeline->addCheck(new CheckMateCATConverter()); |
|
79 | + $pipeline->addCheck(new CheckXliffVersion2()); |
|
80 | 80 | |
81 | 81 | return $pipeline->run(); |
82 | 82 | } |
@@ -99,29 +99,29 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return array|false |
101 | 101 | */ |
102 | - private static function getFirst1024CharsFromXliff( $stringData = null, $fullPathToFile = null ) { |
|
103 | - if ( !empty( $stringData ) && empty( $fullPathToFile ) ) { |
|
102 | + private static function getFirst1024CharsFromXliff($stringData = null, $fullPathToFile = null) { |
|
103 | + if (!empty($stringData) && empty($fullPathToFile)) { |
|
104 | 104 | $pathInfo = []; |
105 | - $stringData = substr( $stringData, 0, 1024 ); |
|
106 | - } elseif ( empty( $stringData ) && !empty( $fullPathToFile ) ) { |
|
107 | - $pathInfo = Files::pathInfo( $fullPathToFile ); |
|
105 | + $stringData = substr($stringData, 0, 1024); |
|
106 | + } elseif (empty($stringData) && !empty($fullPathToFile)) { |
|
107 | + $pathInfo = Files::pathInfo($fullPathToFile); |
|
108 | 108 | |
109 | - if ( is_file( $fullPathToFile ) ) { |
|
110 | - $file_pointer = fopen( "$fullPathToFile", 'r' ); |
|
109 | + if (is_file($fullPathToFile)) { |
|
110 | + $file_pointer = fopen("$fullPathToFile", 'r'); |
|
111 | 111 | // Checking Requirements (By specs, I know that xliff version is in the first 1KB) |
112 | - $stringData = fread( $file_pointer, 1024 ); |
|
113 | - fclose( $file_pointer ); |
|
112 | + $stringData = fread($file_pointer, 1024); |
|
113 | + fclose($file_pointer); |
|
114 | 114 | } |
115 | - } elseif ( !empty( $stringData ) && !empty( $fullPathToFile ) ) { |
|
116 | - $pathInfo = Files::pathInfo( $fullPathToFile ); |
|
115 | + } elseif (!empty($stringData) && !empty($fullPathToFile)) { |
|
116 | + $pathInfo = Files::pathInfo($fullPathToFile); |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( !empty( $pathInfo ) && !Files::isXliff( $fullPathToFile ) ) { |
|
119 | + if (!empty($pathInfo) && !Files::isXliff($fullPathToFile)) { |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | |
123 | - if ( !empty( $stringData ) ) { |
|
124 | - return [ $stringData ]; |
|
123 | + if (!empty($stringData)) { |
|
124 | + return [$stringData]; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | return false; |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | * @throws NotSupportedVersionException |
134 | 134 | * @throws NotValidFileException |
135 | 135 | */ |
136 | - protected static function checkVersion( $tmp ) { |
|
137 | - if ( isset( $tmp[ 0 ] ) ) { |
|
138 | - self::$fileType[ 'version' ] = XliffVersionDetector::detect( $tmp[ 0 ] ); |
|
136 | + protected static function checkVersion($tmp) { |
|
137 | + if (isset($tmp[0])) { |
|
138 | + self::$fileType['version'] = XliffVersionDetector::detect($tmp[0]); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
@@ -146,20 +146,20 @@ discard block |
||
146 | 146 | * @throws NotSupportedVersionException |
147 | 147 | * @throws NotValidFileException |
148 | 148 | */ |
149 | - public static function getInfoByStringData( $stringData ) { |
|
149 | + public static function getInfoByStringData($stringData) { |
|
150 | 150 | self::reset(); |
151 | 151 | |
152 | - $tmp = self::getFirst1024CharsFromXliff( $stringData ); |
|
153 | - self::$fileType[ 'info' ] = []; |
|
154 | - self::checkVersion( $tmp ); |
|
152 | + $tmp = self::getFirst1024CharsFromXliff($stringData); |
|
153 | + self::$fileType['info'] = []; |
|
154 | + self::checkVersion($tmp); |
|
155 | 155 | |
156 | 156 | // run CheckXliffProprietaryPipeline |
157 | - $pipeline = self::runPipeline( $tmp ); |
|
157 | + $pipeline = self::runPipeline($tmp); |
|
158 | 158 | |
159 | - self::$fileType[ 'proprietary' ] = $pipeline[ 'proprietary' ]; |
|
160 | - self::$fileType[ 'proprietary_name' ] = $pipeline[ 'proprietary_name' ]; |
|
161 | - self::$fileType[ 'proprietary_short_name' ] = $pipeline[ 'proprietary_short_name' ]; |
|
162 | - self::$fileType[ 'converter_version' ] = $pipeline[ 'converter_version' ]; |
|
159 | + self::$fileType['proprietary'] = $pipeline['proprietary']; |
|
160 | + self::$fileType['proprietary_name'] = $pipeline['proprietary_name']; |
|
161 | + self::$fileType['proprietary_short_name'] = $pipeline['proprietary_short_name']; |
|
162 | + self::$fileType['converter_version'] = $pipeline['converter_version']; |
|
163 | 163 | |
164 | 164 | return self::$fileType; |
165 | 165 | } |
@@ -171,21 +171,21 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return bool|int |
173 | 173 | */ |
174 | - public static function fileMustBeConverted( $fullPath, $enforceOnXliff = false, $filterAddress = null ) { |
|
174 | + public static function fileMustBeConverted($fullPath, $enforceOnXliff = false, $filterAddress = null) { |
|
175 | 175 | $convert = true; |
176 | 176 | |
177 | - $fileType = self::getInfo( $fullPath ); |
|
178 | - $memoryFileType = Files::getMemoryFileType( $fullPath ); |
|
177 | + $fileType = self::getInfo($fullPath); |
|
178 | + $memoryFileType = Files::getMemoryFileType($fullPath); |
|
179 | 179 | |
180 | - if ( Files::isXliff( $fullPath ) || $memoryFileType ) { |
|
181 | - if ( !empty( $filterAddress ) ) { |
|
180 | + if (Files::isXliff($fullPath) || $memoryFileType) { |
|
181 | + if (!empty($filterAddress)) { |
|
182 | 182 | |
183 | 183 | //conversion enforce |
184 | - if ( !$enforceOnXliff ) { |
|
184 | + if (!$enforceOnXliff) { |
|
185 | 185 | |
186 | 186 | //if file is not proprietary AND Enforce is disabled |
187 | 187 | //we take it as is |
188 | - if ( !$fileType[ 'proprietary' ] || $memoryFileType ) { |
|
188 | + if (!$fileType['proprietary'] || $memoryFileType) { |
|
189 | 189 | $convert = false; |
190 | 190 | //ok don't convert a standard sdlxliff |
191 | 191 | } |
@@ -193,16 +193,16 @@ discard block |
||
193 | 193 | //if conversion enforce is active |
194 | 194 | //we force all xliff files but not files produced by SDL Studio because we can handle them |
195 | 195 | if ( |
196 | - $fileType[ 'proprietary_short_name' ] == 'matecat_converter' |
|
197 | - || $fileType[ 'proprietary_short_name' ] == 'trados' |
|
198 | - || $fileType[ 'proprietary_short_name' ] == 'xliff_v2' |
|
196 | + $fileType['proprietary_short_name'] == 'matecat_converter' |
|
197 | + || $fileType['proprietary_short_name'] == 'trados' |
|
198 | + || $fileType['proprietary_short_name'] == 'xliff_v2' |
|
199 | 199 | || $memoryFileType |
200 | 200 | ) { |
201 | 201 | $convert = false; |
202 | 202 | //ok don't convert a standard sdlxliff |
203 | 203 | } |
204 | 204 | } |
205 | - } elseif ( $fileType[ 'proprietary' ] ) { |
|
205 | + } elseif ($fileType['proprietary']) { |
|
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Application misconfiguration. |
@@ -8,15 +8,15 @@ |
||
8 | 8 | * |
9 | 9 | * @return array|null |
10 | 10 | */ |
11 | - public function check( $tmp ) { |
|
11 | + public function check($tmp) { |
|
12 | 12 | $fileType = []; |
13 | 13 | |
14 | - if ( isset( $tmp[ 0 ] ) ) { |
|
15 | - if ( stripos( $tmp[ 0 ], 'globalsight' ) !== false ) { |
|
16 | - $fileType[ 'proprietary' ] = true; |
|
17 | - $fileType[ 'proprietary_name' ] = 'GlobalSight Download File'; |
|
18 | - $fileType[ 'proprietary_short_name' ] = 'globalsight'; |
|
19 | - $fileType[ 'converter_version' ] = 'legacy'; |
|
14 | + if (isset($tmp[0])) { |
|
15 | + if (stripos($tmp[0], 'globalsight') !== false) { |
|
16 | + $fileType['proprietary'] = true; |
|
17 | + $fileType['proprietary_name'] = 'GlobalSight Download File'; |
|
18 | + $fileType['proprietary_short_name'] = 'globalsight'; |
|
19 | + $fileType['converter_version'] = 'legacy'; |
|
20 | 20 | |
21 | 21 | return $fileType; |
22 | 22 | } |
@@ -8,22 +8,22 @@ |
||
8 | 8 | * |
9 | 9 | * @return array|void|null |
10 | 10 | */ |
11 | - public function check( $tmp ) { |
|
11 | + public function check($tmp) { |
|
12 | 12 | $fileType = []; |
13 | 13 | |
14 | - if ( isset( $tmp[ 0 ] ) ) { |
|
15 | - preg_match( '|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr( $tmp[ 0 ], 0, 1000 ), $versionMatches ); |
|
16 | - preg_match( '|<xliff.*?\sxmlns\s?=\s?["\']urn:oasis:names:tc:xliff:document:(.*?)["\']|si', substr( $tmp[ 0 ], 0, 1000 ), $xmlnsMatches ); |
|
14 | + if (isset($tmp[0])) { |
|
15 | + preg_match('|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr($tmp[0], 0, 1000), $versionMatches); |
|
16 | + preg_match('|<xliff.*?\sxmlns\s?=\s?["\']urn:oasis:names:tc:xliff:document:(.*?)["\']|si', substr($tmp[0], 0, 1000), $xmlnsMatches); |
|
17 | 17 | |
18 | - if ( !empty( $versionMatches ) && !empty( $xmlnsMatches ) ) { |
|
19 | - $version = $versionMatches[ 1 ]; |
|
20 | - $xmlns = $xmlnsMatches[ 1 ]; |
|
18 | + if (!empty($versionMatches) && !empty($xmlnsMatches)) { |
|
19 | + $version = $versionMatches[1]; |
|
20 | + $xmlns = $xmlnsMatches[1]; |
|
21 | 21 | |
22 | - if ( $version === $xmlns && $version >= 2 ) { |
|
23 | - $fileType[ 'proprietary' ] = false; |
|
24 | - $fileType[ 'proprietary_name' ] = 'Xliff v' . $version . ' File'; |
|
25 | - $fileType[ 'proprietary_short_name' ] = 'xliff_v2'; |
|
26 | - $fileType[ 'converter_version' ] = '2.0'; |
|
22 | + if ($version === $xmlns && $version >= 2) { |
|
23 | + $fileType['proprietary'] = false; |
|
24 | + $fileType['proprietary_name'] = 'Xliff v' . $version . ' File'; |
|
25 | + $fileType['proprietary_short_name'] = 'xliff_v2'; |
|
26 | + $fileType['converter_version'] = '2.0'; |
|
27 | 27 | |
28 | 28 | return $fileType; |
29 | 29 | } |