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();
47 * @param string $token The token
49 public function __construct($token)
51 $this->token = $token;
57 * @param string $token The token
59 public function setToken($token)
61 $this->token = $token;
67 * @return string The token
69 public function getToken()
75 * Sets the parent token.
77 public function setParent(Profile $parent)
79 $this->parent = $parent;
83 * Returns the parent profile.
87 public function getParent()
93 * Returns the parent token.
95 * @return string|null The parent token
97 public function getParentToken()
99 return $this->parent ? $this->parent->getToken() : null;
105 * @return string The IP
107 public function getIp()
117 public function setIp($ip)
123 * Returns the request method.
125 * @return string The request method
127 public function getMethod()
129 return $this->method;
132 public function setMethod($method)
134 $this->method = $method;
140 * @return string The URL
142 public function getUrl()
147 public function setUrl($url)
155 * @return int The time
157 public function getTime()
159 if (null === $this->time) {
167 * @param int $time The time
169 public function setTime($time)
175 * @param int $statusCode
177 public function setStatusCode($statusCode)
179 $this->statusCode = $statusCode;
185 public function getStatusCode()
187 return $this->statusCode;
191 * Finds children profilers.
195 public function getChildren()
197 return $this->children;
201 * Sets children profiler.
203 * @param Profile[] $children
205 public function setChildren(array $children)
207 $this->children = array();
208 foreach ($children as $child) {
209 $this->addChild($child);
214 * Adds the child token.
216 public function addChild(Profile $child)
218 $this->children[] = $child;
219 $child->setParent($this);
223 * Gets a Collector by name.
225 * @param string $name A collector name
227 * @return DataCollectorInterface A DataCollectorInterface instance
229 * @throws \InvalidArgumentException if the collector does not exist
231 public function getCollector($name)
233 if (!isset($this->collectors[$name])) {
234 throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
237 return $this->collectors[$name];
241 * Gets the Collectors associated with this profile.
243 * @return DataCollectorInterface[]
245 public function getCollectors()
247 return $this->collectors;
251 * Sets the Collectors associated with this profile.
253 * @param DataCollectorInterface[] $collectors
255 public function setCollectors(array $collectors)
257 $this->collectors = array();
258 foreach ($collectors as $collector) {
259 $this->addCollector($collector);
266 public function addCollector(DataCollectorInterface $collector)
268 $this->collectors[$collector->getName()] = $collector;
272 * Returns true if a Collector for the given name exists.
274 * @param string $name A collector name
278 public function hasCollector($name)
280 return isset($this->collectors[$name]);
283 public function __sleep()
285 return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode');