當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Console::writef方法代碼示例

本文整理匯總了PHP中Console::writef方法的典型用法代碼示例。如果您正苦於以下問題:PHP Console::writef方法的具體用法?PHP Console::writef怎麽用?PHP Console::writef使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Console的用法示例。


在下文中一共展示了Console::writef方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: extract

 /**
  * Extract a ".ar" file into a given target directory
  *
  * @param   string base
  * @param   string ar
  * @param   io.Folder target
  * @throws  lang.IllegalStateException in case the target is not found
  * @throws  lang.FormatException in case the .ar-file is not parseable
  */
 protected function extract($base, $ar, Folder $target)
 {
     // Open a HTTP connection
     $url = new URL($base . $ar . '.ar');
     $r = create(new HttpConnection($url))->get();
     if (HttpConstants::STATUS_OK != $r->getStatusCode()) {
         throw new IllegalStateException(sprintf('Unexpected response %d:%s for %s', $r->getStatusCode(), $r->getMessage(), $url->getURL()));
     }
     $in = new BufferedInputStream($r->getInputStream());
     do {
         // Seach for first section header, --[LENGTH]:[FILENAME]-- and parse it
         do {
             $line = $this->readLine($in);
             if (!$in->available()) {
                 throw new FormatException('Cannot locate section header');
             }
         } while (2 !== sscanf($line, '--%d:%[^:]--', $length, $filename));
         // Calculate target file
         $file = new File($target, $filename);
         $folder = new Folder($file->getPath());
         $folder->exists() || $folder->create();
         Console::writef('     >> [%-10s] %s (%.2f kB) [%s]%s', $ar, $filename, $length / 1024, str_repeat('.', self::PROGRESS_INDICATOR_WIDTH), str_repeat("", self::PROGRESS_INDICATOR_WIDTH + 1));
         // Transfer length bytes into file
         $c = 0;
         $out = $file->getOutputStream();
         $size = 0;
         while ($size < $length) {
             $chunk = $in->read(min(0x1000, $length - $size));
             $size += strlen($chunk);
             $out->write($chunk);
             // Update progress
             $d = ceil($size / $length * self::PROGRESS_INDICATOR_WIDTH);
             if ($d == $c) {
                 continue;
             }
             Console::write(str_repeat('#', $d - $c));
             $c = $d;
         }
         $out->close();
         Console::writeLine();
     } while ($in->available() > 0);
     $in->close();
 }
開發者ID:Gamepay,項目名稱:xp-framework,代碼行數:52,代碼來源:DownloadAction.class.php

示例2: writef

 public function writef()
 {
     Console::writef('Hello "%s"', 'Timm');
     $this->assertEquals('Hello "Timm"', $this->streams[1]->getBytes());
 }
開發者ID:Gamepay,項目名稱:xp-framework,代碼行數:5,代碼來源:ConsoleTest.class.php


注:本文中的Console::writef方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。