new exceptions and handler for log writer file
Dieser Commit ist enthalten in:
Ursprung
a34f26177e
Commit
ed6b5569fd
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ConLite\Exceptions;
|
||||||
|
|
||||||
|
class FileNotFoundException extends RuntimeException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ConLite\Exceptions;
|
||||||
|
|
||||||
|
class RuntimeException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -2,7 +2,49 @@
|
||||||
|
|
||||||
namespace ConLite\Log;
|
namespace ConLite\Log;
|
||||||
|
|
||||||
|
use ConLite\Exceptions\Exception;
|
||||||
|
use ConLite\Exceptions\FileNotFoundException;
|
||||||
|
|
||||||
class LogWriterFile extends LogWriter
|
class LogWriterFile extends LogWriter
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var resource
|
||||||
|
*/
|
||||||
|
protected $handle = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = []) {
|
||||||
|
parent::__construct($options);
|
||||||
|
|
||||||
|
$this->createHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
* @param int $priority
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function write($message, $priority): bool
|
||||||
|
{
|
||||||
|
return fwrite($this->handle, $message) != false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
*/
|
||||||
|
protected function createHandle(): void
|
||||||
|
{
|
||||||
|
$destination = $this->getOption('destination');
|
||||||
|
if ($destination == '') {
|
||||||
|
throw new Exception('No destination was specified.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($this->handle = fopen($destination, 'a')) === false) {
|
||||||
|
throw new FileNotFoundException('Destination handle could not be created.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren