cache: Rename setDir and getDir
- Rename setDir to setWorkingDir - Rename getDir to getWorkingDir - Rename parameter $workingDir to $dir in getWorkingDir
This commit is contained in:
parent
e8442a3bf8
commit
4a99c6e630
2 changed files with 14 additions and 14 deletions
|
@ -26,7 +26,7 @@
|
||||||
* require_once __DIR__ . '/rssbridge.php';
|
* require_once __DIR__ . '/rssbridge.php';
|
||||||
*
|
*
|
||||||
* // Step 1: Set the working directory
|
* // Step 1: Set the working directory
|
||||||
* Cache::setDir(__DIR__ . '/../caches/');
|
* Cache::setWorkingDir(__DIR__ . '/../caches/');
|
||||||
*
|
*
|
||||||
* // Step 2: Create a new instance of a cache object (based on the name)
|
* // Step 2: Create a new instance of a cache object (based on the name)
|
||||||
* $cache = Cache::create('FileCache');
|
* $cache = Cache::create('FileCache');
|
||||||
|
@ -38,7 +38,7 @@ class Cache {
|
||||||
* Holds a path to the working directory.
|
* Holds a path to the working directory.
|
||||||
*
|
*
|
||||||
* Do not access this property directly!
|
* Do not access this property directly!
|
||||||
* Use {@see Cache::setDir()} and {@see Cache::getDir()} instead.
|
* Use {@see Cache::setWorkingDir()} and {@see Cache::getWorkingDir()} instead.
|
||||||
*
|
*
|
||||||
* @var string|null
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
|
@ -69,7 +69,7 @@ class Cache {
|
||||||
throw new \InvalidArgumentException('Cache name invalid!');
|
throw new \InvalidArgumentException('Cache name invalid!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$filePath = self::getDir() . $name . '.php';
|
$filePath = self::getWorkingDir() . $name . '.php';
|
||||||
|
|
||||||
if(!file_exists($filePath)) {
|
if(!file_exists($filePath)) {
|
||||||
throw new \Exception('Cache file ' . $filePath . ' does not exist!');
|
throw new \Exception('Cache file ' . $filePath . ' does not exist!');
|
||||||
|
@ -83,38 +83,38 @@ class Cache {
|
||||||
/**
|
/**
|
||||||
* Sets the working directory.
|
* Sets the working directory.
|
||||||
*
|
*
|
||||||
* @param string $workingDir Path to a directory containing cache classes
|
* @param string $dir Path to a directory containing cache classes
|
||||||
* @throws \InvalidArgumentException if $workingDir is not a string.
|
* @throws \InvalidArgumentException if $dir is not a string.
|
||||||
* @throws \Exception if the working directory doesn't exist.
|
* @throws \Exception if the working directory doesn't exist.
|
||||||
* @throws \InvalidArgumentException if $workingDir is not a directory.
|
* @throws \InvalidArgumentException if $dir is not a directory.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setDir($workingDir){
|
public static function setWorkingDir($dir){
|
||||||
self::$workingDir = null;
|
self::$workingDir = null;
|
||||||
|
|
||||||
if(!is_string($workingDir)) {
|
if(!is_string($dir)) {
|
||||||
throw new \InvalidArgumentException('Working directory is not a valid string!');
|
throw new \InvalidArgumentException('Working directory is not a valid string!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file_exists($workingDir)) {
|
if(!file_exists($dir)) {
|
||||||
throw new \Exception('Working directory does not exist!');
|
throw new \Exception('Working directory does not exist!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_dir($workingDir)) {
|
if(!is_dir($dir)) {
|
||||||
throw new \InvalidArgumentException('Working directory is not a directory!');
|
throw new \InvalidArgumentException('Working directory is not a directory!');
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$workingDir = realpath($workingDir) . '/';
|
self::$workingDir = realpath($dir) . '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current working directory.
|
* Returns the current working directory.
|
||||||
* The working directory must be set with {@see Cache::setDir()}!
|
* The working directory must be set with {@see Cache::setWorkingDir()}!
|
||||||
*
|
*
|
||||||
* @throws \LogicException if the working directory is not set.
|
* @throws \LogicException if the working directory is not set.
|
||||||
* @return string The current working directory.
|
* @return string The current working directory.
|
||||||
*/
|
*/
|
||||||
public static function getDir(){
|
public static function getWorkingDir(){
|
||||||
if(is_null(self::$workingDir)) {
|
if(is_null(self::$workingDir)) {
|
||||||
throw new \LogicException('Working directory is not set!');
|
throw new \LogicException('Working directory is not set!');
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ require_once PATH_LIB_VENDOR . 'php-urljoin/src/urljoin.php';
|
||||||
try {
|
try {
|
||||||
Bridge::setDir(PATH_LIB_BRIDGES);
|
Bridge::setDir(PATH_LIB_BRIDGES);
|
||||||
Format::setDir(PATH_LIB_FORMATS);
|
Format::setDir(PATH_LIB_FORMATS);
|
||||||
Cache::setDir(PATH_LIB_CACHES);
|
Cache::setWorkingDir(PATH_LIB_CACHES);
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
error_log($e);
|
error_log($e);
|
||||||
header('Content-type: text/plain', true, 500);
|
header('Content-type: text/plain', true, 500);
|
||||||
|
|
Loading…
Reference in a new issue