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:
logmanoriginal 2018-11-14 20:39:39 +01:00
parent e8442a3bf8
commit 4a99c6e630
2 changed files with 14 additions and 14 deletions

View file

@ -26,7 +26,7 @@
* require_once __DIR__ . '/rssbridge.php';
*
* // 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)
* $cache = Cache::create('FileCache');
@ -38,7 +38,7 @@ class Cache {
* Holds a path to the working directory.
*
* 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
*/
@ -69,7 +69,7 @@ class Cache {
throw new \InvalidArgumentException('Cache name invalid!');
}
$filePath = self::getDir() . $name . '.php';
$filePath = self::getWorkingDir() . $name . '.php';
if(!file_exists($filePath)) {
throw new \Exception('Cache file ' . $filePath . ' does not exist!');
@ -83,38 +83,38 @@ class Cache {
/**
* Sets the working directory.
*
* @param string $workingDir Path to a directory containing cache classes
* @throws \InvalidArgumentException if $workingDir is not a string.
* @param string $dir Path to a directory containing cache classes
* @throws \InvalidArgumentException if $dir is not a string.
* @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
*/
public static function setDir($workingDir){
public static function setWorkingDir($dir){
self::$workingDir = null;
if(!is_string($workingDir)) {
if(!is_string($dir)) {
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!');
}
if(!is_dir($workingDir)) {
if(!is_dir($dir)) {
throw new \InvalidArgumentException('Working directory is not a directory!');
}
self::$workingDir = realpath($workingDir) . '/';
self::$workingDir = realpath($dir) . '/';
}
/**
* 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.
* @return string The current working directory.
*/
public static function getDir(){
public static function getWorkingDir(){
if(is_null(self::$workingDir)) {
throw new \LogicException('Working directory is not set!');
}

View file

@ -43,7 +43,7 @@ require_once PATH_LIB_VENDOR . 'php-urljoin/src/urljoin.php';
try {
Bridge::setDir(PATH_LIB_BRIDGES);
Format::setDir(PATH_LIB_FORMATS);
Cache::setDir(PATH_LIB_CACHES);
Cache::setWorkingDir(PATH_LIB_CACHES);
} catch(Exception $e) {
error_log($e);
header('Content-type: text/plain', true, 500);