当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFileObject::fflush方法代码示例

本文整理汇总了PHP中SplFileObject::fflush方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::fflush方法的具体用法?PHP SplFileObject::fflush怎么用?PHP SplFileObject::fflush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplFileObject的用法示例。


在下文中一共展示了SplFileObject::fflush方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: write

 /**
  * Write data for key into cache
  *
  * @param string $key Identifier for the data
  * @param mixed $data Data to be cached
  * @return bool True if the data was successfully cached, false on failure
  */
 public function write($key, $data)
 {
     if ($data === '' || !$this->_init) {
         return false;
     }
     $key = $this->_key($key);
     if ($this->_setKey($key, true) === false) {
         return false;
     }
     $lineBreak = "\n";
     if ($this->_config['isWindows']) {
         $lineBreak = "\r\n";
     }
     if (!empty($this->_config['serialize'])) {
         if ($this->_config['isWindows']) {
             $data = str_replace('\\', '\\\\\\\\', serialize($data));
         } else {
             $data = serialize($data);
         }
     }
     $duration = $this->_config['duration'];
     $expires = time() + $duration;
     $contents = $expires . $lineBreak . $data . $lineBreak;
     if ($this->_config['lock']) {
         $this->_File->flock(LOCK_EX);
     }
     $this->_File->rewind();
     $success = $this->_File->ftruncate(0) && $this->_File->fwrite($contents) && $this->_File->fflush();
     if ($this->_config['lock']) {
         $this->_File->flock(LOCK_UN);
     }
     $this->_File = null;
     return $success;
 }
开发者ID:Kononenkomg,项目名称:cakephp,代码行数:41,代码来源:FileEngine.php

示例2: write

 public function write($key, $data, $cache_duration)
 {
     if ($data === '' || is_null($data) || !$this->is_init) {
         return false;
     }
     if ($this->_openFile($key, true) === false) {
         return false;
     }
     $line_break = "\n";
     if ($this->settings['is_windows']) {
         $lineBreak = "\r\n";
     }
     if (!empty($this->settings['serialize'])) {
         if ($this->settings['is_windows']) {
             $data = str_replace('\\', '\\\\\\\\', json_encode($data));
         } else {
             $data = json_encode($data);
         }
     }
     $expires = time() + $cache_duration;
     $contents = $expires . $line_break . $data . $line_break;
     if ($this->settings['lock']) {
         $this->file->flock(LOCK_EX);
     }
     $this->file->rewind();
     $success = $this->file->ftruncate(0) && $this->file->fwrite($contents) && $this->file->fflush();
     if ($this->settings['lock']) {
         $this->file->flock(LOCK_UN);
     }
     return $success;
 }
开发者ID:rossaffandy,项目名称:blockchains.io,代码行数:31,代码来源:cache.php

示例3: createFile

 /**
  * Essentially, an "improved" tempnam().
  *
  * As compared to the core tempnam, this version allows you to add a file
  * extension, returns an SplFileObject and has a short hand for priming it
  * with some content. If content is written, the file is not rewound before
  * returning.
  *
  * @param  string|null    $content
  * @param  string         $extension
  * @return \SplFileObject
  */
 public function createFile($content = null, $extension = 'tmp')
 {
     $filename = $this->generateFilename($extension);
     if (file_exists($filename)) {
         throw FileAlreadyExistsException::create($filename);
     }
     $tempFile = new \SplFileObject($filename, 'x+');
     if ($content !== null) {
         $tempFile->fwrite($content);
         $tempFile->fflush();
     }
     return $tempFile;
 }
开发者ID:bangpound,项目名称:TuckConverterBundle,代码行数:25,代码来源:SysTempFileFactory.php

示例4: save

 /**
  * Saves the current upload stream to designated target.
  *
  * @param {string} Target path to save the contents, cannot be a directory.
  * @param {?bool} True to append to target file, defaults to replace.
  * @return {boolean} True on success, false otherwise.
  */
 public function save($path, $append = false)
 {
     if (is_dir($path)) {
         $path = preg_replace('/\\' . preg_quote(DS) . '?$/', '$1/' . $this->getFilename(), $path);
     }
     $target = new \SplFileObject($path, $append ? 'a' : 'w');
     $this->rewind();
     while (!$this->eof()) {
         $target->fwrite($this->fread(4096));
     }
     $target->fflush();
     $target->rewind();
     return $target;
 }
开发者ID:Victopia,项目名称:prefw,代码行数:21,代码来源:RequestPutFile.php

示例5: execute

 /**
  * @inheritDoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $context = $this->getContainer()->get('router')->getContext();
     $context->setHost($input->getOption('host'));
     $urlCollector = $this->getContainer()->get('shop.url_collector');
     $iterator = $urlCollector->collect();
     if ($file = $input->getOption('output')) {
         $file = new \SplFileObject($file, 'w');
         foreach ($iterator as $item) {
             $file->fwrite($item . PHP_EOL);
         }
         $file->fflush();
     } else {
         foreach ($iterator as $item) {
             $output->writeln($item);
         }
     }
 }
开发者ID:igaponov,项目名称:shop,代码行数:21,代码来源:SiteMapCommand.php

示例6: glossaryImport

 /**
  * Post a file to myMemory
  *
  * Remove the first line from csv ( source and target )
  * and rewrite the csv because MyMemory doesn't want the header line
  *
  * @param            $file
  * @param            $key
  * @param bool|false $name
  *
  * @return Engines_Results_MyMemory_TmxResponse
  */
 public function glossaryImport($file, $key, $name = false)
 {
     try {
         $origFile = new SplFileObject($file, 'r+');
         $origFile->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY | SplFileObject::READ_AHEAD);
         $tmpFileName = tempnam("/tmp", 'GLOS');
         $newFile = new SplFileObject($tmpFileName, 'r+');
         $newFile->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY | SplFileObject::READ_AHEAD);
         foreach ($origFile as $line_num => $line) {
             if (count($line) < 2) {
                 throw new RuntimeException("No valid glossary file provided. Field separator could be not valid.");
             }
             if ($line_num == 0) {
                 list($source_lang, $target_lang, ) = $line;
                 //eventually, remove BOM from source language
                 $bom = pack('H*', 'EFBBBF');
                 $source_lang = preg_replace("/^{$bom}/", "", $source_lang);
                 if (!Langs_Languages::isEnabled($source_lang)) {
                     throw new RuntimeException("The source language specified in the glossary is not supported: " . $source_lang);
                 }
                 if (!Langs_Languages::isEnabled($target_lang)) {
                     throw new RuntimeException("The target language specified in the glossary is not supported: " . $target_lang);
                 }
                 if (empty($source_lang) || empty($target_lang)) {
                     throw new RuntimeException("No language definition found in glossary file.");
                 }
                 continue;
             }
             //copy stream to stream
             $newFile->fputcsv($line);
         }
         $newFile->fflush();
         $origFile = null;
         //close the file handle
         $newFile = null;
         //close the file handle
         copy($tmpFileName, $file);
         unlink($tmpFileName);
     } catch (RuntimeException $e) {
         $this->result = new Engines_Results_MyMemory_TmxResponse(array("responseStatus" => 406, "responseData" => null, "responseDetails" => $e->getMessage()));
         return $this->result;
     }
     $postFields = array('glossary' => "@" . realpath($file), 'source_lang' => $source_lang, 'target_lang' => $target_lang, 'name' => $name);
     $postFields['key'] = trim($key);
     $this->call("glossary_import_relative_url", $postFields, true);
     return $this->result;
 }
开发者ID:bcrazvan,项目名称:MateCat,代码行数:59,代码来源:MyMemory.php

示例7: SplFileObject

<?php

/*
 * test a successful flush
*/
$obj = new SplFileObject(dirname(__FILE__) . '/SplFileObject_testinput.csv');
var_dump($obj->fflush());
/*
 * test a unsuccessful flush
*/
//create a basic stream class
class VariableStream
{
    var $position;
    var $varname;
    function stream_open($path, $mode, $options, &$opened_path)
    {
        return true;
    }
    function url_stat()
    {
    }
}
stream_wrapper_register("SPLtest", "VariableStream");
$ftruncate_test = "";
//end creating stream
//open an SplFileObject using the above test stream
$obj = new SplFileObject("SPLtest://ftruncate_test");
var_dump($obj->fflush());
开发者ID:badlamer,项目名称:hhvm,代码行数:29,代码来源:SplFileObject_fflush_basic_001.php

示例8: addBackupProcessMessage

 /**
  * Add backup process message
  *
  * @param string $message
  * @param bool|string $error Boolean or ERROR|WARNING|INFO|DEBUG
  *
  * @return Varien_Data_Form_Element_Abstract
  */
 public function addBackupProcessMessage($message, $error = false)
 {
     $message_type = $this->getMessageType($error);
     if ($message_type === self::LOG_LEVEL_WARNING) {
         $this->getSession()->setHasBackupWarnings(true);
     }
     $logLevel = $this->getLogLevel();
     if ($logLevel === self::LOG_LEVEL_OFF) {
         return $this;
     }
     if ($logLevel !== self::LOG_LEVEL_ALL) {
         if ($logLevel === self::LOG_LEVEL_WARNING && $message_type !== self::LOG_LEVEL_ERROR && $message_type !== self::LOG_LEVEL_WARNING) {
             return $this;
         } else {
             if ($logLevel === self::LOG_LEVEL_INFO && $message_type === self::LOG_LEVEL_DEBUG) {
                 return $this;
             }
         }
     }
     $content = $this->getBackupProcessMessage($message, $message_type);
     if (!($logFile = $this->getLogMessageFileName())) {
         Mage::logException(new Exception('Message "' . $content . '" is not written to log file'));
     } else {
         $file = new SplFileObject($logFile, 'a');
         $file->fwrite($content . PHP_EOL);
         $file->fflush();
         $file = null;
     }
     return $this;
 }
开发者ID:CE-Webmaster,项目名称:CE-Hub,代码行数:38,代码来源:Backup.php


注:本文中的SplFileObject::fflush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。