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


PHP SplFileObject::ftell方法代码示例

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


在下文中一共展示了SplFileObject::ftell方法的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: 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

示例3: 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

示例4: 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

示例5: next

 /**
  * Move forward to next element
  */
 public function next()
 {
     if (null === $this->_file) {
         $this->_openFile();
     }
     if ($this->_file) {
         $this->_key = $this->_key + 1;
         if (!$this->_file->eof()) {
             $this->_file->next();
             $this->_filepos = $this->_file->ftell();
         }
     }
 }
开发者ID:GemsTracker,项目名称:MUtil,代码行数:16,代码来源:FileIteratorAbstract.php

示例6: calculateOffset

 /**
  * Calculate the bytes to skip when reading the event file.
  *
  * @param DomainEventMessageInterface $snapshotEvent the snapshot event
  * @return integer the bytes to skip when reading the event file
  *
  * @throws \Exception
  */
 private function calculateOffset(DomainEventMessageInterface $snapshotEvent)
 {
     try {
         $eventMessageReader = new FilesystemEventMessageReader($this->eventFile, $this->eventSerializer);
         $lastReadSequenceNumber = -1;
         while ($lastReadSequenceNumber < $snapshotEvent->getScn()) {
             $entry = $eventMessageReader->readEventMessage();
             $lastReadSequenceNumber = $entry->getScn();
         }
         return $this->eventFile->ftell();
     } catch (\Exception $ex) {
         throw $ex;
     }
 }
开发者ID:fcm,项目名称:GovernorFramework,代码行数:22,代码来源:FilesystemSnapshotEventWriter.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: 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

示例9: buildIndex

 /**
  * Index the file by getting key/value positions within the file
  *
  * @return array
  */
 public function buildIndex()
 {
     $this->file->flock(LOCK_SH);
     $this->file->fseek(0);
     $indexes = [];
     while (!$this->file->eof()) {
         $position = $this->file->ftell();
         // Grab key and value lengths - if its the last (empty) line, break
         if (!($metadata = $this->getMetadata())) {
             break;
         }
         // Gets the key and adds the key and position to the index
         $indexes[$this->file->fread($metadata->klen)] = $position;
         //Skip over the value, to the next key/value pair
         $this->file->fseek($metadata->vlen, SEEK_CUR);
     }
     $this->file->flock(LOCK_UN);
     return $indexes;
 }
开发者ID:kmfk,项目名称:slowdb,代码行数:24,代码来源:File.php

示例10: getCharacterContent

 /**
  * {@inheritdoc}
  */
 public function getCharacterContent(\SplFileObject $file, $characterNumber)
 {
     $originalPosition = $file->ftell();
     $this->walker->goBeforeCharacter($file, $characterNumber);
     $character = $this->getNextCharacterContent($file);
     $this->walker->goBeforeCharacter($file, $originalPosition);
     return $character;
 }
开发者ID:Babacooll,项目名称:TextFile,代码行数:11,代码来源:SimpleReader.php

示例11: fetchTasks

 /**
  * @param int $limit
  *
  * @return Task[]
  *
  * @throws \RuntimeException
  */
 protected function fetchTasks($limit)
 {
     $logger = Logger::getLogger('file-queue');
     $statusFileObject = $this->getStatusFileObject();
     if (!$statusFileObject->flock(LOCK_EX)) {
         throw new \RuntimeException("Can't get lock for status file {$this->getStatusFile()}");
     }
     $seek = $statusFileObject->fgets();
     if ($seek === false) {
         throw new \RuntimeException("Can't get seek from status file {$this->getStatusFile()}");
     }
     if (!$seek) {
         $seek = 0;
     }
     $seek = (int) $seek;
     $tasksFileObject = new \SplFileObject($this->getTasksFile(), 'r');
     if ($tasksFileObject->fseek($seek) !== 0) {
         throw new \RuntimeException("Can't seek to {$seek} in tasks file {$this->getTasksFile()}");
     }
     $logger->debug("Current seek {$seek}");
     $tasks = [];
     $taskNumber = 0;
     while ($taskNumber < $limit && !$tasksFileObject->eof()) {
         $this->getProcessor()->getSignalHandler()->dispatch();
         $row = $tasksFileObject->fgetcsv();
         if ($row === false) {
             throw new \RuntimeException("Can't get row from file {$this->getTasksFile()}");
         }
         // пропускаем пустые строки
         if (!$row || $row === [null]) {
             continue;
         }
         $seek = $tasksFileObject->ftell();
         if ($seek === false) {
             throw new \RuntimeException("Can't get seek from file {$this->getTasksFile()}");
         }
         if (count($row) < 2) {
             $eventId = $row[0];
             $data = null;
         } else {
             list($eventId, $data) = $row;
         }
         $tasks[] = new Task($eventId, $data);
         ++$taskNumber;
     }
     if ($statusFileObject->fseek(0) !== 0) {
         throw new \RuntimeException("Can't seek to 0 in status file {$this->getStatusFile()}");
     }
     if (!$statusFileObject->ftruncate(0)) {
         throw new \RuntimeException("Can't truncate status file {$this->getStatusFile()}");
     }
     if (!$statusFileObject->fwrite($seek)) {
         throw new \RuntimeException("Can't write new seek {$seek} to status file {$this->getStatusFile()}");
     }
     $logger->debug("New seek {$seek}");
     if (!$statusFileObject->flock(LOCK_UN)) {
         $logger->warn("Can't release lock");
     }
     return $tasks;
 }
开发者ID:mailru,项目名称:queue-processor,代码行数:67,代码来源:FileQueue.php

示例12: exportLCRun

 /**
  * Internal method used by compile(). Export required standalone functions.
  *
  * @param array<string,array|string|integer> $context current compile context
  *
  * @return string
  */
 protected static function exportLCRun($context)
 {
     if ($context['flags']['standalone'] == 0) {
         return '';
     }
     $class = new ReflectionClass($context['lcrun']);
     $fname = $class->getFileName();
     $lines = file_get_contents($fname);
     $file = new SplFileObject($fname);
     $methods = array();
     $ret = "'funcs' => array(\n";
     foreach ($class->getMethods() as $method) {
         $name = $method->getName();
         $file->seek($method->getStartLine() - 2);
         $spos = $file->ftell();
         $file->seek($method->getEndLine() - 2);
         $epos = $file->ftell();
         $methods[$name] = static::scanLCRunDependency($context, preg_replace('/public static function (.+)\\(/', '\'$1\' => function (', substr($lines, $spos, $epos - $spos)));
     }
     unset($file);
     $exports = array_keys($context['usedCount']['lcrun']);
     while (true) {
         if (array_sum(array_map(function ($name) use(&$exports, $methods) {
             $n = 0;
             foreach ($methods[$name][1] as $child => $count) {
                 if (!in_array($child, $exports)) {
                     $exports[] = $child;
                     $n++;
                 }
             }
             return $n;
         }, $exports)) == 0) {
             break;
         }
     }
     foreach ($exports as $export) {
         $ret .= $methods[$export][0] . "    },\n";
     }
     return "{$ret})\n";
 }
开发者ID:wake-up-neo,项目名称:php-xframework,代码行数:47,代码来源:LightnCandy.php

示例13: array

$fields = array(array('water_fruit\\n'), array("water_fruit\n"), array(""));
$file_path = dirname(__FILE__);
$file = "{$file_path}/fputcsv_variation10.tmp";
$file_modes = array("r+", "r+b", "r+t", "a+", "a+b", "a+t", "w+", "w+b", "w+t", "x+", "x+b", "x+t");
$loop_counter = 1;
foreach ($fields as $field) {
    for ($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
        echo "\n-- file opened in {$file_modes[$mode_counter]} --\n";
        // create the file and add the content with has csv fields
        if (strstr($file_modes[$mode_counter], "r")) {
            $fo = new SplFileObject($file, 'w');
        } else {
            $fo = new SplFileObject($file, $file_modes[$mode_counter]);
        }
        $csv_field = $field;
        // write to a file in csv format
        var_dump($fo->fputcsv($csv_field));
        // check the file pointer position and eof
        var_dump($fo->ftell());
        var_dump($fo->eof());
        //close the file
        unset($fo);
        // print the file contents
        var_dump(file_get_contents($file));
        //delete file
        unlink($file);
    }
    //end of mode loop
}
// end of foreach
echo "Done\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:SplFileObject_fputcsv_variation10.php

示例14: getSize

 public function getSize()
 {
     $this->store->fseek(0, SEEK_END);
     return $this->store->ftell();
 }
开发者ID:pguilford,项目名称:vcomcc,代码行数:5,代码来源:streambuffer.php

示例15: grow_generic


//.........这里部分代码省略.........
             // it will be zero on the first step and then would be passed back in
             // as a parameter on subsequent steps based on where in the file the previous
             // step reached.
             // TODO: Maybe a sanity check to make sure position seems tenable
             try {
                 $contentfile = new SplFileObject($contentfile_name, "rb");
                 $contentfile->fseek($contentfile_fp);
                 // Helper keeps track of what is being added to the burst content and will
                 // tell us when the content is sufficient for this burst based on it's
                 // criteria - this can adapt to how each successive burst goes.
                 while (!$contentfile->eof() && false === $zm->burst_content_complete()) {
                     // Should be at least one item to grab from the list and then move to next
                     // and remember it for if we drop out because burst content complete, in
                     // that case we'll return to that point in the file at the next burst start.
                     // Check for unserialize failure and bail
                     $item = @unserialize($contentfile->current());
                     if (false === $item) {
                         throw new Exception('Unserialization of content list data failed: `' . $contentfile->current() . '`');
                     }
                     $contentfile->next();
                     $file = $item['relative_path'] . $item['filename'];
                     // We shouldn't have any empty items here as we should have removed them
                     // earlier, but just in case...
                     if (!empty($file)) {
                         $ilist[] = $file;
                         // Call the helper event handler as we add each file to the list
                         $zm->burst_content_added($item);
                     }
                 }
                 // Burst list is completed by way of end of content list file or size threshold
                 if (!$contentfile->eof()) {
                     // We haven't exhausted the content list yet so remember where we
                     // are at for next burst (which may be in a following step)
                     $contentfile_fp = $contentfile->ftell();
                 } else {
                     // Exhausted the content list so make sure we drop out after this burst
                     // if we don't break out of the loop due to a zip error or reached step
                     // duration limit. We must not schedule a new step if this burst has
                     // exhausted the contents file.
                     $have_more_content = false;
                 }
                 // Finished one way or another so close content list file for this burst
                 unset($contentfile);
             } catch (Exception $e) {
                 // Something fishy - we should have been able to open the content file...
                 // TODO: We need to bail out totally here I think
                 $error_string = $e->getMessage();
                 $this->log('details', sprintf(__('Zip process reported: Zip content list file could not be opened/read - error reported: %1$s', 'it-l10n-backupbuddy'), $error_string));
                 $exitcode = 255;
                 $zip_error_encountered = true;
                 break;
             }
             // Retain this for reference for now
             //file_put_contents( ( dirname( $tempdir ) . DIRECTORY_SEPARATOR . self::ZIP_CONTENT_FILE_NAME ), print_r( $ilist, true ) );
             // Make sure we expunge any previous version of the inclusions file
             if (file_exists($ifile)) {
                 @unlink($ifile);
             }
             // Slight kludge for now to make sure each burst content file is uniquely named
             $ifile = str_replace(".txt", "_" . $zm->get_burst_count() . ".txt", $master_ifile);
             $file_ok = @file_put_contents($ifile, implode(PHP_EOL, $ilist) . PHP_EOL);
             if (false === $file_ok || 0 === $file_ok) {
                 // The file write failed for some reason, e.g., no disk space? We need to
                 // bail and set exit code so that problem is apparent
                 $this->log('details', sprintf(__('Zip process reported: Unable to write burst content file: `%1$s`', 'it-l10n-backupbuddy'), $ifile));
                 $exitcode = 255;
开发者ID:Coop920,项目名称:Sterling-Wellness,代码行数:67,代码来源:zbzipexec.php


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