This repository has been archived by the owner on May 8, 2021. It is now read-only.
/
Event.php
194 lines (184 loc) · 3.52 KB
/
Event.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/*
* OPEN POWER LIBS <http://www.invenzzia.org>
*
* This file is subject to the new BSD license that is bundled
* with this package in the file LICENSE. It is also available through
* WWW at this URL: <http://www.invenzzia.org/license/new-bsd>
*
* Copyright (c) Invenzzia Group <http://www.invenzzia.org>
* and other contributors. See website for details.
*
*/
/**
* The standard event for the Opl_Profiler.
*
* @author Amadeusz "megawebmaster" Starzykiewicz
* @copyright Invenzzia Group <http://www.invenzzia.org/> and contributors.
* @license http://www.invenzzia.org/license/new-bsd New BSD License
*/
class Opl_Profiler_Event extends Opl_Profiler_Event_Abstract implements Opl_Profiler_Event_Interface
{
protected
/**
* Event name.
* @var string
*/
$_name,
/**
* Start time.
* @var float
*/
$_start,
/**
* End time.
* @var float
*/
$_end,
/**
* Event data.
* @var array
*/
$_data = array();
/**
* Creates new event.
*
* @param string $name Event name.
*/
public function __construct($name)
{
$this->_name = (string)$name;
$this->_start = microtime(true);
} // end __construct();
/**
* Returns name of module.
*
* @return string
*/
public function getName()
{
return $this->_name;
} // end getName();
/**
* Notifies event about action.
*
* @param mixed $paramName Param name or array of params and its values.
* @param mixed $paramValue optional Param value.
* @throws Opl_Profiler_Event_Exception
*/
public function notify($paramName, $paramValue = null)
{
if(is_array($paramName))
{
foreach($paramName as $name => $value)
{
if($name == 'end')
{
$this->_end = $value;
}
else
{
$this->set($name, $value);
}
}
}
else
{
if($paramValue === null)
{
throw new Opl_Profiler_Event_Exception('No value for parameter "'.$paramName.'" given.');
return;
}
if($paramName == 'end')
{
$this->_end = $paramValue;
}
else
{
$this->set($paramName, $paramValue);
}
}
} // end notify();
/**
* Sets the value to the param.
*
* @param string $name Name of param.
* @param mixed $value Value.
*/
public function set($name, $value)
{
$name = explode('.', $name);
if(!in_array($name[0], $this->_positions))
{
$this->_positions[] = $name[0];
}
$holder = &$this->_data;
foreach($name as $n)
{
if(!isset($holder[$n]))
{
$holder[$n] = array();
}
$holder = &$holder[$n];
}
if(empty($holder))
{
$holder = $value;
}
else
{
$holder = array_merge_recursive($holder, array($value));
}
} // end set();
/**
* Returns the param value.
* If param name is not found returns its parent.
*
* @param string $name Param name.
* @return mixed
*/
public function get($name)
{
$name = explode('.', $name);
$holder = &$this->_data;
foreach($name as $n)
{
if(!isset($holder[$n]))
{
break;
}
$holder = &$holder[$n];
}
return $holder;
} // end get();
/**
* Returns array of given data.
*
* @return array
*/
public function getData()
{
return $this->_data;
} // end getData();
// Magical methods
/**
* Magical method for get().
*
* @param string $name Param name.
* @return mixed
*/
public function __get($name)
{
return $this->get($name);
} // end __get();
/**
* Magical method for set().
*
* @param string $name Param name.
* @param mixed $value Value
*/
public function __set($name, $value)
{
$this->set($name, $value);
} // end __set();
} // end Opl_Profiler_Event;