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


PHP SplFileObject::valid方法代码示例

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


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

示例1: read

 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if ($this->file->valid()) {
         $this->file->seek($this->getContext()->getReadCount());
         $line = rtrim($this->file->current(), PHP_EOL);
         $this->getContext()->incrementReadCount();
         return json_decode($line, true);
     }
     return null;
 }
开发者ID:Maksold,项目名称:platform,代码行数:13,代码来源:LogReader.php

示例2: __construct

 /**
  * File constructor.
  * @param $uri String File path or URL
  * @throws \ErrorException
  * @throws \Exception
  */
 public function __construct($uri)
 {
     try {
         $this->messageFactory = new MessageFactory();
         $file = new \SplFileObject($uri, 'rb');
         while ($file->valid()) {
             $raw_time = $file->fread(8);
             if (!$raw_time) {
                 break;
             }
             $header = new Header($file->fread(6));
             if ($header->magic !== 0xfe) {
                 throw new \ErrorException("Unexpected magic number ({$header->magic})");
             }
             $payload = $file->fread($header->length);
             $raw_crc = $file->fread(2);
             $entry = new Entry($raw_time, $header, $payload, $raw_crc);
             $this->entries[] = $entry;
             $this->messages[] = $this->messageFactory->build($entry);
         }
         if (!$this->hasEntries()) {
             throw new \ErrorException('No entries found in file.');
         }
         $this->startTime = $this->entries[0]->time;
         $this->endTime = end($this->entries)->time;
     } catch (\Exception $ex) {
         //            echo $ex->getMessage() . ' ' . $ex->getFile() . ':' . $ex->getLine();
         die;
     }
 }
开发者ID:oblogic7,项目名称:tlog-php,代码行数:36,代码来源:File.php

示例3: valid

 public function valid()
 {
     $current = $this->current();
     if ($this->names) {
         return count($current) == count($this->names);
     }
     return parent::valid();
 }
开发者ID:nesQuick,项目名称:php-csv-file,代码行数:8,代码来源:Iterator.php

示例4: valid

 /**
  * valid SplFileObjectでCSVフィルを読ませると最終行の空配列で返るのでそれの抑止
  *
  * @return bool
  */
 public function valid()
 {
     $parentValid = parent::valid();
     $var = parent::current();
     if ($var === array(null)) {
         return false;
     }
     return $parentValid;
 }
开发者ID:s-nakajima,项目名称:files,代码行数:14,代码来源:CsvFileReader.php

示例5: generate

function generate($nb, $fixture = __DIR__ . '/fixtures/lorem.txt')
{
    $lorems = new SplFileObject($fixture, 'a+');
    $txt = '';
    while ($nb > 0 && $lorems->valid()) {
        $txt .= $lorems->current();
        $lorems->next();
        $nb--;
    }
    return $txt;
}
开发者ID:Antoine07,项目名称:AppFromScratch,代码行数:11,代码来源:seeds.php

示例6: getData

 public function getData()
 {
     try {
         $file = new SplFileObject($this->tmp_name, 'rb');
         $data = null;
         for ($file; $file->valid(); $file->next()) {
             $data .= $file->current();
         }
         return $data;
     } catch (RuntimeException $e) {
     }
     return null;
 }
开发者ID:Fadheler,项目名称:TorrentTrader-3.0,代码行数:13,代码来源:Upload.php

示例7: getRaw

 /**
  * Get raw image data from the SplFileObject.
  *
  * @return string
  *         String representation of the raw image binary data
  */
 public function getRaw()
 {
     if (!is_null($this->raw)) {
         return $this->raw;
     }
     // Save our current position
     $position = $this->object->ftell();
     $this->object->rewind();
     $raw = '';
     while ($this->object->valid()) {
         $raw .= $this->object->fgets();
     }
     // Go back to our original position
     $this->object->fseek($position);
     return $this->raw = $raw;
 }
开发者ID:fuzz-productions,项目名称:image-resizer,代码行数:22,代码来源:File.php

示例8: parseFileObject

 /**
  * @param \SplFileObject $fileObject
  *
  * @return Statement
  */
 protected function parseFileObject(\SplFileObject $fileObject)
 {
     $this->statement = $this->getStatementClass();
     foreach ($fileObject as $line) {
         if ($fileObject->valid()) {
             switch ($this->getLineType($line)) {
                 case self::LINE_TYPE_STATEMENT:
                     $this->parseStatementLine($line);
                     break;
                 case self::LINE_TYPE_TRANSACTION:
                     $transaction = $this->parseTransactionLine($line);
                     $this->statement->addTransaction($transaction);
                     break;
             }
         }
     }
     return $this->statement;
 }
开发者ID:jakubzapletal,项目名称:bank-statements,代码行数:23,代码来源:ABOParser.php

示例9: next

 /**
  * Move forward to next element
  */
 public function next()
 {
     if (null === $this->_file) {
         $this->_openFile();
     }
     if ($this->_file) {
         $this->_key = $this->_key + 1;
         while ($this->_file->valid()) {
             $this->_file->next();
             $this->_filepos = $this->_file->ftell();
             if ($this->_accept()) {
                 $this->_valid = true;
                 return;
             }
         }
     }
     $this->_valid = false;
 }
开发者ID:GemsTracker,项目名称:MUtil,代码行数:21,代码来源:TextFileIterator.php

示例10: parseFile

 public function parseFile($logFile, &$startId, $finish = false)
 {
     if (!$logFile || !file_exists($logFile)) {
         return $this->setError('Log file error');
     }
     try {
         $file = new SplFileObject($logFile);
         $file->seek(!$startId ? 0 : $startId - 1);
         $counter = 0;
         $items = array();
         $item = null;
         while ($file->valid()) {
             $row = trim($file->current());
             $file->next();
             if (!$row) {
                 continue;
             }
             $item = Mage::getModel('mpbackup/backup_progress_item')->parse($row, $item);
             $items[] = $item;
             $counter += $item->getLength();
             if (!$finish && $counter > Mageplace_Backup_Helper_Const::BACKUP_PROCESS_REQUEST_PERIOD * Mageplace_Backup_Helper_Const::BACKUP_PROCESS_RESPONSE_SIZE) {
                 break;
             }
         }
         $startId = $file->key();
     } catch (Exception $e) {
         Mage::logException($e);
         return $this->setError($e->getMessage());
     }
     if (empty($items)) {
         if ($finish) {
             return $this->setError('Log is empty (' . print_r($items, true) . ') and log process is finished');
         } else {
             return $this->setData(self::TEXT, self::TEXT_TREE_POINT)->setError(print_r($items, true));
         }
     }
     return $this->setData(self::ITEMS, $items);
 }
开发者ID:CE-Webmaster,项目名称:CE-Hub,代码行数:38,代码来源:Progress.php

示例11: read

 /**
  * Read a key from the cache
  *
  * @param string $key Identifier for the data
  * @return mixed The cached data, or false if the data doesn't exist, has
  *   expired, or if there was an error fetching it
  */
 public function read($key)
 {
     $key = $this->_key($key);
     if (!$this->_init || $this->_setKey($key) === false) {
         return false;
     }
     if ($this->_config['lock']) {
         $this->_File->flock(LOCK_SH);
     }
     $this->_File->rewind();
     $time = time();
     $cachetime = (int) $this->_File->current();
     if ($cachetime !== false && ($cachetime < $time || $time + $this->_config['duration'] < $cachetime)) {
         if ($this->_config['lock']) {
             $this->_File->flock(LOCK_UN);
         }
         return false;
     }
     $data = '';
     $this->_File->next();
     while ($this->_File->valid()) {
         $data .= $this->_File->current();
         $this->_File->next();
     }
     if ($this->_config['lock']) {
         $this->_File->flock(LOCK_UN);
     }
     $data = trim($data);
     if ($data !== '' && !empty($this->_config['serialize'])) {
         if ($this->_config['isWindows']) {
             $data = str_replace('\\\\\\\\', '\\', $data);
         }
         $data = unserialize((string) $data);
     }
     return $data;
 }
开发者ID:Kononenkomg,项目名称:cakephp,代码行数:43,代码来源:FileEngine.php

示例12: __invoke

 public function __invoke($csvFilePath, $checkLines = 2)
 {
     $file = new \SplFileObject($csvFilePath);
     $delimiters = [',', '\\t', ';', '|', ':'];
     $results = array();
     $i = 0;
     while ($file->valid() && $i <= $checkLines) {
         $line = $file->fgets();
         foreach ($delimiters as $delimiter) {
             $regExp = '/[' . $delimiter . ']/';
             $fields = preg_split($regExp, $line);
             if (count($fields) > 1) {
                 if (!empty($results[$delimiter])) {
                     $results[$delimiter]++;
                 } else {
                     $results[$delimiter] = 1;
                 }
             }
         }
         $i++;
     }
     $results = array_keys($results, max($results));
     return $results[0];
 }
开发者ID:vadimizmalkov,项目名称:visoft-mailer-module,代码行数:24,代码来源:_DetectCsvFileDelimiter.php

示例13: read

 public function read($key)
 {
     if (!$this->is_init || $this->_openFile($key) === false) {
         return false;
     }
     if ($this->settings['lock']) {
         $this->file->flock(LOCK_SH);
     }
     $this->file->rewind();
     $time = time();
     $cachetime = intval($this->file->current());
     //check for expiry
     if ($cachetime !== false && ($cachetime < $time || $time + $this->settings['cache_duration'] < $cachetime)) {
         if ($this->settings['lock']) {
             $this->file->flock(LOCK_UN);
         }
         return false;
     }
     $data = '';
     $this->file->next();
     while ($this->file->valid()) {
         $data .= $this->file->current();
         $this->file->next();
     }
     if ($this->settings['lock']) {
         $this->file->flock(LOCK_UN);
     }
     $data = trim($data);
     if ($data !== '' && !empty($this->settings['serialize'])) {
         if ($this->settings['is_windows']) {
             $data = str_replace('\\\\\\\\', '\\', $data);
         }
         $data = json_decode((string) $data, TRUE);
     }
     return $data;
 }
开发者ID:rossaffandy,项目名称:blockchains.io,代码行数:36,代码来源:cache.php

示例14: valid

 /**
  * {@inheritdoc}
  */
 public function valid()
 {
     return $this->file->valid();
 }
开发者ID:megamanhxh,项目名称:data-import,代码行数:7,代码来源:CsvReader.php

示例15: valid

 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Checks if current position is valid
  * @link http://php.net/manual/en/iterator.valid.php
  * @return boolean The return value will be casted to boolean and then evaluated.
  * Returns true on success or false on failure.
  */
 public function valid()
 {
     if (!is_null($this->line_end_position)) {
         $line = $this->key();
         if ($line > $this->line_end_position) {
             return false;
         }
     }
     return parent::valid();
 }
开发者ID:Talk-Point,项目名称:TPFoundation,代码行数:17,代码来源:File.php


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