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


PHP SplFileObject::fseek方法代码示例

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


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

示例1: getFile

 /**
  * Get an SplFileObject representing the file to be read.
  *
  * @return \SplFileObject The log file object.
  */
 protected function getFile()
 {
     if (!isset($this->file)) {
         $this->file = new \SplFileObject($this->path, 'r');
         $this->file->fseek(0, SEEK_END);
         $this->cursor = $this->file->ftell();
     }
     return $this->file;
 }
开发者ID:zroger,项目名称:feather,代码行数:14,代码来源:FileReader.php

示例2: getTotal

 /**
  * @return int
  */
 public function getTotal()
 {
     if ($this->total === null) {
         $this->csvFile->fseek(0);
         $lines = 0;
         while (!$this->csvFile->eof()) {
             $lines += substr_count($this->csvFile->fread(8192), $this->lineSeparator);
         }
         $this->total = (int) $lines;
     }
     return $this->total;
 }
开发者ID:spryker,项目名称:Library,代码行数:15,代码来源:CsvMeta.php

示例3: getFile

 /**
  * @inheritdoc
  */
 public function getFile()
 {
     if ($this->file === null) {
         try {
             $this->file = new TempFile();
             $this->file->fwrite($this->data);
             $this->file->fseek(0);
         } catch (\RuntimeException $e) {
             throw new TransportException($e->getMessage(), null, $e);
         }
     }
     return $this->file;
 }
开发者ID:treehouselabs,项目名称:feeder,代码行数:16,代码来源:StringResource.php

示例4: readSnapshotEvent

 /**
  * Reads the latest snapshot of the given aggregate identifier.
  *
  * @param string $type       the aggregate's type
  * @param string $identifier the aggregate's identifier
  * @return SerializedDomainEventDataInterface The latest snapshot of the given aggregate identifier
  *
  * @throws EventStoreException when reading the <code>snapshotEventFile</code> or reading the <code>eventFile</code> failed
  */
 public function readSnapshotEvent($type, $identifier)
 {
     $snapshotEvent = null;
     $fileSystemSnapshotEvent = $this->readLastSnapshotEntry();
     if (null !== $fileSystemSnapshotEvent) {
         $this->eventFile->fseek($fileSystemSnapshotEvent['bytesToSkip']);
         $actuallySkipped = $this->eventFile->ftell();
         if ($actuallySkipped !== $fileSystemSnapshotEvent['bytesToSkip']) {
             throw new EventStoreException(sprintf("The skip operation did not actually skip the expected amount of bytes. " . "The event log of aggregate of type %s and identifier %s might be corrupt.", $type, $identifier));
         }
         $snapshotEvent = $fileSystemSnapshotEvent['snapshotEvent'];
     }
     return $snapshotEvent;
 }
开发者ID:fcm,项目名称:GovernorFramework,代码行数:23,代码来源:FilesystemSnapshotEventReader.php

示例5: _openFile

 /**
  * Open the file and optionally restore the position
  *
  * @return void
  */
 private function _openFile()
 {
     $this->_fieldMap = array();
     $this->_fieldMapCount = 0;
     if (!file_exists($this->_filename)) {
         $this->_file = false;
         return;
     }
     try {
         $this->_file = new \SplFileObject($this->_filename, 'r');
         $firstline = trim(\MUtil_Encoding::removeBOM($this->_file->current(), "\r\n"));
         if ($firstline) {
             $this->_fieldMap = call_user_func($this->_splitFunction, $firstline);
             $this->_fieldMapCount = count($this->_fieldMap);
             // Check for fields, do not run when empty
             if (0 === $this->_fieldMapCount) {
                 $this->_file = false;
                 return;
             }
         }
         // Restore old file position if any
         if (null !== $this->_filepos) {
             $this->_file->fseek($this->_filepos, SEEK_SET);
         }
         // Always move to next, even if there was no first line
         $this->next();
     } catch (\Exception $e) {
         $this->_file = false;
     }
 }
开发者ID:GemsTracker,项目名称:MUtil,代码行数:35,代码来源:TextFileIterator.php

示例6: insertOne

 /**
  * Adds a single line to a CSV document
  *
  * @param string[]|string $row a string, an array or an object implementing to '__toString' method
  *
  * @return static
  */
 public function insertOne($row)
 {
     if (!is_array($row)) {
         $row = str_getcsv($row, $this->delimiter, $this->enclosure, $this->escape);
     }
     $row = $this->formatRow($row);
     $this->validateRow($row);
     if (is_null($this->csv)) {
         $this->csv = $this->getIterator();
     }
     $this->csv->fputcsv($row, $this->delimiter, $this->enclosure);
     if ("\n" !== $this->newline) {
         $this->csv->fseek(-1, SEEK_CUR);
         $this->csv->fwrite($this->newline);
     }
     return $this;
 }
开发者ID:raynaldmo,项目名称:php-education,代码行数:24,代码来源:Writer.php

示例7: modifyFileLine

function modifyFileLine($filename, $linenum, $lineText)
{
    $fp = new SplFileObject($filename);
    $fp->seek($linenum);
    $line = $fp->current();
    $fp->fseek($linenum, SEEK_CUR);
    $fp->fwrite($lineText);
}
开发者ID:nirvana-info,项目名称:old_bak,代码行数:8,代码来源:sitemap_generator.php

示例8: putCSVRecord

 /**
  * フィールドの配列をCSVの行として書き出します。
  * @param \SplFileObject $file
  * @param string[] $fields
  */
 protected function putCSVRecord(\SplFileObject $file, array $fields)
 {
     $file->fputcsv(array_map(function (string $field) : string {
         return preg_replace('/[\\x00-\\x09\\x11\\x7F]+/u', '', strtr($field, ["\r\n" => "\r\n", "\r" => "\r\n", "\n" => "\r\n"]));
     }, $fields));
     $file->fseek(-1, SEEK_CUR);
     $file->fwrite("\r\n");
 }
开发者ID:esperecyan,项目名称:dictionary-php,代码行数:13,代码来源:GenericDictionarySerializer.php

示例9: rewind

 /**
  * @param bool $skipColumns
  *
  * @return void
  */
 public function rewind($skipColumns = true)
 {
     $this->csvFile->fseek(0);
     if ($skipColumns) {
         $this->getFile()->fseek($this->getCsvMeta()->getColumnsOffset());
         return;
     }
 }
开发者ID:spryker,项目名称:Library,代码行数:13,代码来源:CsvReader.php

示例10: content

 private function content(SplFileObject $file)
 {
     $result = "";
     $file->fseek(0);
     while (!$file->eof()) {
         $result .= $file->fread(1024);
     }
     return $result;
 }
开发者ID:loopsframework,项目名称:base,代码行数:9,代码来源:LoopsApplicationLoopsAdminTest.php

示例11: getCoverageObject

 /**
  * Returns coverage object from file.
  *
  * @param \SplFileObject $coverageFile Coverage file.
  *
  * @return \PHP_CodeCoverage|CodeCoverage
  */
 private function getCoverageObject(\SplFileObject $coverageFile)
 {
     if ('<?php' === $coverageFile->fread(5)) {
         return include $coverageFile->getRealPath();
     }
     $coverageFile->fseek(0);
     // the PHPUnit 3.x and below
     return unserialize($coverageFile->fread($coverageFile->getSize()));
 }
开发者ID:brianium,项目名称:paratest,代码行数:16,代码来源:CoverageMerger.php

示例12: testWriteMiddleNewLine

 /**
  * @covers TextFile\Writer\ErasingWriter::write
  */
 public function testWriteMiddleNewLine()
 {
     $prependingWriter = new PrependingWriter();
     $filePath = $this->createTestFileFromFixtures('complex_singleline_file.txt');
     $file = new \SplFileObject($filePath, 'r+');
     $file->fseek(5);
     $prependingWriter->write($file, 'test', true);
     $file->rewind();
     $this->assertEquals('firsttest', trim($file->current()));
     $file->next();
     $this->assertEquals('secondthirdfourthfifth', trim($file->current()));
 }
开发者ID:Babacooll,项目名称:TextFile,代码行数:15,代码来源:PrependingWriterTest.php

示例13: getMetadata

 /**
  * Retrieves the Metadata for a Key/Value pair
  *
  * Optionally allows a specific position offset in the file
  * Return Array
  *     - klen: The length of the Key
  *     - vlen: The length of the Value
  *     - length: The total combined length of the Key and the Value
  *
  * @param  integer $position  An offset to seek to in a file
  *
  * @return array|bool
  */
 protected function getMetadata($position = null)
 {
     if (!is_null($position)) {
         $this->file->fseek($position);
     }
     $metadata = $this->file->fread(8);
     if ($metadata) {
         list(, $klen, $vlen) = unpack('N*', $metadata);
         return (object) ['klen' => $klen, 'vlen' => $vlen, 'length' => $klen + $vlen];
     }
     return false;
 }
开发者ID:kmfk,项目名称:slowdb,代码行数:25,代码来源:File.php

示例14: merge

 /**
  * This method merges the data in another array with this array.
  *
  * @access public
  */
 public function merge()
 {
     $arrays = func_get_args();
     $this->writer->fseek($this->writer->ftell());
     foreach ($arrays as $values) {
         if (is_array($values)) {
             foreach ($values as $value) {
                 $this->writer->fwrite(serialize($value) . PHP_EOL);
             }
         }
         $this->length += count($values);
     }
 }
开发者ID:bluesnowman,项目名称:Chimera,代码行数:18,代码来源:StoredList.php

示例15: write

 /**
  * {@inheritdoc}
  */
 public function write(\SplFileObject $file, $text, $newLineAtEnd = false)
 {
     $originalSeek = $file->ftell();
     // Refresh file size
     clearstatcache($file->getFilename());
     if ($file->getSize() - $file->ftell() > 0) {
         $contentAfter = $file->fread($file->getSize() - $file->ftell());
     } else {
         $contentAfter = '';
     }
     $file->fseek($originalSeek);
     $file->fwrite($text . ($newLineAtEnd ? PHP_EOL : ''));
     $file->fwrite($contentAfter);
     return $file;
 }
开发者ID:Babacooll,项目名称:TextFile,代码行数:18,代码来源:PrependingWriter.php


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