Skip to content

Commit

Permalink
Merge pull request #11 from Clavicula-Nox/1.0.2
Browse files Browse the repository at this point in the history
1.0.2 Version
  • Loading branch information
Tydesson authored Apr 26, 2018
2 parents 36a94c3 + f5d8728 commit ee17389
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
26 changes: 19 additions & 7 deletions Classes/Services/Cache/FileSystemCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class FileSystemCacheService
/* @var Filesystem */
private $Filesystem;

/* @var array */
private static $CacheArray = [
'created' => 0,
'ttl' => 0,
'datas' => null,
];

/**
* FileSystemCacheService constructor.
*
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions Classes/Services/Tools/CSVManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions Classes/Services/Tools/StringManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -117,8 +117,6 @@ public function removeCharsKeepInts($string)

/**
* @param string $string
* @param bool $keepTags
* @param array $allowedTags
*
* @return string
*/
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ee17389

Please sign in to comment.