mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-22 17:45:40 +03:00
a4b9611e66
- Do not add spaces after opening or before closing parenthesis // Wrong if( !is_null($var) ) { ... } // Right if(!is_null($var)) { ... } - Add space after closing parenthesis // Wrong if(true){ ... } // Right if(true) { ... } - Add body into new line - Close body in new line // Wrong if(true) { ... } // Right if(true) { ... } Notice: Spaces after keywords are not detected: // Wrong (not detected) // -> space after 'if' and missing space after 'else' if (true) { ... } else{ ... } // Right if(true) { ... } else { ... }
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
require_once(__DIR__ . '/CacheInterface.php');
|
|
class Cache {
|
|
|
|
static protected $dirCache;
|
|
|
|
public function __construct(){
|
|
throw new \LogicException('Please use ' . __CLASS__ . '::create for new object.');
|
|
}
|
|
|
|
static public function create($nameCache){
|
|
if(!static::isValidNameCache($nameCache)) {
|
|
throw new \InvalidArgumentException('Name cache must be at least one
|
|
uppercase follow or not by alphanumeric or dash characters.');
|
|
}
|
|
|
|
$pathCache = self::getDir() . $nameCache . '.php';
|
|
|
|
if(!file_exists($pathCache)) {
|
|
throw new \Exception('The cache you looking for does not exist.');
|
|
}
|
|
|
|
require_once $pathCache;
|
|
|
|
return new $nameCache();
|
|
}
|
|
|
|
static public function setDir($dirCache){
|
|
if(!is_string($dirCache)) {
|
|
throw new \InvalidArgumentException('Dir cache must be a string.');
|
|
}
|
|
|
|
if(!file_exists($dirCache)) {
|
|
throw new \Exception('Dir cache does not exist.');
|
|
}
|
|
|
|
self::$dirCache = $dirCache;
|
|
}
|
|
|
|
static public function getDir(){
|
|
$dirCache = self::$dirCache;
|
|
|
|
if(is_null($dirCache)) {
|
|
throw new \LogicException(__CLASS__ . ' class need to know cache path !');
|
|
}
|
|
|
|
return $dirCache;
|
|
}
|
|
|
|
static public function isValidNameCache($nameCache){
|
|
return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameCache);
|
|
}
|
|
}
|