Пример #1
0
 /**
  * Test stream file
  */
 public function testStreamFile()
 {
     $file = new StreamFile(DATA_PATH . '/log.txt');
     $data = 'Dummy stream test';
     $file->load(function ($chunck) {
     });
     $result = $file->write($data);
     $this->assertEquals(FALSE, $result);
     $result = $file->save();
     $this->assertEquals(FALSE, $result);
     $result = $file->close();
     $this->assertEquals(FALSE, $result);
     $file->open();
     $file->load(function ($chunck) {
     });
     $result = $file->write($data);
     $this->assertEquals(TRUE, $result);
     $expected = strlen($file->getContent());
     $result = $file->save();
     $this->assertEquals($expected, $result);
     $result = $file->close();
     $this->assertEquals(TRUE, $result);
     $file = new StreamFile(DATA_PATH . '/original.jpg');
     $file->open('r');
     $file->load(function ($chunck) {
     });
     $result = $file->close();
     $this->assertEquals(TRUE, $result);
 }
Пример #2
0
 /**
  * Default error handler
  * 
  * @param int    $errno   Give the error number
  * @param string $errstr  Give the error description
  * @param string $errfile Give file from which came the error
  * @param int    $errline Give line from which came the error
  * 
  * @return void|boolean
  */
 public function error($errno, $errstr, $errfile, $errline)
 {
     $msg = '';
     switch ($errno) {
         case E_USER_ERROR:
             $msg = "Duality Fatal Error [{$errno}] {$errstr}" . " on line {$errline} in file {$errfile}\n";
             $msg .= "PHP " . PHP_VERSION . " (" . PHP_OS . ")\n";
             $msg .= "Cannot continue. Aborting...\n";
             // Set error on fatal
             $this->error = true;
             break;
         case E_USER_WARNING:
             $msg = "Duality Warning [{$errno}] {$errstr}" . " on line {$errline} in file {$errfile}\n";
             break;
         default:
             $msg = "Duality Notice [{$errno}] {$errstr}";
             $msg .= !empty($errline) ? " on line {$errline}" : '';
             $msg .= !empty($errfile) ? " in file {$errfile}" : '';
             $msg .= "\n";
             break;
     }
     // Add date to message
     $msg = date('Y-m-d H:i:s') . ": " . $msg;
     // write log to buffer
     $this->stream->write($msg);
     /* Don't execute PHP internal error handler */
     return true;
 }