本文整理汇总了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);
}
示例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());
}
示例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;
}
示例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('>');
}
示例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);
}
}
示例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));
}
}
示例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());
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}