|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\HttpKernel\Profiler; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* Profile. |
|
|
18 |
* |
|
|
19 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
20 |
*/ |
|
|
21 |
class Profile implements \Serializable |
|
|
22 |
{ |
|
|
23 |
private $token; |
|
|
24 |
private $collectors; |
|
|
25 |
private $ip; |
|
|
26 |
private $url; |
|
|
27 |
private $time; |
|
|
28 |
private $parent; |
|
|
29 |
private $children; |
|
|
30 |
|
|
|
31 |
public function __construct($token) |
|
|
32 |
{ |
|
|
33 |
$this->token = $token; |
|
|
34 |
$this->collectors = array(); |
|
|
35 |
} |
|
|
36 |
|
|
|
37 |
/** |
|
|
38 |
* Sets the token. |
|
|
39 |
* |
|
|
40 |
* @param string $token The token |
|
|
41 |
*/ |
|
|
42 |
public function setToken($token) |
|
|
43 |
{ |
|
|
44 |
$this->token = $token; |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
/** |
|
|
48 |
* Gets the token. |
|
|
49 |
* |
|
|
50 |
* @return string The token |
|
|
51 |
*/ |
|
|
52 |
public function getToken() |
|
|
53 |
{ |
|
|
54 |
return $this->token; |
|
|
55 |
} |
|
|
56 |
|
|
|
57 |
/** |
|
|
58 |
* Sets the parent token |
|
|
59 |
* |
|
|
60 |
* @param Profile $parent The parent Profile |
|
|
61 |
*/ |
|
|
62 |
public function setParent(Profile $parent) |
|
|
63 |
{ |
|
|
64 |
$this->parent = $parent; |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
/** |
|
|
68 |
* Returns the parent token. |
|
|
69 |
* |
|
|
70 |
* @return Profile The parent profile |
|
|
71 |
*/ |
|
|
72 |
public function getParent() |
|
|
73 |
{ |
|
|
74 |
return $this->parent; |
|
|
75 |
} |
|
|
76 |
|
|
|
77 |
/** |
|
|
78 |
* Returns the IP. |
|
|
79 |
* |
|
|
80 |
* @return string The IP |
|
|
81 |
*/ |
|
|
82 |
public function getIp() |
|
|
83 |
{ |
|
|
84 |
return $this->ip; |
|
|
85 |
} |
|
|
86 |
|
|
|
87 |
public function setIp($ip) |
|
|
88 |
{ |
|
|
89 |
$this->ip = $ip; |
|
|
90 |
} |
|
|
91 |
|
|
|
92 |
/** |
|
|
93 |
* Returns the URL. |
|
|
94 |
* |
|
|
95 |
* @return string The URL |
|
|
96 |
*/ |
|
|
97 |
public function getUrl() |
|
|
98 |
{ |
|
|
99 |
return $this->url; |
|
|
100 |
} |
|
|
101 |
|
|
|
102 |
public function setUrl($url) |
|
|
103 |
{ |
|
|
104 |
$this->url = $url; |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
/** |
|
|
108 |
* Returns the time. |
|
|
109 |
* |
|
|
110 |
* @return string The time |
|
|
111 |
*/ |
|
|
112 |
public function getTime() |
|
|
113 |
{ |
|
|
114 |
return $this->time; |
|
|
115 |
} |
|
|
116 |
|
|
|
117 |
public function setTime($time) |
|
|
118 |
{ |
|
|
119 |
$this->time = $time; |
|
|
120 |
} |
|
|
121 |
|
|
|
122 |
/** |
|
|
123 |
* Finds children profilers. |
|
|
124 |
* |
|
|
125 |
* @return array An array of Profile |
|
|
126 |
*/ |
|
|
127 |
public function getChildren() |
|
|
128 |
{ |
|
|
129 |
return $this->children; |
|
|
130 |
} |
|
|
131 |
|
|
|
132 |
public function setChildren(array $children) |
|
|
133 |
{ |
|
|
134 |
$this->children = array(); |
|
|
135 |
foreach ($children as $child) { |
|
|
136 |
$this->addChild($child); |
|
|
137 |
} |
|
|
138 |
} |
|
|
139 |
|
|
|
140 |
public function addChild(Profile $child) |
|
|
141 |
{ |
|
|
142 |
$this->children[] = $child; |
|
|
143 |
} |
|
|
144 |
|
|
|
145 |
public function getCollector($name) |
|
|
146 |
{ |
|
|
147 |
if (!isset($this->collectors[$name])) { |
|
|
148 |
throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name)); |
|
|
149 |
} |
|
|
150 |
|
|
|
151 |
return $this->collectors[$name]; |
|
|
152 |
} |
|
|
153 |
|
|
|
154 |
public function getCollectors() |
|
|
155 |
{ |
|
|
156 |
return $this->collectors; |
|
|
157 |
} |
|
|
158 |
|
|
|
159 |
public function setCollectors(array $collectors) |
|
|
160 |
{ |
|
|
161 |
$this->collectors = array(); |
|
|
162 |
foreach ($collectors as $collector) { |
|
|
163 |
$this->addCollector($collector); |
|
|
164 |
} |
|
|
165 |
} |
|
|
166 |
|
|
|
167 |
public function addCollector(DataCollectorInterface $collector) |
|
|
168 |
{ |
|
|
169 |
$this->collectors[$collector->getName()] = $collector; |
|
|
170 |
} |
|
|
171 |
|
|
|
172 |
public function hasCollector($name) |
|
|
173 |
{ |
|
|
174 |
return isset($this->collectors[$name]); |
|
|
175 |
} |
|
|
176 |
|
|
|
177 |
public function serialize() |
|
|
178 |
{ |
|
|
179 |
return serialize(array($this->token, $this->parent, $this->children, $this->collectors, $this->ip, $this->url, $this->time)); |
|
|
180 |
} |
|
|
181 |
|
|
|
182 |
public function unserialize($data) |
|
|
183 |
{ |
|
|
184 |
list($this->token, $this->parent, $this->children, $this->collectors, $this->ip, $this->url, $this->time) = unserialize($data); |
|
|
185 |
} |
|
|
186 |
} |