This commit is contained in:
Dennis Eichhorn 2016-10-31 10:14:25 +01:00
parent 8c1e601bfd
commit dd04acdb59
4 changed files with 11 additions and 10 deletions

View File

@ -142,7 +142,7 @@ class FileCache implements CacheInterface
return false; return false;
} }
$path = File::sanitize($key); $path = File::sanitize($key, '~');
file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire)); file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire));
@ -158,7 +158,7 @@ class FileCache implements CacheInterface
return false; return false;
} }
$path = File::sanitize($key); $path = File::sanitize($key, '~');
if (!file_exists($this->cachePath . '/' . $path)) { if (!file_exists($this->cachePath . '/' . $path)) {
file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire)); file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire));
@ -274,7 +274,7 @@ class FileCache implements CacheInterface
return null; return null;
} }
$name = File::sanitize($key); $name = File::sanitize($key, '~');
$path = $this->cachePath . '/' . $name; $path = $this->cachePath . '/' . $name;
if(!file_exists($path)) { if(!file_exists($path)) {
@ -341,7 +341,7 @@ class FileCache implements CacheInterface
return false; return false;
} }
$name = File::sanitize($key); $name = File::sanitize($key, '~');
$path = $this->cachePath . '/' . $name; $path = $this->cachePath . '/' . $name;
if ($expire < 0 && file_exists($path)) { if ($expire < 0 && file_exists($path)) {
@ -404,7 +404,7 @@ class FileCache implements CacheInterface
return false; return false;
} }
$path = File::sanitize($key); $path = File::sanitize($key, '~');
if (file_exists($this->cachePath . '/' . $path)) { if (file_exists($this->cachePath . '/' . $path)) {
file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire)); file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire));

View File

@ -197,13 +197,14 @@ interface ContainerInterface
* Make name/path operating system safe. * Make name/path operating system safe.
* *
* @param string $path Path of the resource * @param string $path Path of the resource
* @param string $replace Replace invalid chars with
* *
* @return string * @return string
* *
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public static function sanitize(string $path) : string; public static function sanitize(string $path, string $replace = '') : string;
/** /**
* Get amount of sub-resources. * Get amount of sub-resources.

View File

@ -260,9 +260,9 @@ class Directory extends FileAbstract implements DirectoryInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function sanitize(string $path) : string public static function sanitize(string $path, string $replace = '') : string
{ {
return preg_replace('[^\w\s\d\.\-_~,;:\[\]\(\]\/]', '', $path); return preg_replace('[^\w\s\d\.\-_~,;:\[\]\(\]\/]', $replace, $path);
} }
/** /**

View File

@ -143,9 +143,9 @@ class File extends FileAbstract implements FileInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function sanitize(string $path) : string public static function sanitize(string $path, string $replace = '') : string
{ {
return preg_replace('/[^\w\s\d\.\-_~,;\[\]\(\]]/', '', $path); return preg_replace('/[^\w\s\d\.\-_~,;\[\]\(\]]/', $replace, $path);
} }
/** /**