Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpKernel\Profiler; Chris@0: Chris@0: use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; Chris@0: Chris@0: /** Chris@0: * Profile. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class Profile Chris@0: { Chris@0: private $token; Chris@0: Chris@0: /** Chris@0: * @var DataCollectorInterface[] Chris@0: */ Chris@17: private $collectors = []; Chris@0: Chris@0: private $ip; Chris@0: private $method; Chris@0: private $url; Chris@0: private $time; Chris@0: private $statusCode; Chris@0: Chris@0: /** Chris@0: * @var Profile Chris@0: */ Chris@0: private $parent; Chris@0: Chris@0: /** Chris@0: * @var Profile[] Chris@0: */ Chris@17: private $children = []; Chris@0: Chris@0: /** Chris@0: * @param string $token The token Chris@0: */ Chris@0: public function __construct($token) Chris@0: { Chris@0: $this->token = $token; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the token. Chris@0: * Chris@0: * @param string $token The token Chris@0: */ Chris@0: public function setToken($token) Chris@0: { Chris@0: $this->token = $token; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the token. Chris@0: * Chris@0: * @return string The token Chris@0: */ Chris@0: public function getToken() Chris@0: { Chris@0: return $this->token; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the parent token. Chris@0: */ Chris@17: public function setParent(self $parent) Chris@0: { Chris@0: $this->parent = $parent; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the parent profile. Chris@0: * Chris@0: * @return self Chris@0: */ Chris@0: public function getParent() Chris@0: { Chris@0: return $this->parent; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the parent token. Chris@0: * Chris@17: * @return string|null The parent token Chris@0: */ Chris@0: public function getParentToken() Chris@0: { Chris@0: return $this->parent ? $this->parent->getToken() : null; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the IP. Chris@0: * Chris@0: * @return string The IP Chris@0: */ Chris@0: public function getIp() Chris@0: { Chris@0: return $this->ip; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the IP. Chris@0: * Chris@0: * @param string $ip Chris@0: */ Chris@0: public function setIp($ip) Chris@0: { Chris@0: $this->ip = $ip; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the request method. Chris@0: * Chris@0: * @return string The request method Chris@0: */ Chris@0: public function getMethod() Chris@0: { Chris@0: return $this->method; Chris@0: } Chris@0: Chris@0: public function setMethod($method) Chris@0: { Chris@0: $this->method = $method; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the URL. Chris@0: * Chris@0: * @return string The URL Chris@0: */ Chris@0: public function getUrl() Chris@0: { Chris@0: return $this->url; Chris@0: } Chris@0: Chris@0: public function setUrl($url) Chris@0: { Chris@0: $this->url = $url; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the time. Chris@0: * Chris@0: * @return int The time Chris@0: */ Chris@0: public function getTime() Chris@0: { Chris@0: if (null === $this->time) { Chris@0: return 0; Chris@0: } Chris@0: Chris@0: return $this->time; Chris@0: } Chris@0: Chris@0: /** Chris@14: * @param int $time The time Chris@0: */ Chris@0: public function setTime($time) Chris@0: { Chris@0: $this->time = $time; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @param int $statusCode Chris@0: */ Chris@0: public function setStatusCode($statusCode) Chris@0: { Chris@0: $this->statusCode = $statusCode; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return int Chris@0: */ Chris@0: public function getStatusCode() Chris@0: { Chris@0: return $this->statusCode; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Finds children profilers. Chris@0: * Chris@0: * @return self[] Chris@0: */ Chris@0: public function getChildren() Chris@0: { Chris@0: return $this->children; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets children profiler. Chris@0: * Chris@0: * @param Profile[] $children Chris@0: */ Chris@0: public function setChildren(array $children) Chris@0: { Chris@17: $this->children = []; Chris@0: foreach ($children as $child) { Chris@0: $this->addChild($child); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds the child token. Chris@0: */ Chris@17: public function addChild(self $child) Chris@0: { Chris@0: $this->children[] = $child; Chris@0: $child->setParent($this); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets a Collector by name. Chris@0: * Chris@0: * @param string $name A collector name Chris@0: * Chris@0: * @return DataCollectorInterface A DataCollectorInterface instance Chris@0: * Chris@0: * @throws \InvalidArgumentException if the collector does not exist Chris@0: */ Chris@0: public function getCollector($name) Chris@0: { Chris@0: if (!isset($this->collectors[$name])) { Chris@0: throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name)); Chris@0: } Chris@0: Chris@0: return $this->collectors[$name]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the Collectors associated with this profile. Chris@0: * Chris@0: * @return DataCollectorInterface[] Chris@0: */ Chris@0: public function getCollectors() Chris@0: { Chris@0: return $this->collectors; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the Collectors associated with this profile. Chris@0: * Chris@0: * @param DataCollectorInterface[] $collectors Chris@0: */ Chris@0: public function setCollectors(array $collectors) Chris@0: { Chris@17: $this->collectors = []; Chris@0: foreach ($collectors as $collector) { Chris@0: $this->addCollector($collector); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a Collector. Chris@0: */ Chris@0: public function addCollector(DataCollectorInterface $collector) Chris@0: { Chris@0: $this->collectors[$collector->getName()] = $collector; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns true if a Collector for the given name exists. Chris@0: * Chris@0: * @param string $name A collector name Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function hasCollector($name) Chris@0: { Chris@0: return isset($this->collectors[$name]); Chris@0: } Chris@0: Chris@0: public function __sleep() Chris@0: { Chris@17: return ['token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode']; Chris@0: } Chris@0: }