diff --git a/Classes/Services/Cache/FileSystemCacheService.php b/Classes/Services/Cache/FileSystemCacheService.php index 53ead10..6f129c4 100644 --- a/Classes/Services/Cache/FileSystemCacheService.php +++ b/Classes/Services/Cache/FileSystemCacheService.php @@ -31,6 +31,13 @@ class FileSystemCacheService /* @var Filesystem */ private $Filesystem; + /* @var array */ + private static $CacheArray = [ + 'created' => 0, + 'ttl' => 0, + 'datas' => null, + ]; + /** * FileSystemCacheService constructor. * @@ -51,6 +58,8 @@ public function __construct(string $cachePath, string $cacheChmod, int $cacheDef if (!is_writable($this->PathToCache)) { throw new AccessDeniedException($this->PathToCache); } + } elseif (!is_writable($this->PathToCache)) { + throw new AccessDeniedException($this->PathToCache); } } @@ -87,12 +96,10 @@ public function set(string $key, $datas, int $ttl = -1): void if (-1 === $ttl) { $ttl = $this->DefaultTTL; } - - $cache = array( - 'created' => time(), - 'ttl' => $ttl, - 'datas' => $datas, - ); + $cache = self::$CacheArray; + $cache['created'] = time(); + $cache['ttl'] = $ttl; + $cache['datas'] = $datas; $cache = $this->convertToCache($cache); $this->writeCacheFile($this->getCacheFilePath($key), $cache); @@ -164,6 +171,11 @@ private function convertToCache(array $content): string */ private function getDatasFromCache(string $content): array { - return json_decode($content, true); + $cache = json_decode($content, true); + if (!is_array($cache)) { + $cache = self::$CacheArray; + } + + return $cache; } } diff --git a/Classes/Services/Tools/CSVManager.php b/Classes/Services/Tools/CSVManager.php index 5a8182c..7c12917 100644 --- a/Classes/Services/Tools/CSVManager.php +++ b/Classes/Services/Tools/CSVManager.php @@ -47,6 +47,9 @@ public function getCSV(string $filePath, string $delim = ';'): array while (false !== ($line = fgetcsv($fileHandler, 4096, $delim))) { $count = count($line); for ($j = 0; $j < $count; ++$j) { + if (!mb_detect_encoding($line[$j], 'UTF-8')) { + $line[$j] = utf8_encode($line[$j]); + } $return[$i][$j] = $line[$j]; } ++$i; diff --git a/Classes/Services/Tools/StringManager.php b/Classes/Services/Tools/StringManager.php index cbefdd5..eb203cb 100644 --- a/Classes/Services/Tools/StringManager.php +++ b/Classes/Services/Tools/StringManager.php @@ -84,8 +84,8 @@ public function washString(string $string): string public function removeAccents($string) { $string = str_replace( - array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'), - array('A', 'A', 'A', 'A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'a', 'O', 'O', 'O', 'O', 'O', 'O', 'o', 'o', 'o', 'o', 'o', 'o', 'E', 'E', 'E', 'E', 'e', 'e', 'e', 'e', 'C', 'c', 'I', 'I', 'I', 'I', 'i', 'i', 'i', 'i', 'U', 'U', 'U', 'U', 'u', 'u', 'u', 'u', 'y', 'N', 'n'), + ['À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'], + ['A', 'A', 'A', 'A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'a', 'O', 'O', 'O', 'O', 'O', 'O', 'o', 'o', 'o', 'o', 'o', 'o', 'E', 'E', 'E', 'E', 'e', 'e', 'e', 'e', 'C', 'c', 'I', 'I', 'I', 'I', 'i', 'i', 'i', 'i', 'U', 'U', 'U', 'U', 'u', 'u', 'u', 'u', 'y', 'N', 'n'], $string ); @@ -117,8 +117,6 @@ public function removeCharsKeepInts($string) /** * @param string $string - * @param bool $keepTags - * @param array $allowedTags * * @return string */ @@ -203,15 +201,15 @@ public function niceSubStr(string $string, int $length = 200): string public function stringToLabel(string $string): string { $string = self::washString($string); - $toReplace = [',', ';', '.', ':', '°', '-', '_', "'", '"', '&', ' ', '/', '\\', '@', '$', '%', '£', '¤', 'µ', '*', '!', '§']; - $string = str_replace($toReplace, ' ', $string); $string = self::removeAccents($string); $stringArray = explode(' ', $string); + foreach ($stringArray as $key => $value) { $stringArray[$key] = ucfirst(strtolower($value)); } $string = implode(' ', $stringArray); + $string = self::cleanString($string); $string = str_replace(' ', '', $string); return (string) $string;