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