1
|
<?php
|
2
|
/**
|
3
|
* Description of class
|
4
|
*
|
5
|
* @author wkl
|
6
|
*/
|
7
|
class msgQueue {
|
8
|
|
9
|
const RETVAL_ARRAY = 0;
|
10
|
const RETVAL_STRING = 1; // (default)
|
11
|
|
12
|
private static $_instance;
|
13
|
|
14
|
private $_error = array();
|
15
|
private $_success = array();
|
16
|
|
17
|
protected function __construct() {
|
18
|
$this->_error = array();
|
19
|
$this->_success = array();
|
20
|
}
|
21
|
private function __clone() { throw new Exception('cloning Class '.__CLASS__.' is illegal'); }
|
22
|
|
23
|
public static function handle()
|
24
|
{
|
25
|
if (!isset(self::$_instance)) {
|
26
|
$c = __CLASS__;
|
27
|
self::$_instance = new $c;
|
28
|
}
|
29
|
return self::$_instance;
|
30
|
}
|
31
|
|
32
|
public static function add($message = '', $type = false)
|
33
|
{
|
34
|
if($type)
|
35
|
{
|
36
|
self::handle()->_success[] = $message;
|
37
|
}else
|
38
|
{
|
39
|
self::handle()->_error[] = $message;
|
40
|
}
|
41
|
}
|
42
|
|
43
|
public static function clear()
|
44
|
{
|
45
|
self::handle()->_error = array();
|
46
|
self::handle()->_success = array();
|
47
|
}
|
48
|
|
49
|
public static function isEmpty()
|
50
|
{
|
51
|
return (sizeof(self::handle()->_success) == 0 && sizeof(self::handle()->_error) == 0 );
|
52
|
}
|
53
|
|
54
|
public static function getError($retval_type = self::RETVAL_STRING)
|
55
|
{
|
56
|
if(sizeof(self::handle()->_error))
|
57
|
{
|
58
|
if($retval_type == self::RETVAL_STRING)
|
59
|
{
|
60
|
return implode('<br />', self::handle()->_error);
|
61
|
}else
|
62
|
{
|
63
|
return self::handle()->_error;
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
|
68
|
public static function getSuccess($retval_type = self::RETVAL_STRING)
|
69
|
{
|
70
|
if(sizeof(self::handle()->_success))
|
71
|
{
|
72
|
if($retval_type == self::RETVAL_STRING)
|
73
|
{
|
74
|
return implode('<br />', self::handle()->_success);
|
75
|
}else
|
76
|
{
|
77
|
return self::handle()->_success;
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
|
83
|
}
|