@@ -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 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param string|null $xliffProprietary |
| 35 | 35 | * @param LoggerInterface|null $logger |
| 36 | 36 | */ |
| 37 | - public function __construct( $xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null ) { |
|
| 37 | + public function __construct($xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null) { |
|
| 38 | 38 | $this->xliffVersion = $xliffVersion; |
| 39 | 39 | $this->logger = $logger; |
| 40 | 40 | $this->xliffProprietary = $xliffProprietary; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | 46 | protected function getTuTagName() { |
| 47 | - return ( $this->xliffVersion === 1 ) ? 'trans-unit' : 'unit'; |
|
| 47 | + return ($this->xliffVersion === 1) ? 'trans-unit' : 'unit'; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - abstract public function parse( DOMDocument $dom, $output = [] ); |
|
| 55 | + abstract public function parse(DOMDocument $dom, $output = []); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Extract trans-unit content from the current node |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * @param $i |
| 65 | 65 | * @param $j |
| 66 | 66 | */ |
| 67 | - protected function extractTuFromNode( $childNode, &$transUnitIdArrayForUniquenessCheck, DOMDocument $dom, &$output, &$i, &$j ) { |
|
| 68 | - if ( $childNode->nodeName === 'group' ) { |
|
| 69 | - foreach ( $childNode->childNodes as $nestedChildNode ) { |
|
| 70 | - if ( $nestedChildNode->nodeName === 'group' ) { |
|
| 71 | - $this->extractTuFromNode( $nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j ); |
|
| 72 | - } elseif ( $nestedChildNode->nodeName === $this->getTuTagName() ) { |
|
| 73 | - $this->extractTransUnit( $nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j ); |
|
| 67 | + protected function extractTuFromNode($childNode, &$transUnitIdArrayForUniquenessCheck, DOMDocument $dom, &$output, &$i, &$j) { |
|
| 68 | + if ($childNode->nodeName === 'group') { |
|
| 69 | + foreach ($childNode->childNodes as $nestedChildNode) { |
|
| 70 | + if ($nestedChildNode->nodeName === 'group') { |
|
| 71 | + $this->extractTuFromNode($nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j); |
|
| 72 | + } elseif ($nestedChildNode->nodeName === $this->getTuTagName()) { |
|
| 73 | + $this->extractTransUnit($nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | - } elseif ( $childNode->nodeName === $this->getTuTagName() ) { |
|
| 77 | - $this->extractTransUnit( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j ); |
|
| 76 | + } elseif ($childNode->nodeName === $this->getTuTagName()) { |
|
| 77 | + $this->extractTransUnit($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return mixed |
| 92 | 92 | */ |
| 93 | - abstract protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j ); |
|
| 93 | + abstract protected function extractTransUnit($transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j); |
|
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * @param DOMDocument $dom |
@@ -98,10 +98,10 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @return array |
| 100 | 100 | */ |
| 101 | - protected function extractContent( DOMDocument $dom, DOMNode $node ) { |
|
| 101 | + protected function extractContent(DOMDocument $dom, DOMNode $node) { |
|
| 102 | 102 | return [ |
| 103 | - 'raw-content' => $this->extractTagContent( $dom, $node ), |
|
| 104 | - 'attr' => $this->extractTagAttributes( $node ) |
|
| 103 | + 'raw-content' => $this->extractTagContent($dom, $node), |
|
| 104 | + 'attr' => $this->extractTagAttributes($node) |
|
| 105 | 105 | ]; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return array |
| 120 | 120 | */ |
| 121 | - protected function extractTagAttributes( DOMNode $element ) { |
|
| 121 | + protected function extractTagAttributes(DOMNode $element) { |
|
| 122 | 122 | $tagAttributes = []; |
| 123 | 123 | |
| 124 | - if ( $element->hasAttributes() ) { |
|
| 125 | - foreach ( $element->attributes as $attr ) { |
|
| 126 | - $tagAttributes[ $attr->nodeName ] = $attr->nodeValue; |
|
| 124 | + if ($element->hasAttributes()) { |
|
| 125 | + foreach ($element->attributes as $attr) { |
|
| 126 | + $tagAttributes[$attr->nodeName] = $attr->nodeValue; |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
@@ -138,17 +138,17 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | - protected function extractTagContent( DOMDocument $dom, DOMNode $element ) { |
|
| 141 | + protected function extractTagContent(DOMDocument $dom, DOMNode $element) { |
|
| 142 | 142 | $childNodes = $element->hasChildNodes(); |
| 143 | 143 | $extractedContent = ''; |
| 144 | 144 | |
| 145 | - if ( !empty( $childNodes ) ) { |
|
| 146 | - foreach ( $element->childNodes as $node ) { |
|
| 147 | - $extractedContent .= Emoji::toEntity( Strings::fixNonWellFormedXml( $dom->saveXML( $node ) ) ); |
|
| 145 | + if (!empty($childNodes)) { |
|
| 146 | + foreach ($element->childNodes as $node) { |
|
| 147 | + $extractedContent .= Emoji::toEntity(Strings::fixNonWellFormedXml($dom->saveXML($node))); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - return str_replace( Placeholder::EMPTY_TAG_PLACEHOLDER, '', $extractedContent ); |
|
| 151 | + return str_replace(Placeholder::EMPTY_TAG_PLACEHOLDER, '', $extractedContent); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -161,50 +161,50 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @return array |
| 163 | 163 | */ |
| 164 | - protected function extractContentWithMarksAndExtTags( DOMDocument $dom, DOMElement $childNode, $originalRawContent, array $originalData = [] ) { |
|
| 164 | + protected function extractContentWithMarksAndExtTags(DOMDocument $dom, DOMElement $childNode, $originalRawContent, array $originalData = []) { |
|
| 165 | 165 | $source = []; |
| 166 | 166 | |
| 167 | 167 | // example: |
| 168 | 168 | // <g id="1"><mrk mid="0" mtype="seg">An English string with g tags</mrk></g> |
| 169 | - $raw = $this->extractTagContent( $dom, $childNode ); |
|
| 169 | + $raw = $this->extractTagContent($dom, $childNode); |
|
| 170 | 170 | |
| 171 | - $markers = preg_split( '#<mrk\s#si', $raw, -1 ); |
|
| 171 | + $markers = preg_split('#<mrk\s#si', $raw, -1); |
|
| 172 | 172 | |
| 173 | 173 | $mi = 0; |
| 174 | - while ( isset( $markers[ $mi + 1 ] ) ) { |
|
| 175 | - unset( $mid ); |
|
| 174 | + while (isset($markers[$mi + 1])) { |
|
| 175 | + unset($mid); |
|
| 176 | 176 | |
| 177 | - preg_match( '|mid\s?=\s?["\'](.*?)["\']|si', $markers[ $mi + 1 ], $mid ); |
|
| 177 | + preg_match('|mid\s?=\s?["\'](.*?)["\']|si', $markers[$mi + 1], $mid); |
|
| 178 | 178 | |
| 179 | 179 | // if it's a Trados file the trailing spaces after </mrk> are meaningful |
| 180 | 180 | // so we add them to |
| 181 | 181 | $trailingSpaces = ''; |
| 182 | - if ( $this->xliffProprietary === 'trados' ) { |
|
| 183 | - preg_match_all( '/<\/mrk>[\s]+/iu', $markers[ $mi + 1 ], $trailingSpacesMatches ); |
|
| 182 | + if ($this->xliffProprietary === 'trados') { |
|
| 183 | + preg_match_all('/<\/mrk>[\s]+/iu', $markers[$mi + 1], $trailingSpacesMatches); |
|
| 184 | 184 | |
| 185 | - if ( isset( $trailingSpacesMatches[ 0 ] ) && count( $trailingSpacesMatches[ 0 ] ) > 0 ) { |
|
| 186 | - foreach ( $trailingSpacesMatches[ 0 ] as $match ) { |
|
| 187 | - $trailingSpaces = str_replace( '</mrk>', '', $match ); |
|
| 185 | + if (isset($trailingSpacesMatches[0]) && count($trailingSpacesMatches[0]) > 0) { |
|
| 186 | + foreach ($trailingSpacesMatches[0] as $match) { |
|
| 187 | + $trailingSpaces = str_replace('</mrk>', '', $match); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | //re-build the mrk tag after the split |
| 193 | - $originalMark = trim( '<mrk ' . $markers[ $mi + 1 ] ); |
|
| 193 | + $originalMark = trim('<mrk ' . $markers[$mi + 1]); |
|
| 194 | 194 | |
| 195 | - $mark_string = preg_replace( '#^<mrk\s[^>]+>(.*)#', '$1', $originalMark ); // at this point we have: ---> 'Test </mrk> </g>>' |
|
| 196 | - $mark_content = preg_split( '#</mrk>#si', $mark_string ); |
|
| 195 | + $mark_string = preg_replace('#^<mrk\s[^>]+>(.*)#', '$1', $originalMark); // at this point we have: ---> 'Test </mrk> </g>>' |
|
| 196 | + $mark_content = preg_split('#</mrk>#si', $mark_string); |
|
| 197 | 197 | |
| 198 | 198 | $sourceArray = [ |
| 199 | - 'mid' => ( isset( $mid[ 1 ] ) ) ? $mid[ 1 ] : $mi, |
|
| 200 | - 'ext-prec-tags' => ( $mi == 0 ? $markers[ 0 ] : "" ), |
|
| 201 | - 'raw-content' => ( isset( $mark_content[ 0 ] ) ) ? $mark_content[ 0 ] . $trailingSpaces : '', |
|
| 202 | - 'ext-succ-tags' => ( isset( $mark_content[ 1 ] ) ) ? $mark_content[ 1 ] : '', |
|
| 199 | + 'mid' => (isset($mid[1])) ? $mid[1] : $mi, |
|
| 200 | + 'ext-prec-tags' => ($mi == 0 ? $markers[0] : ""), |
|
| 201 | + 'raw-content' => (isset($mark_content[0])) ? $mark_content[0] . $trailingSpaces : '', |
|
| 202 | + 'ext-succ-tags' => (isset($mark_content[1])) ? $mark_content[1] : '', |
|
| 203 | 203 | ]; |
| 204 | 204 | |
| 205 | - if ( !empty( $originalData ) ) { |
|
| 206 | - $dataRefMap = $this->getDataRefMap( $originalData ); |
|
| 207 | - $sourceArray[ 'replaced-content' ] = ( new DataRefReplacer( $dataRefMap ) )->replace( $mark_content[ 0 ] ); |
|
| 205 | + if (!empty($originalData)) { |
|
| 206 | + $dataRefMap = $this->getDataRefMap($originalData); |
|
| 207 | + $sourceArray['replaced-content'] = (new DataRefReplacer($dataRefMap))->replace($mark_content[0]); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | $source[] = $sourceArray; |
@@ -220,12 +220,12 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @return array |
| 222 | 222 | */ |
| 223 | - protected function getDataRefMap( $originalData ) { |
|
| 223 | + protected function getDataRefMap($originalData) { |
|
| 224 | 224 | // dataRef map |
| 225 | 225 | $dataRefMap = []; |
| 226 | - foreach ( $originalData as $datum ) { |
|
| 227 | - if ( isset( $datum[ 'attr' ][ 'id' ] ) ) { |
|
| 228 | - $dataRefMap[ $datum[ 'attr' ][ 'id' ] ] = $datum[ 'raw-content' ]; |
|
| 226 | + foreach ($originalData as $datum) { |
|
| 227 | + if (isset($datum['attr']['id'])) { |
|
| 228 | + $dataRefMap[$datum['attr']['id']] = $datum['raw-content']; |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
@@ -237,10 +237,10 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return bool |
| 239 | 239 | */ |
| 240 | - protected function stringContainsMarks( $raw ) { |
|
| 241 | - $markers = preg_split( '#<mrk\s#si', $raw, -1 ); |
|
| 240 | + protected function stringContainsMarks($raw) { |
|
| 241 | + $markers = preg_split('#<mrk\s#si', $raw, -1); |
|
| 242 | 242 | |
| 243 | - return isset( $markers[ 1 ] ); |
|
| 243 | + return isset($markers[1]); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | * @throws \Exception |
| 252 | 252 | */ |
| 253 | - protected function JSONOrRawContentArray( $noteValue, $escapeStrings = true ) { |
|
| 253 | + protected function JSONOrRawContentArray($noteValue, $escapeStrings = true) { |
|
| 254 | 254 | // |
| 255 | 255 | // convert double escaped entites |
| 256 | 256 | // |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | // &amp; ---> & |
| 261 | 261 | // &apos ---> ' |
| 262 | 262 | // |
| 263 | - if ( Strings::isADoubleEscapedEntity( $noteValue ) ) { |
|
| 264 | - $noteValue = Strings::htmlspecialchars_decode( $noteValue, true ); |
|
| 263 | + if (Strings::isADoubleEscapedEntity($noteValue)) { |
|
| 264 | + $noteValue = Strings::htmlspecialchars_decode($noteValue, true); |
|
| 265 | 265 | } else { |
| 266 | 266 | // for non escaped entities $escapeStrings is always true for security reasons |
| 267 | 267 | $escapeStrings = true; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - if ( Strings::isJSON( $noteValue ) ) { |
|
| 271 | - return [ 'json' => Strings::cleanCDATA( $noteValue ) ]; |
|
| 270 | + if (Strings::isJSON($noteValue)) { |
|
| 271 | + return ['json' => Strings::cleanCDATA($noteValue)]; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - return [ 'raw-content' => Strings::fixNonWellFormedXml( $noteValue, $escapeStrings ) ]; |
|
| 274 | + return ['raw-content' => Strings::fixNonWellFormedXml($noteValue, $escapeStrings)]; |
|
| 275 | 275 | } |
| 276 | 276 | } |
@@ -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 | } |
@@ -15,17 +15,17 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return array |
| 17 | 17 | */ |
| 18 | - public static function parse( $html ) { |
|
| 19 | - $toBeEscaped = Strings::isAnEscapedHTML( $html ); |
|
| 18 | + public static function parse($html) { |
|
| 19 | + $toBeEscaped = Strings::isAnEscapedHTML($html); |
|
| 20 | 20 | |
| 21 | - if ( $toBeEscaped ) { |
|
| 22 | - $html = Strings::htmlspecialchars_decode( $html ); |
|
| 21 | + if ($toBeEscaped) { |
|
| 22 | + $html = Strings::htmlspecialchars_decode($html); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - $html = self::protectNotClosedHtmlTags( $html ); |
|
| 26 | - $html = self::protectNotHtmlLessThanSymbols( $html ); |
|
| 25 | + $html = self::protectNotClosedHtmlTags($html); |
|
| 26 | + $html = self::protectNotHtmlLessThanSymbols($html); |
|
| 27 | 27 | |
| 28 | - return self::extractHtmlNode( $html, $toBeEscaped ); |
|
| 28 | + return self::extractHtmlNode($html, $toBeEscaped); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -43,41 +43,41 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - private static function protectNotHtmlLessThanSymbols( $html ) { |
|
| 47 | - preg_match_all( '/<|>/iu', $html, $matches, PREG_OFFSET_CAPTURE ); |
|
| 46 | + private static function protectNotHtmlLessThanSymbols($html) { |
|
| 47 | + preg_match_all('/<|>/iu', $html, $matches, PREG_OFFSET_CAPTURE); |
|
| 48 | 48 | |
| 49 | 49 | $delta = 0; |
| 50 | 50 | $realNextOffset = 0; |
| 51 | 51 | $next = null; |
| 52 | 52 | |
| 53 | - foreach ( $matches[ 0 ] as $key => $match ) { |
|
| 53 | + foreach ($matches[0] as $key => $match) { |
|
| 54 | 54 | |
| 55 | - $current = $matches[ 0 ][ $key ][ 0 ]; |
|
| 55 | + $current = $matches[0][$key][0]; |
|
| 56 | 56 | |
| 57 | - if ( isset( $matches[ 0 ][ $key + 1 ][ 0 ] ) ) { |
|
| 58 | - $next = $matches[ 0 ][ $key + 1 ][ 0 ]; |
|
| 59 | - $nextOffset = $matches[ 0 ][ $key + 1 ][ 1 ]; |
|
| 60 | - $realNextOffset = ( $delta === 0 ) ? $nextOffset : ( $nextOffset + $delta ); |
|
| 57 | + if (isset($matches[0][$key + 1][0])) { |
|
| 58 | + $next = $matches[0][$key + 1][0]; |
|
| 59 | + $nextOffset = $matches[0][$key + 1][1]; |
|
| 60 | + $realNextOffset = ($delta === 0) ? $nextOffset : ($nextOffset + $delta); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $length = strlen( $match[ 0 ] ); |
|
| 64 | - $offset = $matches[ 0 ][ $key ][ 1 ]; |
|
| 65 | - $realOffset = ( $delta === 0 ) ? $offset : ( $offset + $delta ); |
|
| 63 | + $length = strlen($match[0]); |
|
| 64 | + $offset = $matches[0][$key][1]; |
|
| 65 | + $realOffset = ($delta === 0) ? $offset : ($offset + $delta); |
|
| 66 | 66 | |
| 67 | - if ( $current === '<' && isset( $next ) ) { |
|
| 67 | + if ($current === '<' && isset($next)) { |
|
| 68 | 68 | |
| 69 | 69 | // 1. if next is > or |
| 70 | 70 | // 2. next is < and is not html tag (like < >) |
| 71 | - $insideAngularTags = substr( $html, $realOffset, ( $realNextOffset - $realOffset + 1 ) ); |
|
| 71 | + $insideAngularTags = substr($html, $realOffset, ($realNextOffset - $realOffset + 1)); |
|
| 72 | 72 | |
| 73 | - if ( $next !== '>' || !Strings::isHtmlString( $insideAngularTags ) ) { |
|
| 74 | - $html = substr_replace( $html, self::LT_PLACEHOLDER, $realOffset, $length ); |
|
| 75 | - $delta = $delta + strlen( self::LT_PLACEHOLDER ) - $length; |
|
| 73 | + if ($next !== '>' || !Strings::isHtmlString($insideAngularTags)) { |
|
| 74 | + $html = substr_replace($html, self::LT_PLACEHOLDER, $realOffset, $length); |
|
| 75 | + $delta = $delta + strlen(self::LT_PLACEHOLDER) - $length; |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - return !is_array( $html ) ? $html : implode( $html ); |
|
| 80 | + return !is_array($html) ? $html : implode($html); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -95,29 +95,29 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | - private static function protectNotClosedHtmlTags( $html ) { |
|
| 99 | - preg_match_all( '/<|>/iu', $html, $matches, PREG_OFFSET_CAPTURE ); |
|
| 98 | + private static function protectNotClosedHtmlTags($html) { |
|
| 99 | + preg_match_all('/<|>/iu', $html, $matches, PREG_OFFSET_CAPTURE); |
|
| 100 | 100 | |
| 101 | 101 | $tags = []; |
| 102 | 102 | $offsets = []; |
| 103 | 103 | $originalLengths = []; |
| 104 | 104 | |
| 105 | 105 | // 1. Map all tags |
| 106 | - foreach ( $matches[ 0 ] as $key => $match ) { |
|
| 107 | - $current = $matches[ 0 ][ $key ][ 0 ]; |
|
| 108 | - $currentOffset = $matches[ 0 ][ $key ][ 1 ]; |
|
| 106 | + foreach ($matches[0] as $key => $match) { |
|
| 107 | + $current = $matches[0][$key][0]; |
|
| 108 | + $currentOffset = $matches[0][$key][1]; |
|
| 109 | 109 | |
| 110 | 110 | // check every string inside angular brackets (< and >) |
| 111 | - if ( $current === '<' && isset( $matches[ 0 ][ $key + 1 ][ 0 ] ) && $matches[ 0 ][ $key + 1 ][ 0 ] === '>' ) { |
|
| 112 | - $nextOffset = $matches[ 0 ][ $key + 1 ][ 1 ]; |
|
| 113 | - $tag = substr( $html, ( $currentOffset + 1 ), ( $nextOffset - $currentOffset - 1 ) ); |
|
| 114 | - $trimmedTag = trim( $tag ); |
|
| 111 | + if ($current === '<' && isset($matches[0][$key + 1][0]) && $matches[0][$key + 1][0] === '>') { |
|
| 112 | + $nextOffset = $matches[0][$key + 1][1]; |
|
| 113 | + $tag = substr($html, ($currentOffset + 1), ($nextOffset - $currentOffset - 1)); |
|
| 114 | + $trimmedTag = trim($tag); |
|
| 115 | 115 | |
| 116 | 116 | // if the tag is self closed do nothing |
| 117 | - if ( Strings::lastChar( $tag ) !== '/' ) { |
|
| 117 | + if (Strings::lastChar($tag) !== '/') { |
|
| 118 | 118 | $tags[] = $trimmedTag; |
| 119 | 119 | $offsets[] = $currentOffset; |
| 120 | - $originalLengths[] = strlen( $tag ) + 2; // add 2 to length because there are < and > |
|
| 120 | + $originalLengths[] = strlen($tag) + 2; // add 2 to length because there are < and > |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -125,47 +125,47 @@ discard block |
||
| 125 | 125 | // 2. Removing closed tags |
| 126 | 126 | $indexes = []; |
| 127 | 127 | |
| 128 | - if ( count( $tags ) > 0 ) { |
|
| 129 | - foreach ( $tags as $index => $tag ) { |
|
| 128 | + if (count($tags) > 0) { |
|
| 129 | + foreach ($tags as $index => $tag) { |
|
| 130 | 130 | |
| 131 | - if ( Strings::contains( '/', $tag ) ) { |
|
| 131 | + if (Strings::contains('/', $tag)) { |
|
| 132 | 132 | $complementaryTag = $tag; |
| 133 | 133 | } else { |
| 134 | - $complementaryTag = '/' . explode( ' ', $tag )[ 0 ]; |
|
| 134 | + $complementaryTag = '/' . explode(' ', $tag)[0]; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $complementaryTagIndex = array_search( $complementaryTag, $tags ); |
|
| 137 | + $complementaryTagIndex = array_search($complementaryTag, $tags); |
|
| 138 | 138 | |
| 139 | - if ( false !== $complementaryTagIndex ) { |
|
| 139 | + if (false !== $complementaryTagIndex) { |
|
| 140 | 140 | $indexes[] = $index; |
| 141 | 141 | $indexes[] = $complementaryTagIndex; |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - $indexes = array_unique( $indexes ); |
|
| 147 | - foreach ( $indexes as $index ) { |
|
| 148 | - unset( $tags[ $index ] ); |
|
| 146 | + $indexes = array_unique($indexes); |
|
| 147 | + foreach ($indexes as $index) { |
|
| 148 | + unset($tags[$index]); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // 3. Loop not closed tags |
| 152 | 152 | $delta = 0; |
| 153 | 153 | |
| 154 | - if ( count( $tags ) ) { |
|
| 155 | - foreach ( $tags as $index => $tag ) { |
|
| 154 | + if (count($tags)) { |
|
| 155 | + foreach ($tags as $index => $tag) { |
|
| 156 | 156 | |
| 157 | - $length = $originalLengths[ $index ]; |
|
| 158 | - $offset = $offsets[ $index ]; |
|
| 159 | - $realOffset = ( $delta === 0 ) ? $offset : ( $offset + $delta ); |
|
| 157 | + $length = $originalLengths[$index]; |
|
| 158 | + $offset = $offsets[$index]; |
|
| 159 | + $realOffset = ($delta === 0) ? $offset : ($offset + $delta); |
|
| 160 | 160 | |
| 161 | 161 | $replacement = self::LT_PLACEHOLDER . $tag . self::GT_PLACEHOLDER; |
| 162 | 162 | |
| 163 | - $html = substr_replace( $html, $replacement, $realOffset, $length ); |
|
| 164 | - $delta = $delta + strlen( $replacement ) - $length; |
|
| 163 | + $html = substr_replace($html, $replacement, $realOffset, $length); |
|
| 164 | + $delta = $delta + strlen($replacement) - $length; |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - return !is_array( $html ) ? $html : implode( $html ); |
|
| 168 | + return !is_array($html) ? $html : implode($html); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -174,55 +174,55 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return array |
| 176 | 176 | */ |
| 177 | - private static function extractHtmlNode( $html, $toBeEscaped = false ) { |
|
| 177 | + private static function extractHtmlNode($html, $toBeEscaped = false) { |
|
| 178 | 178 | $pattern = "/<([a-zA-Z0-9._-]+)([^>]|[^<]*?)(([\s]*\/>)|" . |
| 179 | 179 | "(>((([^<]*?|<\!\-\-.*?\-\->)|(?R))*)<\/\\1[\s]*>))/sm"; |
| 180 | - preg_match_all( $pattern, $html, $matches, PREG_OFFSET_CAPTURE ); |
|
| 180 | + preg_match_all($pattern, $html, $matches, PREG_OFFSET_CAPTURE); |
|
| 181 | 181 | |
| 182 | 182 | $elements = []; |
| 183 | 183 | |
| 184 | - foreach ( $matches[ 0 ] as $key => $match ) { |
|
| 184 | + foreach ($matches[0] as $key => $match) { |
|
| 185 | 185 | |
| 186 | - $attributes = isset( $matches[ 2 ][ $key ][ 0 ] ) ? self::getAttributes( $matches[ 2 ][ $key ][ 0 ] ) : []; |
|
| 187 | - $base64Decoded = ( isset( $attributes[ 'equiv-text' ] ) ) ? base64_decode( str_replace( "base64:", "", $attributes[ 'equiv-text' ] ) ) : null; |
|
| 188 | - $tagName = $matches[ 1 ][ $key ][ 0 ]; |
|
| 189 | - $text = !empty( $matches[ 6 ][ $key ][ 0 ] ) ? $matches[ 6 ][ $key ][ 0 ] : ""; |
|
| 186 | + $attributes = isset($matches[2][$key][0]) ? self::getAttributes($matches[2][$key][0]) : []; |
|
| 187 | + $base64Decoded = (isset($attributes['equiv-text'])) ? base64_decode(str_replace("base64:", "", $attributes['equiv-text'])) : null; |
|
| 188 | + $tagName = $matches[1][$key][0]; |
|
| 189 | + $text = !empty($matches[6][$key][0]) ? $matches[6][$key][0] : ""; |
|
| 190 | 190 | $originalText = $text; |
| 191 | - $strippedText = strip_tags( $text ); |
|
| 191 | + $strippedText = strip_tags($text); |
|
| 192 | 192 | |
| 193 | 193 | // get start and end tags |
| 194 | - $explodedNode = explode( self::ORIGINAL_TEXT_PLACEHOLDER, str_replace( $originalText, self::ORIGINAL_TEXT_PLACEHOLDER, $match[ 0 ] ) ); |
|
| 194 | + $explodedNode = explode(self::ORIGINAL_TEXT_PLACEHOLDER, str_replace($originalText, self::ORIGINAL_TEXT_PLACEHOLDER, $match[0])); |
|
| 195 | 195 | |
| 196 | - $start = ( isset( $explodedNode[ 0 ] ) ) ? $explodedNode[ 0 ] : ""; |
|
| 197 | - $end = ( isset( $explodedNode[ 1 ] ) ) ? $explodedNode[ 1 ] : ""; |
|
| 196 | + $start = (isset($explodedNode[0])) ? $explodedNode[0] : ""; |
|
| 197 | + $end = (isset($explodedNode[1])) ? $explodedNode[1] : ""; |
|
| 198 | 198 | |
| 199 | 199 | // inner_html |
| 200 | - $inner_html = self::getInnerHtml( $matches, $key, $toBeEscaped ); |
|
| 200 | + $inner_html = self::getInnerHtml($matches, $key, $toBeEscaped); |
|
| 201 | 201 | |
| 202 | 202 | // node |
| 203 | - $node = self::rebuildNode( $originalText, $toBeEscaped, $start, $end ); |
|
| 203 | + $node = self::rebuildNode($originalText, $toBeEscaped, $start, $end); |
|
| 204 | 204 | |
| 205 | 205 | // terminator |
| 206 | - $terminator = ( $toBeEscaped ) ? '>' : '>'; |
|
| 206 | + $terminator = ($toBeEscaped) ? '>' : '>'; |
|
| 207 | 207 | |
| 208 | 208 | // self closed |
| 209 | - $selfClosed = Strings::contains( '/>', trim( $start ) ); |
|
| 209 | + $selfClosed = Strings::contains('/>', trim($start)); |
|
| 210 | 210 | |
| 211 | 211 | $elements[] = (object)[ |
| 212 | - 'node' => self::restoreLessThanAndGreaterThanSymbols( $node ), |
|
| 213 | - 'start' => self::restoreLessThanAndGreaterThanSymbols( $start ), |
|
| 214 | - 'end' => self::restoreLessThanAndGreaterThanSymbols( $end ), |
|
| 212 | + 'node' => self::restoreLessThanAndGreaterThanSymbols($node), |
|
| 213 | + 'start' => self::restoreLessThanAndGreaterThanSymbols($start), |
|
| 214 | + 'end' => self::restoreLessThanAndGreaterThanSymbols($end), |
|
| 215 | 215 | 'terminator' => $terminator, |
| 216 | - 'offset' => $match[ 1 ], |
|
| 216 | + 'offset' => $match[1], |
|
| 217 | 217 | 'tagname' => $tagName, |
| 218 | 218 | 'attributes' => $attributes, |
| 219 | 219 | 'base64_decoded' => $base64Decoded, |
| 220 | 220 | 'self_closed' => $selfClosed, |
| 221 | - 'omittag' => ( $matches[ 4 ][ $key ][ 1 ] > -1 ), // boolean |
|
| 221 | + 'omittag' => ($matches[4][$key][1] > -1), // boolean |
|
| 222 | 222 | 'inner_html' => $inner_html, |
| 223 | - 'has_children' => is_array( $inner_html ), |
|
| 224 | - 'original_text' => ( $toBeEscaped ) ? self::restoreLessThanAndGreaterThanSymbols( Strings::escapeOnlyHTMLTags( $originalText ) ) : self::restoreLessThanAndGreaterThanSymbols( $originalText ), |
|
| 225 | - 'stripped_text' => self::restoreLessThanAndGreaterThanSymbols( $strippedText ), |
|
| 223 | + 'has_children' => is_array($inner_html), |
|
| 224 | + 'original_text' => ($toBeEscaped) ? self::restoreLessThanAndGreaterThanSymbols(Strings::escapeOnlyHTMLTags($originalText)) : self::restoreLessThanAndGreaterThanSymbols($originalText), |
|
| 225 | + 'stripped_text' => self::restoreLessThanAndGreaterThanSymbols($strippedText), |
|
| 226 | 226 | ]; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @return string|string[] |
| 236 | 236 | */ |
| 237 | - private static function restoreLessThanAndGreaterThanSymbols( $text ) { |
|
| 238 | - return str_replace( [ self::LT_PLACEHOLDER, self::GT_PLACEHOLDER ], [ '<', '>' ], $text ); |
|
| 237 | + private static function restoreLessThanAndGreaterThanSymbols($text) { |
|
| 238 | + return str_replace([self::LT_PLACEHOLDER, self::GT_PLACEHOLDER], ['<', '>'], $text); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -246,17 +246,17 @@ discard block |
||
| 246 | 246 | * |
| 247 | 247 | * @return string |
| 248 | 248 | */ |
| 249 | - private static function rebuildNode( $originalText, $toBeEscaped, $start = null, $end = null ) { |
|
| 249 | + private static function rebuildNode($originalText, $toBeEscaped, $start = null, $end = null) { |
|
| 250 | 250 | $node = ''; |
| 251 | 251 | |
| 252 | - if ( !empty( $start ) ) { |
|
| 253 | - $node .= ( $toBeEscaped ) ? Strings::escapeOnlyHTMLTags( $start ) : $start; |
|
| 252 | + if (!empty($start)) { |
|
| 253 | + $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($start) : $start; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $node .= ( $toBeEscaped ) ? Strings::escapeOnlyHTMLTags( $originalText ) : $originalText; |
|
| 256 | + $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($originalText) : $originalText; |
|
| 257 | 257 | |
| 258 | - if ( !empty( $end ) ) { |
|
| 259 | - $node .= ( $toBeEscaped ) ? Strings::escapeOnlyHTMLTags( $end ) : $end; |
|
| 258 | + if (!empty($end)) { |
|
| 259 | + $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($end) : $end; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | return $node; |
@@ -267,16 +267,16 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return mixed |
| 269 | 269 | */ |
| 270 | - public static function getAttributes( $content ) { |
|
| 270 | + public static function getAttributes($content) { |
|
| 271 | 271 | $pattern = '/(.*?)=("|\'|\\\")(.*?)("|\'|\\\"|\\\')/'; |
| 272 | 272 | |
| 273 | - preg_match_all( $pattern, $content, $matches, PREG_OFFSET_CAPTURE ); |
|
| 273 | + preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE); |
|
| 274 | 274 | |
| 275 | 275 | $attributes = []; |
| 276 | 276 | |
| 277 | - if ( isset( $matches[ 1 ] ) && count( $matches[ 1 ] ) > 0 ) { |
|
| 278 | - foreach ( $matches[ 1 ] as $key => $match ) { |
|
| 279 | - $attributes[ trim( $match[ 0 ] ) ] = $matches[ 3 ][ $key ][ 0 ]; |
|
| 277 | + if (isset($matches[1]) && count($matches[1]) > 0) { |
|
| 278 | + foreach ($matches[1] as $key => $match) { |
|
| 279 | + $attributes[trim($match[0])] = $matches[3][$key][0]; |
|
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
@@ -291,11 +291,11 @@ discard block |
||
| 291 | 291 | * |
| 292 | 292 | * @return array|mixed|string |
| 293 | 293 | */ |
| 294 | - private static function getInnerHtml( $matches, $key, $toBeEscaped = false ) { |
|
| 295 | - if ( isset( $matches[ 6 ][ $key ][ 0 ] ) ) { |
|
| 296 | - $node = self::extractHtmlNode( $matches[ 6 ][ $key ][ 0 ], $toBeEscaped ); |
|
| 294 | + private static function getInnerHtml($matches, $key, $toBeEscaped = false) { |
|
| 295 | + if (isset($matches[6][$key][0])) { |
|
| 296 | + $node = self::extractHtmlNode($matches[6][$key][0], $toBeEscaped); |
|
| 297 | 297 | |
| 298 | - return ( !empty( $node ) ) ? $node : $matches[ 6 ][ $key ][ 0 ]; |
|
| 298 | + return (!empty($node)) ? $node : $matches[6][$key][0]; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | return null; |
@@ -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. |