From a577c01660e0a3ce048f94e07b86c3425e75cac9 Mon Sep 17 00:00:00 2001 From: TS Date: Wed, 14 Jun 2023 15:41:04 +0200 Subject: [PATCH] Updated Log (mkdir) --- src/Log.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Log.php b/src/Log.php index 4aced9c..5d89b68 100644 --- a/src/Log.php +++ b/src/Log.php @@ -33,6 +33,7 @@ class Log protected $type = 'default'; protected $filepath; + protected $filename; protected $config; protected $status = self::INFO; @@ -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); } } @@ -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);