Yaffs site version 1.1
[yaffs-website] / vendor / symfony / http-kernel / Profiler / Profile.php
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
22 {
23     private $token;
24
25     /**
26      * @var DataCollectorInterface[]
27      */
28     private $collectors = array();
29
30     private $ip;
31     private $method;
32     private $url;
33     private $time;
34     private $statusCode;
35
36     /**
37      * @var Profile
38      */
39     private $parent;
40
41     /**
42      * @var Profile[]
43      */
44     private $children = array();
45
46     /**
47      * Constructor.
48      *
49      * @param string $token The token
50      */
51     public function __construct($token)
52     {
53         $this->token = $token;
54     }
55
56     /**
57      * Sets the token.
58      *
59      * @param string $token The token
60      */
61     public function setToken($token)
62     {
63         $this->token = $token;
64     }
65
66     /**
67      * Gets the token.
68      *
69      * @return string The token
70      */
71     public function getToken()
72     {
73         return $this->token;
74     }
75
76     /**
77      * Sets the parent token.
78      *
79      * @param Profile $parent
80      */
81     public function setParent(Profile $parent)
82     {
83         $this->parent = $parent;
84     }
85
86     /**
87      * Returns the parent profile.
88      *
89      * @return self
90      */
91     public function getParent()
92     {
93         return $this->parent;
94     }
95
96     /**
97      * Returns the parent token.
98      *
99      * @return null|string The parent token
100      */
101     public function getParentToken()
102     {
103         return $this->parent ? $this->parent->getToken() : null;
104     }
105
106     /**
107      * Returns the IP.
108      *
109      * @return string The IP
110      */
111     public function getIp()
112     {
113         return $this->ip;
114     }
115
116     /**
117      * Sets the IP.
118      *
119      * @param string $ip
120      */
121     public function setIp($ip)
122     {
123         $this->ip = $ip;
124     }
125
126     /**
127      * Returns the request method.
128      *
129      * @return string The request method
130      */
131     public function getMethod()
132     {
133         return $this->method;
134     }
135
136     public function setMethod($method)
137     {
138         $this->method = $method;
139     }
140
141     /**
142      * Returns the URL.
143      *
144      * @return string The URL
145      */
146     public function getUrl()
147     {
148         return $this->url;
149     }
150
151     public function setUrl($url)
152     {
153         $this->url = $url;
154     }
155
156     /**
157      * Returns the time.
158      *
159      * @return int The time
160      */
161     public function getTime()
162     {
163         if (null === $this->time) {
164             return 0;
165         }
166
167         return $this->time;
168     }
169
170     /**
171      * @param int The time
172      */
173     public function setTime($time)
174     {
175         $this->time = $time;
176     }
177
178     /**
179      * @param int $statusCode
180      */
181     public function setStatusCode($statusCode)
182     {
183         $this->statusCode = $statusCode;
184     }
185
186     /**
187      * @return int
188      */
189     public function getStatusCode()
190     {
191         return $this->statusCode;
192     }
193
194     /**
195      * Finds children profilers.
196      *
197      * @return self[]
198      */
199     public function getChildren()
200     {
201         return $this->children;
202     }
203
204     /**
205      * Sets children profiler.
206      *
207      * @param Profile[] $children
208      */
209     public function setChildren(array $children)
210     {
211         $this->children = array();
212         foreach ($children as $child) {
213             $this->addChild($child);
214         }
215     }
216
217     /**
218      * Adds the child token.
219      *
220      * @param Profile $child
221      */
222     public function addChild(Profile $child)
223     {
224         $this->children[] = $child;
225         $child->setParent($this);
226     }
227
228     /**
229      * Gets a Collector by name.
230      *
231      * @param string $name A collector name
232      *
233      * @return DataCollectorInterface A DataCollectorInterface instance
234      *
235      * @throws \InvalidArgumentException if the collector does not exist
236      */
237     public function getCollector($name)
238     {
239         if (!isset($this->collectors[$name])) {
240             throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
241         }
242
243         return $this->collectors[$name];
244     }
245
246     /**
247      * Gets the Collectors associated with this profile.
248      *
249      * @return DataCollectorInterface[]
250      */
251     public function getCollectors()
252     {
253         return $this->collectors;
254     }
255
256     /**
257      * Sets the Collectors associated with this profile.
258      *
259      * @param DataCollectorInterface[] $collectors
260      */
261     public function setCollectors(array $collectors)
262     {
263         $this->collectors = array();
264         foreach ($collectors as $collector) {
265             $this->addCollector($collector);
266         }
267     }
268
269     /**
270      * Adds a Collector.
271      *
272      * @param DataCollectorInterface $collector A DataCollectorInterface instance
273      */
274     public function addCollector(DataCollectorInterface $collector)
275     {
276         $this->collectors[$collector->getName()] = $collector;
277     }
278
279     /**
280      * Returns true if a Collector for the given name exists.
281      *
282      * @param string $name A collector name
283      *
284      * @return bool
285      */
286     public function hasCollector($name)
287     {
288         return isset($this->collectors[$name]);
289     }
290
291     public function __sleep()
292     {
293         return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time');
294     }
295 }