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


PHP SplFileObject::fwrite方法代码示例

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


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

示例1: write

 /**
  * {@inheritdoc}
  */
 public function write($item)
 {
     if (!is_array($item) && !is_scalar($item)) {
         throw new UnsupportedItemTypeException(sprintf('%s only supports items of type scalar or array', __CLASS__));
     }
     $this->file->fwrite(json_encode($item) . PHP_EOL);
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:10,代码来源:JSONFileBuffer.php

示例2: testParseFileObject

 public function testParseFileObject()
 {
     $parser = new ABOParser();
     $reflectionParser = new \ReflectionClass($this->parserClassName);
     $method = $reflectionParser->getMethod('parseFileObject');
     $method->setAccessible(true);
     # Positive statement
     $fileObject = new \SplFileObject(tempnam(sys_get_temp_dir(), 'test_'), 'w+');
     $fileObject->fwrite('0740000000000012345Test s.r.o.         01011400000000100000+00000000080000+00000000060000' . '+00000000040000+002010214              ' . PHP_EOL);
     $fileObject->fwrite('0750000000000012345000000000015678900000000020010000000400002000000001100100000120000000013050114' . 'Tran 1              01102050114' . PHP_EOL);
     $fileObject->fwrite('0750000000000012345000000000025678900000000020020000000600001000000002100200000220000000023070114' . 'Tran 2              01101070114' . PHP_EOL);
     $fileObject->fwrite('0760000000000012345000000000025678900000000020020000000600001000000002100200000220000000023070114' . 'Tran 2              01101070114' . PHP_EOL);
     $statement = $method->invokeArgs($parser, array($fileObject));
     $this->assertInstanceOf('\\JakubZapletal\\Component\\BankStatement\\Statement\\Statement', $statement);
     # Statement
     $this->assertSame($statement, $parser->getStatement());
     $this->assertEquals('12345', $statement->getAccountNumber());
     $this->assertEquals(new \DateTime('2014-01-01 12:00:00'), $statement->getDateLastBalance());
     $this->assertSame(1000.0, $statement->getLastBalance());
     $this->assertSame(800.0, $statement->getBalance());
     $this->assertSame(400.0, $statement->getCreditTurnover());
     $this->assertSame(600.0, $statement->getDebitTurnover());
     $this->assertEquals(2, $statement->getSerialNumber());
     $this->assertEquals(new \DateTime('2014-02-01 12:00:00'), $statement->getDateCreated());
     # Transactions
     $statement->rewind();
     $this->assertCount(2, $statement);
     $transaction = $statement->current();
     $this->assertEquals('156789/1000', $transaction->getCounterAccountNumber());
     $this->assertEquals(2001, $transaction->getReceiptId());
     $this->assertSame(400.0, $transaction->getCredit());
     $this->assertNull($transaction->getDebit());
     $this->assertEquals(11, $transaction->getVariableSymbol());
     $this->assertEquals(12, $transaction->getConstantSymbol());
     $this->assertEquals(13, $transaction->getSpecificSymbol());
     $this->assertEquals('Tran 1', $transaction->getNote());
     $this->assertEquals(new \DateTime('2014-01-05 12:00:00'), $transaction->getDateCreated());
     $transaction = $statement->next();
     $this->assertNull($transaction->getCredit());
     $this->assertSame(600.0, $transaction->getDebit());
     # Negative statement
     $fileObject = new \SplFileObject(tempnam(sys_get_temp_dir(), 'test_'), 'w+');
     $fileObject->fwrite('0740000000000012345Test s.r.o.         01011400000000100000-00000000080000-00000000060000-00000000040000' . '-002010214              ' . PHP_EOL);
     $fileObject->fwrite('0750000000000012345000000000015678900000000020010000000400005000000001100100000120000000013050114' . 'Tran 1              01102050114' . PHP_EOL);
     $fileObject->fwrite('0750000000000012345000000000025678900000000020020000000600004000000002100200000220000000023070114' . 'Tran 2              01101070114' . PHP_EOL);
     $statement = $method->invokeArgs($parser, array($fileObject));
     # Statement
     $this->assertSame(-1000.0, $statement->getLastBalance());
     $this->assertSame(-800.0, $statement->getBalance());
     $this->assertSame(-400.0, $statement->getCreditTurnover());
     $this->assertSame(-600.0, $statement->getDebitTurnover());
     # Transactions
     $statement->rewind();
     $transaction = $statement->current();
     $this->assertSame(-400.0, $transaction->getCredit());
     $transaction = $statement->next();
     $this->assertSame(-600.0, $transaction->getDebit());
 }
开发者ID:jakubzapletal,项目名称:bank-statements,代码行数:58,代码来源:ABOParserTest.php

示例3: createIniFile

function createIniFile($path)
{
    $configFile = new SplFileObject($path . DIRECTORY_SEPARATOR . 'theme', 'w');
    $base = array('Name' => 'Twitch Icons via SpazTwitch', 'Description' => 'Thanks to twitchemotes.com for the API.', 'Icon' => '25.png', 'Author' => 'Omnifox');
    foreach ($base as $k => $v) {
        $configFile->fwrite("{$k}={$v}" . PHP_EOL);
    }
    $configFile->fwrite(PHP_EOL);
    return $configFile;
}
开发者ID:omnifox,项目名称:SpazTwitch,代码行数:10,代码来源:import.php

示例4: writeToStream

 /**
  * {@inheritdoc}
  */
 public function writeToStream(SplFileObject $fileObject, $encryptionKey)
 {
     $value = $this->value;
     if (null !== $encryptionKey) {
         $value = \Bacon\Pdf\Utils\EncryptionUtils::rc4($encryptionKey, $value);
     }
     $fileObject->fwrite('<');
     $fileObject->fwrite(chunk_split(bin2hex($value), 255, "\n"));
     $fileObject->fwrite('>');
 }
开发者ID:jeremiahsmall,项目名称:BaconPdf,代码行数:13,代码来源:HexadecimalStringObject.php

示例5: writeSnapshotEvent

 /**
  * Writes the given snapshotEvent to the {@link #snapshotEventFile}.
  * Prepends a long value to the event in the file indicating the bytes to skip when reading the {@link #eventFile}.
  *
  * @param DomainEventMessageInterface $snapshotEvent The snapshot to write to the {@link #snapshotEventFile}
  * @throws EventStoreException
  */
 public function writeSnapshotEvent(DomainEventMessageInterface $snapshotEvent)
 {
     try {
         $offset = $this->calculateOffset($snapshotEvent);
         $this->snapshotEventFile->fwrite(pack("N", $offset));
         $eventMessageWriter = new FilesystemEventMessageWriter($this->snapshotEventFile, $this->eventSerializer);
         $eventMessageWriter->writeEventMessage($snapshotEvent);
     } catch (\Exception $ex) {
         throw new EventStoreException("Error writing a snapshot event", 0, $ex);
     }
 }
开发者ID:fcm,项目名称:GovernorFramework,代码行数:18,代码来源:FilesystemSnapshotEventWriter.php

示例6: inline

 /**
  * Inline all classes from path to single file
  *
  */
 public function inline($path, $ext, $filename)
 {
     $this->setPath($path);
     $this->setFileExt($ext);
     $classes = $this->readClasses();
     $inlined = new SplFileObject(__DIR__ . '/' . $filename, 'w');
     $inlined->fwrite('<?php');
     foreach ($classes as $class) {
         $inlined->fwrite($this->cleanClass($class));
     }
 }
开发者ID:gwinn,项目名称:inliner,代码行数:15,代码来源:Inliner.php

示例7: testSetWhereValueSetIsntAsLongAsSlice

 public function testSetWhereValueSetIsntAsLongAsSlice()
 {
     $fileObject = new \SplFileObject(__DIR__ . '/Fixtures/lazy_line_' . $this->getFaker()->word . '.txt', 'w+');
     $fileObject->fwrite(str_repeat(' ', 10));
     $fileObject->fwrite("\n");
     $fileObject->fwrite(str_repeat(' ', 10));
     $line = new FileSystemLine($fileObject, 11, 10);
     $line['0:5'] = 'we';
     $this->assertEquals('we        ', (string) $line);
     unlink($fileObject->getRealPath());
 }
开发者ID:SaveYa,项目名称:FixedWidth,代码行数:11,代码来源:FileSystemLineTest.php

示例8: testWriteLine

 /**
  * @return      void
  */
 public function testWriteLine()
 {
     $filePath = __DIR__ . '/example_write1.txt';
     $fileObject = new FileWriter($filePath, 'a+');
     $fileObject->writeLine("foo");
     $fileObject->writeLine("bar");
     $fileObject->writeLine(" some string " . PHP_EOL . "with line breaks \n\r" . PHP_EOL);
     $filePath = __DIR__ . '/example_write2.txt';
     $fileObject = new \SplFileObject($filePath, 'a+');
     $fileObject->fwrite("foo" . PHP_EOL);
     $fileObject->fwrite("bar" . PHP_EOL);
 }
开发者ID:naucon,项目名称:file,代码行数:15,代码来源:FileWriterTest.php

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

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

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

示例12: write

 public function write(\SplFileObject $file, \de\codenamephp\platform\core\file\property\Entries $propertyFile)
 {
     foreach ($propertyFile->getEntries() as $entry) {
         $file->fwrite(sprintf('%s=%s' . PHP_EOL, $entry->getKey(), $entry->getValue()));
     }
     return $this;
 }
开发者ID:codenamephp,项目名称:platform.core,代码行数:7,代码来源:Stream.php

示例13: __invoke

 public function __invoke($file, $minify = null)
 {
     if (!is_file($this->getOptions()->getPublicDir() . $file)) {
         throw new \InvalidArgumentException('File "' . $this->getOptions()->getPublicDir() . $file . '" not found.');
     }
     $less = new \lessc();
     $info = pathinfo($file);
     $newFile = $this->getOptions()->getDestinationDir() . $info['filename'] . '.' . filemtime($this->getOptions()->getPublicDir() . $file) . '.css';
     $_file = $this->getOptions()->getPublicDir() . $newFile;
     if (!is_file($_file)) {
         $globPattern = $this->getOptions()->getPublicDir() . $this->getOptions()->getDestinationDir() . $info['filename'] . '.*.css';
         foreach (Glob::glob($globPattern, Glob::GLOB_BRACE) as $match) {
             if (preg_match("/^" . $info['filename'] . "\\.[0-9]{10}\\.css\$/", basename($match))) {
                 unlink($match);
             }
         }
         $compiledFile = new \SplFileObject($_file, 'w');
         $result = $less->compileFile($this->getOptions()->getPublicDir() . $file);
         if (is_null($minify) && $this->getOptions()->getMinify() || $minify === true) {
             $result = \CssMin::minify($result);
         }
         $compiledFile->fwrite($result);
     }
     return $newFile;
 }
开发者ID:rickkuipers,项目名称:justless,代码行数:25,代码来源:Less.php

示例14: fileNameToSplFile

 public function fileNameToSplFile($filename)
 {
     // Add a Newline to the end of the file (because SplFileObject needs a newline)
     $splFile = new \SplFileObject($filename, 'a+');
     $splFile->fwrite(PHP_EOL);
     return $splFile;
 }
开发者ID:stevenbuehner,项目名称:import-jot-form,代码行数:7,代码来源:JotFormDownloadHelper.php

示例15: getImage

 /**
  * @param string $filename
  * @param string $name
  * @return string
  */
 private function getImage($filename, $name)
 {
     $path = $this->getContainer()->getParameter("upload_dir") . "images/post/";
     $file = new \SplFileObject($path . $name, "w");
     $file->fwrite(file_get_contents($filename));
     return $file->getFilename();
 }
开发者ID:Eraac,项目名称:TP-Blog,代码行数:12,代码来源:ImageCommand.php


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