예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function write()
 {
     $path = LogFile::getPathFromName($this->record->getName());
     if (($test = File::prepare($path, 0775)) !== true) {
         throw new Exception("failed to write log file '{$path}'; {$test}");
     }
     $line = LogFile::encodeRecord($this->record);
     if (!@file_put_contents($path, "{$line}\n", FILE_APPEND)) {
         throw new Exception("failed to write log '{$path}': {$line}");
     }
 }
예제 #2
0
 /**
  * Encode a variable as JSON and write it to a file
  * 
  * @param string $path An absolute path to the file to write
  * @param mixed $data The variable to encode
  * @param bitmask $options json_encode options
  * @return boolean|string
  * @return boolean:true The variable was encoded and written successfully
  * @return string An error message describing the failure
  */
 public static function encodeFile($path, $data, $options = 0)
 {
     if (($test = File::prepare($path)) !== true) {
         $err = $test;
     } else {
         if (($json = json_encode($data, $options)) === false) {
             $err = self::getError();
         } else {
             if (@file_put_contents($path, $json) === false) {
                 $err = "write operation failed on '{$path}'";
             } else {
                 return true;
             }
         }
     }
     return "failed to encode JSON file; {$err}";
 }