Beispiel #1
0
 /**
  * @return      array
  */
 public function testWrite()
 {
     $string = 'Line01' . PHP_EOL;
     $string .= 'Line02' . PHP_EOL;
     $string .= 'Line03' . PHP_EOL;
     $string .= 'Line04' . PHP_EOL;
     $filePath = __DIR__ . '/example_write1.txt';
     $fileObject1 = new FileWriter($filePath, 'w+');
     $fileObject1->write($string);
     $filePath = __DIR__ . '/example_write2.txt';
     $fileObject2 = new \SplFileObject($filePath, 'w+');
     $fileObject2->fwrite($string);
     return $fileObject1;
 }
Beispiel #2
0
 /**
  * @access      protected
  * @param       string                  log record string
  * @return      void
  */
 protected function writeRecord($logRecordString)
 {
     $fileWriterObject = new FileWriter($this->getFileObject(), 'a');
     $fileWriterObject->write($logRecordString);
 }
Beispiel #3
0
 /**
  * @access      protected
  * @param       string                  log record string
  * @return      void
  */
 protected function writeRecord($logRecordString)
 {
     $fileWriterObject = new FileWriter(ini_get('error_log'), 'a');
     $fileWriterObject->write($logRecordString);
 }
Beispiel #4
0
<?php

$filePath = __DIR__ . '/example_write.txt';
use Naucon\File\FileWriter;
$fileObject = new FileWriter($filePath, 'w+');
// file point at the beginning of the file, truncate existing content
echo 'File: ' . $fileObject->getPathname();
echo '<br/>';
echo '<br/>';
$string = 'Line01' . PHP_EOL;
$string .= 'Line02' . PHP_EOL;
$string .= 'Line03' . PHP_EOL;
$string .= 'Line04' . PHP_EOL;
$fileObject->write($string);
foreach ($fileObject as $line) {
    echo $line . '<br/>';
}
echo '<br/>';
//Line01
//Line02
//Line03
//Line04
$filePath = __DIR__ . '/example_write.txt';
$fileObject = new FileWriter($filePath, 'a+');
// file point at the end of the file
$fileObject->writeLine("foo");
$fileObject->writeLine("bar");
foreach ($fileObject as $line) {
    echo $line . '<br/>';
}
echo '<br/>';