/** * @param string $filepath_ * @param \Components\Io_Mimetype $mimeType_ * * @throws \Components\Runtime_Exception * * @return \Components\Mail_Part_Image */ public static function forFile(Io_File $file_) { if (false === $file_->exists()) { throw new Io_Exception('mail/part/file', sprintf('File does not exist [file: %1$s].', $file_)); } $mimeType = $file_->getMimetype(); if (null === $mimeType) { throw new Io_Exception('mail/part/file', sprintf('Unable to resolve mimetype for given file [file: %1$s].', $file_)); } return new static($file_->getName(), $file_->getContent(), $mimeType); }
private function importScript($script_) { $target = Environment::pathComponentsResource('i18n', 'resource', 'i18n', 'script', "{$script_}.json"); $ranges = array_chunk(self::$m_unicodeRanges[$script_], 2); $range = []; foreach ($ranges as $r) { $range = array_merge($range, range(reset($r), end($r))); } $range = array_flip($range); $mapScript = []; $mapScriptUnicode =& $mapScript['unicode']; $mapScriptTransformations =& $mapScript['transform']; foreach (self::$m_scripts[$script_] as $transformation) { $mapScriptTransformations[$transformation] = []; $mapScriptTransformationsCurrent =& $mapScriptTransformations[$transformation]; $source = self::$m_sources[$script_][$transformation]; $source = Environment::pathComponentsResource('i18n', 'resource', 'cldr', $source); // TODO Implement Io_File_Xml $xml = new \SimpleXMLElement(Io_File::valueOf($source)->getContent()); /* @var $node \SimpleXMLElement */ foreach ($xml->xpath('//supplementalData/transforms/transform/tRule') as $node) { $string = (string) $node; $chars = ''; $trans = ''; if (91 === ord($string[0])) { $chars = mb_substr($string, 1, mb_strpos($string, chr(93)) - 1); $ldim = mb_strrpos($string, chr(226)); $trans = mb_substr($string, $ldim + 1, mb_strrpos($string, chr(59)) - $ldim - 1); } $len = mb_strlen($chars); for ($i = 0; $i < $len; $i++) { $char = mb_substr($chars, $i, 1); $dec = Character::unicodeDecimal($char); if (isset($range[$dec])) { $mapScriptUnicode[$dec] = " \"{$dec}\": \"{$char}\""; $mapScriptTransformationsCurrent[$dec] = " \"{$dec}\": \"{$trans}\""; } } } $string = implode(",\n", $mapScriptUnicode); } $transform = []; foreach ($mapScript['transform'] as $script => $transformations) { $transform[] = sprintf(' "%1$s":%3$s {%3$s%2$s%3$s }%3$s', $script, implode(",\n", $transformations), Io::LINE_SEPARATOR_DEFAULT); } $file = new Io_File($target, Io_File::CREATE | Io_File::WRITE | Io_File::TRUNCATE); if (false === $file->exists()) { $file->create(); } $file->open(); // XXX json_encode converts to unicode - which we dont want here - yet maybe implement an alternative Object_Marshaller_Json or Io_File_Json... $file->writeLine('{'); $file->writeLine(' "unicode":'); $file->writeLine(' {'); $file->writeLine(implode(",\n", $mapScript['unicode'])); $file->writeLine(' },'); $file->writeLine(' "transform":'); $file->writeLine(' {'); $file->write(implode(",\n", $transform)); $file->writeLine(' }'); $file->writeLine('}'); $file->close(); }