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 string The time
161 public function getTime()
163 if (null === $this->time) {
170 public function setTime($time)
176 * @param int $statusCode
178 public function setStatusCode($statusCode)
180 $this->statusCode = $statusCode;
186 public function getStatusCode()
188 return $this->statusCode;
192 * Finds children profilers.
196 public function getChildren()
198 return $this->children;
202 * Sets children profiler.
204 * @param Profile[] $children
206 public function setChildren(array $children)
208 $this->children = array();
209 foreach ($children as $child) {
210 $this->addChild($child);
215 * Adds the child token.
217 * @param Profile $child
219 public function addChild(Profile $child)
221 $this->children[] = $child;
222 $child->setParent($this);
226 * Gets a Collector by name.
228 * @param string $name A collector name
230 * @return DataCollectorInterface A DataCollectorInterface instance
232 * @throws \InvalidArgumentException if the collector does not exist
234 public function getCollector($name)
236 if (!isset($this->collectors[$name])) {
237 throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
240 return $this->collectors[$name];
244 * Gets the Collectors associated with this profile.
246 * @return DataCollectorInterface[]
248 public function getCollectors()
250 return $this->collectors;
254 * Sets the Collectors associated with this profile.
256 * @param DataCollectorInterface[] $collectors
258 public function setCollectors(array $collectors)
260 $this->collectors = array();
261 foreach ($collectors as $collector) {
262 $this->addCollector($collector);
269 * @param DataCollectorInterface $collector A DataCollectorInterface instance
271 public function addCollector(DataCollectorInterface $collector)
273 $this->collectors[$collector->getName()] = $collector;
277 * Returns true if a Collector for the given name exists.
279 * @param string $name A collector name
283 public function hasCollector($name)
285 return isset($this->collectors[$name]);
288 public function __sleep()
290 return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time');