From 4f344065bf3e2cb928feeeef7f899c9aaf89e25e Mon Sep 17 00:00:00 2001 From: akaunderr Date: Fri, 29 Dec 2023 16:02:13 +0200 Subject: [PATCH] removed obsolete cache cleanup --- CHANGELOG.md | 4 ++++ TODO.md | 3 +++ src/ShrinkWrap.php | 39 ++++++--------------------------------- 3 files changed, 13 insertions(+), 33 deletions(-) create mode 100644 TODO.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 647f049..ef6639b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.0.3 (2023.12.29) +### Removed +- Obsolete cache cleanup. + ## 0.0.2 (2023.12.28) ### Fixed - Error message while log (by null coalescing). diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..5ae6e5d --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +# To-Do + +- Obsolete cache cleanup. It is necessary to decide whether it is needed or whether to run it from the outside... diff --git a/src/ShrinkWrap.php b/src/ShrinkWrap.php index 6f6c0aa..a965489 100644 --- a/src/ShrinkWrap.php +++ b/src/ShrinkWrap.php @@ -417,8 +417,6 @@ private function minRefByType(string $type = 'js'): void { $minifier = $this->{$type . 'Minifier'}->init(); $minifier->add($fname); $minifier->minify($mfile); - - $this->clearPrev($fname); } if ($this->doLog) { @@ -444,8 +442,6 @@ private function minRefByType(string $type = 'js'): void { } $minifier->minify($mfile); - - $this->clearPrev($mfile); } if ($this->doLog) { @@ -473,48 +469,25 @@ private function minRefByType(string $type = 'js'): void { } /** - * Returns the full path and name of the minified file. + * Returns path to minified file by source file name. * - * @param string $fname The name of a file that will be minified + * @param string $file Name or full path of a file to be minified * - * @return string The name of the minified file + * @return string Minified file path */ - private function getMfile(string $fname): string { - $finfo = pathinfo($fname); + private function getMfile(string $file): string { + $finfo = pathinfo($file); if (preg_match('/[0-9a-f]{32}/i', explode('.', $finfo['filename'])[0])) { $finfo['filename'] = explode('.', $finfo['filename'])[0]; $tmpl = '.min.' . $finfo['extension']; } else { - $tmpl = '_' . filemtime($fname) . '.min.' . $finfo['extension']; + $tmpl = '_' . filemtime($file) . '.min.' . $finfo['extension']; } return $this->assetDir . $finfo['filename'] . $tmpl; } - /** - * Clear out of date minified files. - * - * @param string (optional) $fname File name to delete from cache - */ - private function clearPrev(string $fname = ''): void { - if ($fname) { - $finfo = pathinfo($fname); - - if (preg_match('/[0-9a-f]{32}/i', $finfo['filename'])) { - $files = glob($this->assetDir . '*.' . $finfo['extension']); - } else { - $files = glob($this->assetDir . $finfo['filename'] . '*.' . $finfo['extension']); - } - - foreach ($files as $file) { - if (is_file($file) && $file != $this->getMfile($fname)) { - @unlink($file); - } - } - } - } - /** * @param string[] $files File list *