yarhon /
RouteGuardBundle
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * |
||
| 5 | * (c) Yaroslav Honcharuk <[email protected]> |
||
| 6 | * |
||
| 7 | * For the full copyright and license information, please view the LICENSE |
||
| 8 | * file that was distributed with this source code. |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Yarhon\RouteGuardBundle\Cache; |
||
| 12 | |||
| 13 | use Symfony\Component\Cache\Adapter\AdapterInterface; |
||
| 14 | use Symfony\Component\Cache\Adapter\PhpFilesAdapter; |
||
| 15 | use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @author Yaroslav Honcharuk <[email protected]> |
||
| 19 | */ |
||
| 20 | class CacheFactory |
||
| 21 | { |
||
| 22 | private static $keyEncodedChars = [ |
||
| 23 | '{' => '%7B', |
||
| 24 | '}' => '%7D', |
||
| 25 | '(' => '%28', |
||
| 26 | ')' => '%29', |
||
| 27 | '/' => '%2F', |
||
| 28 | '\\' => '%5C', |
||
| 29 | '@' => '%40', |
||
| 30 | ':' => '%3A', |
||
| 31 | ]; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $directory |
||
| 35 | * @param string $namespace |
||
| 36 | * |
||
| 37 | * @return AdapterInterface |
||
| 38 | */ |
||
| 39 | 21 | public static function createCache($directory, $namespace) |
|
| 40 | { |
||
| 41 | 21 | if (PhpFilesAdapter::isSupported()) { |
|
| 42 | 20 | return new PhpFilesAdapter($namespace, 0, $directory); |
|
| 43 | } |
||
| 44 | |||
| 45 | 1 | return new FilesystemAdapter($namespace, 0, $directory); |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @see \Symfony\Component\Cache\CacheItem::validateKey |
||
| 50 | * |
||
| 51 | * @param string $key |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | 37 | public static function getValidCacheKey($key) |
|
| 56 | { |
||
| 57 | 37 | return strtr($key, static::$keyEncodedChars); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 58 | } |
||
| 59 | } |
||
| 60 |