11
11
12
12
namespace Symfony \Component \Translation \Loader \XliffVersion ;
13
13
14
- use DOMDocument ;
15
14
use Symfony \Component \Translation \MessageCatalogue ;
16
15
17
16
/**
18
17
* XliffVersion12 loads XLIFF files identified with version 1.2
19
18
*
20
19
* @author Berny Cantos <[email protected] >
21
20
*/
22
- class XliffVersion12
21
+ class XliffVersion12 extends AbstractXliffVersion
23
22
{
24
23
/**
25
24
* Get validation schema source for this version
@@ -36,11 +35,11 @@ public function getSchema()
36
35
/**
37
36
* Extract messages and metadata from DOMDocument into a MessageCatalogue
38
37
*
39
- * @param DOMDocument $dom Source to extract messages and metadata
38
+ * @param \ DOMDocument $dom Source to extract messages and metadata
40
39
* @param MessageCatalogue $catalogue Catalogue where we'll collect messages and metadata
41
40
* @param string $domain The domain
42
41
*/
43
- public function extract (DOMDocument $ dom , MessageCatalogue $ catalogue , $ domain )
42
+ public function extract (\ DOMDocument $ dom , MessageCatalogue $ catalogue , $ domain )
44
43
{
45
44
$ xml = simplexml_import_dom ($ dom );
46
45
$ encoding = strtoupper ($ dom ->encoding );
@@ -81,57 +80,4 @@ public function extract(DOMDocument $dom, MessageCatalogue $catalogue, $domain)
81
80
}
82
81
}
83
82
}
84
-
85
- /**
86
- * Internally changes the URI of a dependent xsd to be loaded locally
87
- *
88
- * @param string $schemaSource Current content of schema file
89
- * @param string $xmlUri External URI of XML to convert to local
90
- *
91
- * @return string
92
- */
93
- protected function fixXmlLocation ($ schemaSource , $ xmlUri )
94
- {
95
- $ newPath = str_replace ('\\' , '/ ' , __DIR__ ).'/../schema/dic/xliff-core/xml.xsd ' ;
96
- $ parts = explode ('/ ' , $ newPath );
97
- if (0 === stripos ($ newPath , 'phar:// ' )) {
98
- $ tmpfile = tempnam (sys_get_temp_dir (), 'sf2 ' );
99
- if ($ tmpfile ) {
100
- copy ($ newPath , $ tmpfile );
101
- $ parts = explode ('/ ' , str_replace ('\\' , '/ ' , $ tmpfile ));
102
- }
103
- }
104
- $ drive = '\\' === DIRECTORY_SEPARATOR ? array_shift ($ parts ).'/ ' : '' ;
105
- $ newPath = 'file:/// ' .$ drive .implode ('/ ' , array_map ('rawurlencode ' , $ parts ));
106
-
107
- return str_replace ($ xmlUri , $ newPath , $ schemaSource );
108
- }
109
-
110
- /**
111
- * Convert a UTF8 string to the specified encoding
112
- *
113
- * @param string $content String to decode
114
- * @param string $encoding Target encoding
115
- *
116
- * @throws \RuntimeException
117
- * @return string
118
- */
119
- protected function utf8ToCharset ($ content , $ encoding = null )
120
- {
121
- if (empty ($ encoding ) || 'UTF-8 ' === $ encoding ) {
122
- return $ content ;
123
- }
124
-
125
- if (function_exists ('mb_convert_encoding ' )) {
126
- return mb_convert_encoding ($ content , $ encoding , 'UTF-8 ' );
127
- }
128
-
129
- if (function_exists ('iconv ' )) {
130
- return iconv ('UTF-8 ' , $ encoding , $ content );
131
- }
132
-
133
- throw new \RuntimeException (
134
- 'No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension). '
135
- );
136
- }
137
83
}
0 commit comments