/** * @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 static function load() { if (!($map = Cache::get(self::CACHE_KEY . '_map'))) { $path = Environment::pathComponentsResource('i18n', 'resource', 'i18n', 'script', 'hans.json'); $map = json_decode(Io_File::valueOf($path)->getContent(), true); Cache::set(self::CACHE_KEY . '_map', $map); } self::$m_unicode =& $map['unicode']; self::$m_transformLatn =& $map['transform']['latin']; }
/** * @param integer $mask_ * * @return \Components\Io_File * * @throws \Components\Io_Exception */ public function open() { parent::open(); if ($this->m_accessMask & self::APPEND) { $this->m_bufferPosition = $this->m_length; } else { $this->m_bufferPosition = 0; } $this->m_eof = $this->m_bufferPosition === $this->m_length; return $this; }
/** * @param string $prefix_ * @param string $path_ * @param boolean $global_ * @param integer $accessModeMask_ * * @return \Components\Io_File */ public static function tmpFileForMimetype(Io_Mimetype $mimeType_, $prefix_ = null, $path_ = null, $global_ = true, $accessModeMask_ = Io_File::CREATE) { return Io_File::forMimetype(static::tmpFileName($prefix_, $path_, $global_), $accessModeMask_, $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(); }
public function containsFile(Io_File $file_) { return $this->m_path === $file_->getDirectory()->m_path; }
/** * @see \Components\Io_File::open() \Components\Io_File::open() * * @return \Components\Io_File_Csv */ public function open() { parent::open(); $this->readHeader(); return $this; }
/** * @see \Components\Media_Storage::addByScheme() \Components\Media_Storage::addByScheme() */ public function addByScheme($scheme_, Io_File $file_, $id_, $category_ = null) { return $file_->copy(Io::file(Environment::pathResource("{$this->store->path}/{$scheme_}/{$category_}/{$id_}")), true); }
public function saveAs(Io_File $file_) { $this->engine()->save($file_->m_pathAsString, $file_->getMimetype()); return $this; }
/** * @param \Components\Io_File $target_ * * @return \Components\Io_File */ public function move(Io_File $destination_, $autoCreateTargetDirectory_ = false, $umaskTargetDirectory_ = 0775) { if (true === $autoCreateTargetDirectory_) { $targetDirectory = $destination_->getDirectory(); if (false === $targetDirectory->exists()) { $targetDirectory->create($umaskTargetDirectory_); } } if (false === rename($this->m_pathAsString, $destination_->m_pathAsString)) { if (is_file($destination_->m_pathAsString)) { unlink($this->m_pathAsString); } else { throw new Io_Exception('io/file', sprintf('Failed to move file to given destination [source: %s, destination: %s].', $this, $destination_)); } } return $destination_; }
public function printFile(Io_File $file_, $subPath_, $mimeTypeIconSize_ = Io_Mimetype::ICON_SIZE_64) { $actions = []; foreach ($this->m_fileActionsJs as $name => $action) { if (false === ($callback = call_user_func_array($action['callback'], [$file_]))) { continue; } $function = array_shift($callback); $actions[] = sprintf('<a href="javascript:void(0);" onclick="%3$s(%4$s);" class="%1$s">%2$s</a>', $name, $action['title'], $function, strtr(json_encode(array_merge([$subPath_], $callback)), '"', "'")); } $actionRemove = sprintf('<a href="javascript:void(0);" onclick="%3$s" class="%1$s">%2$s</a>', 'remove', 'Remove', $this->callback(['remove' => $subPath_])); echo '<div class="file">'; if ($mimeTypeIconSize_ > Io_Mimetype::ICON_SIZE_16) { printf(' <div class="icon"> <img src="%1$s" alt="%2$s" title="%2$s"/> </div> <div class="info"> <a href="javascript:void(0);" class="label">%2$s</a>', $file_->getMimetype()->icon($mimeTypeIconSize_), $subPath_); array_unshift($actions, $actionRemove); } else { printf(' <div class="info"> <img src="%1$s" alt="%2$s" title="%2$s"/> <a href="javascript:void(0);" class="label">%2$s</a>', $file_->getMimetype()->icon($mimeTypeIconSize_), $subPath_); array_push($actions, $actionRemove); } printf(' <span class="type">%1$s</span> <span class="size">%2$s</span> <span class="links">%3$s</span> </div> <br class="clear"/> </div>', ucfirst($file_->getMimetype()->title()), $file_->getSize()->formatAsBytes(2), implode(' | ', $actions)); }