mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-07-13 07:24:48 +02:00
refactor: general code base refactor (#2950)
* refactor * fix: bug in previous refactor * chore: exclude phpcompat sniff due to bug in phpcompat * fix: do not leak absolute paths * refactor/fix: batch extensions checking, fix DOS issue
This commit is contained in:
parent
b042412416
commit
2bbce8ebef
45 changed files with 679 additions and 827 deletions
|
@ -12,29 +12,33 @@ class MemcachedCache implements CacheInterface
|
|||
public function __construct()
|
||||
{
|
||||
if (!extension_loaded('memcached')) {
|
||||
returnServerError('"memcached" extension not loaded. Please check "php.ini"');
|
||||
throw new \Exception('"memcached" extension not loaded. Please check "php.ini"');
|
||||
}
|
||||
|
||||
$section = 'MemcachedCache';
|
||||
$host = Configuration::getConfig($section, 'host');
|
||||
$port = Configuration::getConfig($section, 'port');
|
||||
|
||||
if (empty($host) && empty($port)) {
|
||||
returnServerError('Configuration for ' . $section . ' missing. Please check your ' . FILE_CONFIG);
|
||||
} elseif (empty($host)) {
|
||||
returnServerError('"host" param is not set for ' . $section . '. Please check your ' . FILE_CONFIG);
|
||||
} elseif (empty($port)) {
|
||||
returnServerError('"port" param is not set for ' . $section . '. Please check your ' . FILE_CONFIG);
|
||||
} elseif (!ctype_digit($port)) {
|
||||
returnServerError('"port" param is invalid for ' . $section . '. Please check your ' . FILE_CONFIG);
|
||||
throw new \Exception('Configuration for ' . $section . ' missing. Please check your ' . FILE_CONFIG);
|
||||
}
|
||||
if (empty($host)) {
|
||||
throw new \Exception('"host" param is not set for ' . $section . '. Please check your ' . FILE_CONFIG);
|
||||
}
|
||||
if (empty($port)) {
|
||||
throw new \Exception('"port" param is not set for ' . $section . '. Please check your ' . FILE_CONFIG);
|
||||
}
|
||||
if (!ctype_digit($port)) {
|
||||
throw new \Exception('"port" param is invalid for ' . $section . '. Please check your ' . FILE_CONFIG);
|
||||
}
|
||||
|
||||
$port = intval($port);
|
||||
|
||||
if ($port < 1 || $port > 65535) {
|
||||
returnServerError('"port" param is invalid for ' . $section . '. Please check your ' . FILE_CONFIG);
|
||||
throw new \Exception('"port" param is invalid for ' . $section . '. Please check your ' . FILE_CONFIG);
|
||||
}
|
||||
|
||||
$conn = new Memcached();
|
||||
$conn = new \Memcached();
|
||||
$conn->addServer($host, $port) or returnServerError('Could not connect to memcached server');
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
@ -64,7 +68,7 @@ class MemcachedCache implements CacheInterface
|
|||
$result = $this->conn->set($this->getCacheKey(), $object_to_save, $this->expiration);
|
||||
|
||||
if ($result === false) {
|
||||
returnServerError('Cannot write the cache to memcached server');
|
||||
throw new \Exception('Cannot write the cache to memcached server');
|
||||
}
|
||||
|
||||
$this->time = $time;
|
||||
|
@ -87,20 +91,12 @@ class MemcachedCache implements CacheInterface
|
|||
$this->expiration = $duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set scope
|
||||
* @return self
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set key
|
||||
* @return self
|
||||
*/
|
||||
public function setKey($key)
|
||||
{
|
||||
if (!empty($key) && is_array($key)) {
|
||||
|
@ -119,7 +115,7 @@ class MemcachedCache implements CacheInterface
|
|||
private function getCacheKey()
|
||||
{
|
||||
if (is_null($this->key)) {
|
||||
returnServerError('Call "setKey" first!');
|
||||
throw new \Exception('Call "setKey" first!');
|
||||
}
|
||||
|
||||
return 'rss_bridge_cache_' . hash('md5', $this->scope . $this->key . 'A');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue