-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.class.php
94 lines (82 loc) · 1.87 KB
/
base.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
class base {
public $config = NULL;
public $memcache = NULL;
function __autoload($class)
{
require_once("$class.class.php");
}
function __construct($config)
{
$this->config = $config;
if(config::use_memcache)
{
$this->memcache = new Memcache;
if(!$this->memcache->pconnect(config::memcache_host, $config::memcache_port))
$this->error("Connection to memcached failed.");
}
}
function memcache_get($key)
{
return $this->memcache->get($key);
}
function memcache_set($key, $value, $timeout = 3600, $flags = 0)
{
$this->memcache->set($key, $value, $flags, $timeout);
}
function memcache_delete($key)
{
$this->memcache->delete($key);
}
function timestamp($format = "Y-m-d H:i:s")
{
return date($format);
}
function session($key)
{
if(isset($_SESSION) && isset($_SESSION[$key]))
return $_SESSION[$key];
return false;
}
function error($arg, $log = false)
{
if($log)
{
$trace = debug_backtrace();
$this->log("=====================\n");
$this->log("ERROR: " . $arg . "\n");
$this->log(implode('\n',$trace));
$this->log("=====================\n");
}
die($arg);
}
function log($msg, $logfile = "log.txt")
{
if(!($fh = fopen($logfile, "at")))
die("<strong>ERROR</strong>: Could not open $logfile for logging.");
$fwrite($fh, $msg."\n");
@fclose($fh);
}
function display()
{
echo " == " . get_class($this) . "<br />";
foreach($this as $key => $value)
if(is_object($value) && (is_subclass_of($value,"base") || get_class($value) == "base"))
{
echo "$key...<br>";
$value->display();
}
else
if(!is_object($value))
if(is_array($value))
{
echo "$key => ";
print_r($value);
echo "<br />";
}
else
echo "$key => $value<br />";
echo " /// " . get_class($this) . "<br />";;
}
}
?>