本文整理汇总了PHP中SplFileObject::rewind方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::rewind方法的具体用法?PHP SplFileObject::rewind怎么用?PHP SplFileObject::rewind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::rewind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSolution
/**
* @return string
*/
public function getSolution()
{
$txt = 'Solution - ' . $this->getName() . ' :' . PHP_EOL;
foreach (array(1, 2) as $part) {
try {
$txt .= '- Part ' . $part . ' : ' . $this->getAnswer($part) . PHP_EOL;
$this->instructionsFile->rewind();
} catch (Exception $exception) {
$txt .= 'Exception while executing part ' . $part . ' : ' . $exception->getMessage() . PHP_EOL;
}
}
return $txt;
}
示例2: rewind
/**
* Rewind the file pointer
*
* If a header row has been set, the pointer is set just below the header
* row. That way, when you iterate over the rows, that header row is
* skipped.
*/
public function rewind()
{
$this->file->rewind();
if (null !== $this->headerRowNumber) {
$this->file->seek($this->headerRowNumber + 1);
}
}
示例3: rewind
/**
* Implements Iterator::rewind().
*/
public function rewind()
{
parent::rewind();
if ($this->startPosition) {
$this->fseek($this->startPosition);
}
$this->linesRead = 0;
}
示例4: finalizeFile
public function finalizeFile(\SplFileObject $fileObject)
{
if ($this->headers !== null) {
// Create tmp file with header
$fd = fopen('php://temp', 'w+b');
fputcsv($fd, $this->headers);
// Copy file content into tmp file
$fileObject->rewind();
fwrite($fd, $fileObject->fread($fileObject->getSize()));
// Overwrite file content with tmp content
rewind($fd);
$fileObject->rewind();
$fileObject->fwrite(stream_get_contents($fd));
clearstatcache(true, $fileObject->getPathname());
fclose($fd);
}
// Remove last line feed
$fileObject->ftruncate($fileObject->getSize() - 1);
}
示例5: testFromAppendixA
/**
* Test the words found in Appendix A from Mr.
* Ntais's thesis.
*
* The words are not tested against the stem reported in the appendix
* but against the results of Mr. Ntais's canonical implementation in js
* found here http://people.dsv.su.se/~hercules/greek_stemmer.gr.html
*/
public function testFromAppendixA()
{
$words = new \SplFileObject(TEST_DATA_DIR . '/Stemmers/GreekStemmerTest/appendix-a-words');
$stems = new \SplFileObject(TEST_DATA_DIR . '/Stemmers/GreekStemmerTest/appendix-a-stems');
$words->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
$stems->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
$stems->rewind();
$stemmer = new GreekStemmer();
$this->checkStemmer($stemmer, $words, $stems);
}
示例6: rewind
public function rewind()
{
parent::rewind();
// If we are getting the first line as columns, take them then skip to
// the next line.
if ($this->_firstLineIsColumns) {
$this->setColumns(parent::current());
parent::next();
}
}
示例7: freeUsedRequestCount
/**
* Free the used slots
*
* @param $sliced_report_definitions_count
*/
private function freeUsedRequestCount($sliced_report_definitions_count)
{
$this->file_counter->flock(LOCK_EX);
$this->file_counter->rewind();
$used_request_count = (int) $this->file_counter->fgets();
$new_used_request_count = $used_request_count - $sliced_report_definitions_count;
$this->file_counter->ftruncate(0);
$this->file_counter->fwrite($new_used_request_count);
$this->file_counter->flock(LOCK_UN);
}
示例8: testStemmer
/**
* Load a set of words and their stems and check if the stemmer
* produces the correct stems
*
* @group Slow
*/
public function testStemmer()
{
$words = new \SplFileObject(TEST_DATA_DIR . '/Stemmers/PorterStemmerTest/words.txt');
$stems = new \SplFileObject(TEST_DATA_DIR . '/Stemmers/PorterStemmerTest/stems.txt');
$words->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
$stems->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
$stems->rewind();
$stemmer = new PorterStemmer();
$this->checkStemmer($stemmer, $words, $stems);
}
示例9: getWritableFile
/**
* Get writable copy of the file
*
* @return SplFileObject
*/
protected function getWritableFile()
{
if ($this->tmpfile === null) {
$this->tmpfile = new \SplTempFileObject(131072);
$this->file->rewind();
foreach ($this->file as $line) {
$this->tmpfile->fwrite($line);
}
}
return $this->tmpfile;
}
示例10: goBeforeCharacter
/**
* {@inheritdoc}
*/
public function goBeforeCharacter(\SplFileObject $file, $characterNumber)
{
$file->rewind();
if ($characterNumber < 0 || $characterNumber > $file->getSize()) {
throw new OutOfBoundsException();
}
for ($i = 0; $i <= $characterNumber - 1; $i++) {
$file->fgetc();
}
return $file;
}
示例11: rewind
/**
* Rewind the \Iterator to the first element
*/
public function rewind()
{
$this->_filepos = null;
$this->_key = 0;
if (null === $this->_file) {
$this->_openFile();
} elseif ($this->_file) {
$this->_file->rewind();
$this->_file->current();
// Reading first line is necessary for correct loading of file.
$this->next();
}
}
示例12: getContent
/**
*
* because \SplFileObject::fread() is not available before 5.5.11 anyway
*
* returns the full content of a file, rewinds pointer in the beginning and leaves it at the end
* but dont rely on this pointer behaviour
*
* @param \SplFileObject $fileObject
*
* @return \SplString|string
*/
public static function getContent(\SplFileObject $fileObject)
{
if (class_exists('SplString')) {
$result = new \SplString();
} else {
$result = '';
}
$fileObject->rewind();
while (!$fileObject->eof()) {
$result .= $fileObject->fgets();
}
return $result;
}
示例13: 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;
}
示例14: testAgainstOriginalSedImplementation
public function testAgainstOriginalSedImplementation()
{
$tokenizer = new PennTreeBankTokenizer();
$tokenized = new \SplFileObject(TEST_DATA_DIR . "/Tokenizers/PennTreeBankTokenizerTest/tokenized");
$tokenized->setFlags(\SplFileObject::DROP_NEW_LINE);
$sentences = new \SplFileObject(TEST_DATA_DIR . "/Tokenizers/PennTreeBankTokenizerTest/test.txt");
$sentences->setFlags(\SplFileObject::DROP_NEW_LINE);
$tokenized->rewind();
foreach ($sentences as $sentence) {
if ($sentence) {
$this->assertEquals($tokenized->current(), implode(" ", $tokenizer->tokenize($sentence)), "Sentence: '{$sentence}' was not tokenized correctly");
}
$tokenized->next();
}
}
示例15: 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;
}