Added exception when file could not be created

This commit is contained in:
Florian Bouillon 2019-04-26 15:25:04 +02:00
parent c71600aa66
commit 37f62ba892
2 changed files with 17 additions and 4 deletions

View File

@ -0,0 +1,9 @@
<?php
namespace DeltaCMS\Exception;
use Exception;
class FileException extends Exception
{
}

View File

@ -6,6 +6,7 @@ use Psr\Log\AbstractLogger;
use Psr\Log\InvalidArgumentException; use Psr\Log\InvalidArgumentException;
use Exception; use Exception;
use DeltaCMS\Exception\FileException;
class Logger extends AbstractLogger class Logger extends AbstractLogger
{ {
@ -28,11 +29,14 @@ class Logger extends AbstractLogger
public function __construct($file = "./logs.log") public function __construct($file = "./logs.log")
{ {
if (!file_exists($file)) { if (!file_exists($file)) {
$ressource = fopen($file, 'w'); try {
if ($ressource === false) { $ressource = fopen($file, 'w');
throw new Exception("File at " . $file . " can't be created. exiting", 1); if ($ressource !== false) {
fclose($ressource);
}
} catch (Exception $e) {
throw new FileException("File can't be created");
} }
fclose($ressource);
} }
$this->file = $file; $this->file = $file;
} }