Use the settings class in the cache class (#6891)
This commit is contained in:
parent
6890c21e92
commit
a17b63e616
|
|
@ -1,20 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cache class provides an abstracted cache
|
* Provides an abstracted cache
|
||||||
*
|
|
||||||
* @method string set
|
|
||||||
* @method string get
|
|
||||||
* @method string delete
|
|
||||||
* @method string flush
|
|
||||||
*/
|
*/
|
||||||
class cache {
|
class cache {
|
||||||
|
private $settings;
|
||||||
|
private $syslog;
|
||||||
|
private $location;
|
||||||
|
private $method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the object is created
|
* Called when the object is created
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct(settings $settings = null) {
|
||||||
//place holder
|
//set defaults
|
||||||
|
if ($settings === null) {
|
||||||
|
$settings = new settings();
|
||||||
|
}
|
||||||
|
|
||||||
|
//get the settings
|
||||||
|
$this->settings = $settings;
|
||||||
|
$this->method = $this->setting('method');
|
||||||
|
$this->syslog = $this->setting('syslog');
|
||||||
|
$this->location = $this->setting('location');
|
||||||
|
if (empty($this->method)) {
|
||||||
|
$this->method = 'file';
|
||||||
|
}
|
||||||
|
if (empty($this->syslog)) {
|
||||||
|
$this->syslog = 'false';
|
||||||
|
}
|
||||||
|
if (empty($this->location)) {
|
||||||
|
$this->location = '/var/cache/fusionpbx';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setting($subcategory) {
|
||||||
|
return $this->settings->get('cache', $subcategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -28,7 +50,7 @@ class cache {
|
||||||
$key = str_replace(":", ".", $key);
|
$key = str_replace(":", ".", $key);
|
||||||
|
|
||||||
//save to memcache
|
//save to memcache
|
||||||
if ($_SESSION['cache']['method']['text'] == "memcache") {
|
if ($this->method === "memcache") {
|
||||||
//connect to event socket
|
//connect to event socket
|
||||||
$esl = event_socket::create();
|
$esl = event_socket::create();
|
||||||
if ($esl === false) {
|
if ($esl === false) {
|
||||||
|
|
@ -42,8 +64,8 @@ class cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
//save to the file cache
|
//save to the file cache
|
||||||
if ($_SESSION['cache']['method']['text'] == "file") {
|
if ($this->method === "file") {
|
||||||
$result = file_put_contents($_SESSION['cache']['location']['text'] . "/" . $key, $value);
|
$result = file_put_contents($this->location . "/" . $key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//return result
|
//return result
|
||||||
|
|
@ -59,8 +81,8 @@ class cache {
|
||||||
//change the delimiter
|
//change the delimiter
|
||||||
$key = str_replace(":", ".", $key);
|
$key = str_replace(":", ".", $key);
|
||||||
|
|
||||||
//cache method memcache
|
//cache method memcache
|
||||||
if ($_SESSION['cache']['method']['text'] == "memcache") {
|
if ($this->method === "memcache") {
|
||||||
// connect to event socket
|
// connect to event socket
|
||||||
$esl = event_socket::create();
|
$esl = event_socket::create();
|
||||||
if (!$esl->is_connected()) {
|
if (!$esl->is_connected()) {
|
||||||
|
|
@ -76,9 +98,9 @@ class cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the file cache
|
//get the file cache
|
||||||
if ($_SESSION['cache']['method']['text'] == "file") {
|
if ($this->method === "file") {
|
||||||
if (file_exists($_SESSION['cache']['location']['text'] . "/" . $key)) {
|
if (file_exists($this->location . "/" . $key)) {
|
||||||
$result = file_get_contents($_SESSION['cache']['location']['text'] . "/" . $key);
|
$result = file_get_contents($this->location . "/" . $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,14 +115,14 @@ class cache {
|
||||||
public function delete($key) {
|
public function delete($key) {
|
||||||
|
|
||||||
//debug information
|
//debug information
|
||||||
if (isset($_SESSION['cache']['syslog']['boolean']) && $_SESSION['cache']['syslog']['boolean'] == "true") {
|
if ($this->syslog === "true") {
|
||||||
openlog("fusionpbx", LOG_PID | LOG_PERROR, LOG_USER);
|
openlog("fusionpbx", LOG_PID | LOG_PERROR, LOG_USER);
|
||||||
syslog(LOG_WARNING, "debug: cache: [key: ".$key.", script: ".$_SERVER['SCRIPT_NAME'].", line: ".__line__."]");
|
syslog(LOG_WARNING, "debug: cache: [key: ".$key.", script: ".$_SERVER['SCRIPT_NAME'].", line: ".__line__."]");
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
|
|
||||||
//cache method memcache
|
//cache method memcache
|
||||||
if (!empty($_SESSION['cache']['method']['text']) && $_SESSION['cache']['method']['text'] == "memcache") {
|
if ($this->method === "memcache") {
|
||||||
//connect to event socket
|
//connect to event socket
|
||||||
$esl = event_socket::create();
|
$esl = event_socket::create();
|
||||||
if ($esl === false) {
|
if ($esl === false) {
|
||||||
|
|
@ -122,7 +144,7 @@ class cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
//cache method file
|
//cache method file
|
||||||
if (!empty($_SESSION['cache']['method']['text']) && $_SESSION['cache']['method']['text'] == "file") {
|
if ($this->method === "file") {
|
||||||
//change the delimiter
|
//change the delimiter
|
||||||
$key = str_replace(":", ".", $key);
|
$key = str_replace(":", ".", $key);
|
||||||
|
|
||||||
|
|
@ -141,7 +163,7 @@ class cache {
|
||||||
event_socket::command($event);
|
event_socket::command($event);
|
||||||
|
|
||||||
//remove the local files
|
//remove the local files
|
||||||
foreach (glob($_SESSION['cache']['location']['text'] . "/" . $key) as $file) {
|
foreach (glob($this->location . "/" . $key) as $file) {
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
|
|
@ -159,14 +181,14 @@ class cache {
|
||||||
public function flush() {
|
public function flush() {
|
||||||
|
|
||||||
//debug information
|
//debug information
|
||||||
if (isset($_SESSION['cache']['syslog']['boolean']) && $_SESSION['cache']['syslog']['boolean'] == "true") {
|
if ($this->syslog === "true") {
|
||||||
openlog("fusionpbx", LOG_PID | LOG_PERROR, LOG_USER);
|
openlog("fusionpbx", LOG_PID | LOG_PERROR, LOG_USER);
|
||||||
syslog(LOG_WARNING, "debug: cache: [flush: all, script: ".$_SERVER['SCRIPT_NAME'].", line: ".__line__."]");
|
syslog(LOG_WARNING, "debug: cache: [flush: all, script: ".$_SERVER['SCRIPT_NAME'].", line: ".__line__."]");
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
|
|
||||||
//cache method memcache
|
//cache method memcache
|
||||||
if ($_SESSION['cache']['method']['text'] == "memcache") {
|
if ($this->method === "memcache") {
|
||||||
// connect to event socket
|
// connect to event socket
|
||||||
$esl = event_socket::create();
|
$esl = event_socket::create();
|
||||||
if ($esl === false) {
|
if ($esl === false) {
|
||||||
|
|
@ -187,8 +209,8 @@ class cache {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//cache method file
|
//cache method file
|
||||||
if ($_SESSION['cache']['method']['text'] == "file") {
|
if ($this->method === "file") {
|
||||||
// connect to event socket
|
// connect to event socket
|
||||||
$esl = event_socket::create();
|
$esl = event_socket::create();
|
||||||
if ($esl === false) {
|
if ($esl === false) {
|
||||||
|
|
@ -204,7 +226,7 @@ class cache {
|
||||||
event_socket::command($event);
|
event_socket::command($event);
|
||||||
|
|
||||||
//remove the cache
|
//remove the cache
|
||||||
recursive_delete($_SESSION['cache']['location']['text']);
|
recursive_delete($this->location);
|
||||||
|
|
||||||
//set message
|
//set message
|
||||||
$result = '+OK cache flushed';
|
$result = '+OK cache flushed';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue