comparison vendor/symfony/translation/Loader/MoFileLoader.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
19 class MoFileLoader extends FileLoader 19 class MoFileLoader extends FileLoader
20 { 20 {
21 /** 21 /**
22 * Magic used for validating the format of a MO file as well as 22 * Magic used for validating the format of a MO file as well as
23 * detecting if the machine used to create that file was little endian. 23 * detecting if the machine used to create that file was little endian.
24 *
25 * @var float
26 */ 24 */
27 const MO_LITTLE_ENDIAN_MAGIC = 0x950412de; 25 const MO_LITTLE_ENDIAN_MAGIC = 0x950412de;
28 26
29 /** 27 /**
30 * Magic used for validating the format of a MO file as well as 28 * Magic used for validating the format of a MO file as well as
31 * detecting if the machine used to create that file was big endian. 29 * detecting if the machine used to create that file was big endian.
32 *
33 * @var float
34 */ 30 */
35 const MO_BIG_ENDIAN_MAGIC = 0xde120495; 31 const MO_BIG_ENDIAN_MAGIC = 0xde120495;
36 32
37 /** 33 /**
38 * The size of the header of a MO file in bytes. 34 * The size of the header of a MO file in bytes.
39 *
40 * @var int Number of bytes
41 */ 35 */
42 const MO_HEADER_SIZE = 28; 36 const MO_HEADER_SIZE = 28;
43 37
44 /** 38 /**
45 * Parses machine object (MO) format, independent of the machine's endian it 39 * Parses machine object (MO) format, independent of the machine's endian it
57 throw new InvalidResourceException('MO stream content has an invalid format.'); 51 throw new InvalidResourceException('MO stream content has an invalid format.');
58 } 52 }
59 $magic = unpack('V1', fread($stream, 4)); 53 $magic = unpack('V1', fread($stream, 4));
60 $magic = hexdec(substr(dechex(current($magic)), -8)); 54 $magic = hexdec(substr(dechex(current($magic)), -8));
61 55
62 if ($magic == self::MO_LITTLE_ENDIAN_MAGIC) { 56 if (self::MO_LITTLE_ENDIAN_MAGIC == $magic) {
63 $isBigEndian = false; 57 $isBigEndian = false;
64 } elseif ($magic == self::MO_BIG_ENDIAN_MAGIC) { 58 } elseif (self::MO_BIG_ENDIAN_MAGIC == $magic) {
65 $isBigEndian = true; 59 $isBigEndian = true;
66 } else { 60 } else {
67 throw new InvalidResourceException('MO stream content has an invalid format.'); 61 throw new InvalidResourceException('MO stream content has an invalid format.');
68 } 62 }
69 63
93 } 87 }
94 88
95 fseek($stream, $offset); 89 fseek($stream, $offset);
96 $singularId = fread($stream, $length); 90 $singularId = fread($stream, $length);
97 91
98 if (strpos($singularId, "\000") !== false) { 92 if (false !== strpos($singularId, "\000")) {
99 list($singularId, $pluralId) = explode("\000", $singularId); 93 list($singularId, $pluralId) = explode("\000", $singularId);
100 } 94 }
101 95
102 fseek($stream, $offsetTranslated + $i * 8); 96 fseek($stream, $offsetTranslated + $i * 8);
103 $length = $this->readLong($stream, $isBigEndian); 97 $length = $this->readLong($stream, $isBigEndian);
108 } 102 }
109 103
110 fseek($stream, $offset); 104 fseek($stream, $offset);
111 $translated = fread($stream, $length); 105 $translated = fread($stream, $length);
112 106
113 if (strpos($translated, "\000") !== false) { 107 if (false !== strpos($translated, "\000")) {
114 $translated = explode("\000", $translated); 108 $translated = explode("\000", $translated);
115 } 109 }
116 110
117 $ids = array('singular' => $singularId, 'plural' => $pluralId); 111 $ids = array('singular' => $singularId, 'plural' => $pluralId);
118 $item = compact('ids', 'translated'); 112 $item = compact('ids', 'translated');