1: <?php
2: /**
3: * The Horde_Notification_Event:: class defines a single notification event.
4: *
5: * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (LGPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9: *
10: * @author Hans Lellelid <hans@velum.net>
11: * @category Horde
12: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
13: * @package Notification
14: */
15: class Horde_Notification_Event
16: {
17: /**
18: * The message being passed.
19: *
20: * @var string
21: */
22: public $message = '';
23:
24: /**
25: * The flags for this message.
26: *
27: * @var array
28: */
29: public $flags = array();
30:
31: /**
32: * The message type.
33: *
34: * @var string
35: */
36: public $type;
37:
38: /**
39: * Constructor.
40: *
41: * @param mixed $data Message: either a string or an Exception or
42: * PEAR_Error object.
43: * @param string $type The event type.
44: * @param array $flags The flag array.
45: */
46: public function __construct($data, $type = null, array $flags = array())
47: {
48: $this->flags = $flags;
49:
50: $this->type = empty($type)
51: ? 'status'
52: : $type;
53:
54: if ($data instanceof PEAR_Error) {
55: // DEPRECATED
56: if (($userinfo = $data->getUserInfo()) &&
57: is_array($userinfo)) {
58: $userinfo_elts = array();
59: foreach ($userinfo as $userinfo_elt) {
60: if (is_scalar($userinfo_elt)) {
61: $userinfo_elts[] = $userinfo_elt;
62: } elseif (is_object($userinfo_elt)) {
63: if (is_callable(array($userinfo_elt, '__toString'))) {
64: $userinfo_elts[] = $userinfo_elt->__toString();
65: } elseif (is_callable(array($userinfo_elt, 'getMessage'))) {
66: $userinfo_elts[] = $userinfo_elt->getMessage();
67: }
68: }
69: }
70:
71: $this->message = $data->getMessage() . ' : ' . implode(', ', $userinfo_elts);
72: } else {
73: $this->message = $data->getMessage();
74: }
75: } elseif ($data instanceof Exception) {
76: // Exception
77: $this->message = $data->getMessage();
78: } else {
79: // String or object
80: $this->message = strval($data);
81: }
82: }
83:
84: /**
85: * String representation of this object.
86: *
87: * @return string String representation.
88: */
89: public function __toString()
90: {
91: return $this->message;
92: }
93:
94: }
95: