4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Profiler;
14 use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
19 * @author Fabien Potencier <fabien@symfony.com>
26 * @var DataCollectorInterface[]
28 private $collectors = array();
44 private $children = array();
49 * @param string $token The token
51 public function __construct($token)
53 $this->token = $token;
59 * @param string $token The token
61 public function setToken($token)
63 $this->token = $token;
69 * @return string The token
71 public function getToken()
77 * Sets the parent token.
79 * @param Profile $parent
81 public function setParent(Profile $parent)
83 $this->parent = $parent;
87 * Returns the parent profile.
91 public function getParent()
97 * Returns the parent token.
99 * @return null|string The parent token
101 public function getParentToken()
103 return $this->parent ? $this->parent->getToken() : null;
109 * @return string The IP
111 public function getIp()
121 public function setIp($ip)
127 * Returns the request method.
129 * @return string The request method
131 public function getMethod()
133 return $this->method;
136 public function setMethod($method)
138 $this->method = $method;
144 * @return string The URL
146 public function getUrl()
151 public function setUrl($url)
159 * @return int The time
161 public function getTime()
163 if (null === $this->time) {
171 * @param int The time
173 public function setTime($time)
179 * @param int $statusCode
181 public function setStatusCode($statusCode)
183 $this->statusCode = $statusCode;
189 public function getStatusCode()
191 return $this->statusCode;
195 * Finds children profilers.
199 public function getChildren()
201 return $this->children;
205 * Sets children profiler.
207 * @param Profile[] $children
209 public function setChildren(array $children)
211 $this->children = array();
212 foreach ($children as $child) {
213 $this->addChild($child);
218 * Adds the child token.
220 * @param Profile $child
222 public function addChild(Profile $child)
224 $this->children[] = $child;
225 $child->setParent($this);
229 * Gets a Collector by name.
231 * @param string $name A collector name
233 * @return DataCollectorInterface A DataCollectorInterface instance
235 * @throws \InvalidArgumentException if the collector does not exist
237 public function getCollector($name)
239 if (!isset($this->collectors[$name])) {
240 throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
243 return $this->collectors[$name];
247 * Gets the Collectors associated with this profile.
249 * @return DataCollectorInterface[]
251 public function getCollectors()
253 return $this->collectors;
257 * Sets the Collectors associated with this profile.
259 * @param DataCollectorInterface[] $collectors
261 public function setCollectors(array $collectors)
263 $this->collectors = array();
264 foreach ($collectors as $collector) {
265 $this->addCollector($collector);
272 * @param DataCollectorInterface $collector A DataCollectorInterface instance
274 public function addCollector(DataCollectorInterface $collector)
276 $this->collectors[$collector->getName()] = $collector;
280 * Returns true if a Collector for the given name exists.
282 * @param string $name A collector name
286 public function hasCollector($name)
288 return isset($this->collectors[$name]);
291 public function __sleep()
293 return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time');