Skip to content

Commit

Permalink
Updated Log (mkdir)
Browse files Browse the repository at this point in the history
  • Loading branch information
TS committed Jun 14, 2023
1 parent cdef6a3 commit a577c01
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Log

protected $type = 'default';
protected $filepath;
protected $filename;
protected $config;
protected $status = self::INFO;

Expand Down Expand Up @@ -207,22 +208,18 @@ protected function setPath()
$this->config['folder'] = dirname(__DIR__) . self::DS . 'logs';
}

$path = \stripslashes(implode('', [
$filepath = (implode('', [
$this->config['folder'],
$this->setVariables($this->config['pattern_file']),
'.',
$this->config['extension']
]));

$parts = explode(\DIRECTORY_SEPARATOR, $path);
$parts = array_map('trim', $parts);
$this->filepath = dirname($filepath);
$this->filename = basename($filepath);

$this->filepath = implode(\DIRECTORY_SEPARATOR, $parts);

$basefolder = pathinfo($this->filepath, PATHINFO_DIRNAME);

if (!file_exists($basefolder)) {
mkdir($basefolder, !empty($this->config['folder_chmod']) ? $this->config['folder_chmod'] : 0770, true);
if (!file_exists($this->filepath)) {
mkdir($this->filepath, !empty($this->config['folder_chmod']) ? $this->config['folder_chmod'] : 0770, true);
}
}

Expand All @@ -244,7 +241,7 @@ protected function addMessage($message, $status = null, $title = null)
$this->setPath();

$row = $this->setVariables($this->config['pattern_row'], $message, $title);
$filepath = trim($this->filepath);
$filepath = realpath($this->filepath) . self::DS . $this->filename;

if (!file_exists($filepath) && !empty($this->config['header'])) {
file_put_contents($filepath, $this->config['header'] . PHP_EOL, FILE_APPEND);
Expand Down

0 comments on commit a577c01

Please sign in to comment.