Version 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 string 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     public function setTime($time)
171     {
172         $this->time = $time;
173     }
174
175     /**
176      * @param int $statusCode
177      */
178     public function setStatusCode($statusCode)
179     {
180         $this->statusCode = $statusCode;
181     }
182
183     /**
184      * @return int
185      */
186     public function getStatusCode()
187     {
188         return $this->statusCode;
189     }
190
191     /**
192      * Finds children profilers.
193      *
194      * @return self[]
195      */
196     public function getChildren()
197     {
198         return $this->children;
199     }
200
201     /**
202      * Sets children profiler.
203      *
204      * @param Profile[] $children
205      */
206     public function setChildren(array $children)
207     {
208         $this->children = array();
209         foreach ($children as $child) {
210             $this->addChild($child);
211         }
212     }
213
214     /**
215      * Adds the child token.
216      *
217      * @param Profile $child
218      */
219     public function addChild(Profile $child)
220     {
221         $this->children[] = $child;
222         $child->setParent($this);
223     }
224
225     /**
226      * Gets a Collector by name.
227      *
228      * @param string $name A collector name
229      *
230      * @return DataCollectorInterface A DataCollectorInterface instance
231      *
232      * @throws \InvalidArgumentException if the collector does not exist
233      */
234     public function getCollector($name)
235     {
236         if (!isset($this->collectors[$name])) {
237             throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
238         }
239
240         return $this->collectors[$name];
241     }
242
243     /**
244      * Gets the Collectors associated with this profile.
245      *
246      * @return DataCollectorInterface[]
247      */
248     public function getCollectors()
249     {
250         return $this->collectors;
251     }
252
253     /**
254      * Sets the Collectors associated with this profile.
255      *
256      * @param DataCollectorInterface[] $collectors
257      */
258     public function setCollectors(array $collectors)
259     {
260         $this->collectors = array();
261         foreach ($collectors as $collector) {
262             $this->addCollector($collector);
263         }
264     }
265
266     /**
267      * Adds a Collector.
268      *
269      * @param DataCollectorInterface $collector A DataCollectorInterface instance
270      */
271     public function addCollector(DataCollectorInterface $collector)
272     {
273         $this->collectors[$collector->getName()] = $collector;
274     }
275
276     /**
277      * Returns true if a Collector for the given name exists.
278      *
279      * @param string $name A collector name
280      *
281      * @return bool
282      */
283     public function hasCollector($name)
284     {
285         return isset($this->collectors[$name]);
286     }
287
288     public function __sleep()
289     {
290         return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time');
291     }
292 }