/** * * @param string $message * @param string $tag * @param string $date */ public function log($message, $tag = null, $date = null) { if (!is_null($message) && is_string($message) && trim($message) != '') { if (is_null($date)) { $date = date('Y-m-d H:i:s'); } if (is_null($tag)) { $tag = 'LOG'; } else { $tag = strtoupper($tag); } $fileHandler = new FileHandler(); if (!file_exists(ENV_DIR_LOG) || !is_dir(ENV_DIR_LOG)) { $fileHandler->createDirectory(ENV_DIR_LOG); } $filename = ENV_DIR_LOG . '/' . 'log_' . date('Ymd') . '.txt'; $message = str_replace(PHP_EOL, PHP_EOL . "\t", $message); $log = PHP_EOL . "[{$date}] [{$tag}]: {$message}" . PHP_EOL; $fileHandler->writeFile($filename, $log, 'a'); } }
/** * * @param string $filename * @param int $cacheExpire * @param mixed $mode * @throws InvalidArgumentException */ public function cache($filename, $cacheExpire = 0, $mode = 0755) { if (!is_string($filename)) { throw new InvalidArgumentException(I18n::text("Argument 'filename' is invalid.")); } if (!is_int($cacheExpire) || $cacheExpire < 0) { throw new InvalidArgumentException(I18n::text("Argument 'cacheExpire' is invalid.")); } $this->cache = trim($filename); $fileHandler = new FileHandler(); if (file_exists($this->cache) && $cacheExpire > 0) { $cacheExpire += filemtime($this->cache) - 1; if ($cacheExpire < time()) { $fileHandler->removeFile($this->cache); } } if (file_exists($this->cache) && !is_dir($this->cache)) { require_once $this->cache; } else { $dir = dirname($this->cache); if (!file_exists($dir)) { $fileHandler->createDirectory($dir, $mode, true); } } }