3 namespace Drupal\webprofiler\Profiler;
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Psr\Log\LoggerInterface;
7 use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
8 use Symfony\Component\HttpKernel\Profiler\Profile;
9 use Symfony\Component\HttpKernel\Profiler\Profiler as SymfonyProfiler;
10 use Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface;
15 class Profiler extends SymfonyProfiler {
18 * @var \Drupal\Core\Config\ConfigFactoryInterface $config
25 private $activeToolbarItems;
27 private $localStorage;
33 * @param \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface $storage
34 * A ProfilerStorageInterface instance
35 * @param \Psr\Log\LoggerInterface $logger
36 * A LoggerInterface instance
37 * @param \Drupal\Core\Config\ConfigFactoryInterface $config
39 public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = NULL, ConfigFactoryInterface $config) {
40 parent::__construct($storage, $logger);
42 $this->localStorage = $storage;
43 $this->localLogger = $logger;
45 $this->config = $config;
46 $this->activeToolbarItems = $this->config->get('webprofiler.config')
47 ->get('active_toolbar_items');
53 public function add(DataCollectorInterface $collector) {
54 // drupal collector should not be disabled
55 if ($collector->getName() == 'drupal') {
56 parent::add($collector);
59 if ($this->activeToolbarItems && array_key_exists($collector->getName(), $this->activeToolbarItems) && $this->activeToolbarItems[$collector->getName()] !== '0') {
60 parent::add($collector);
66 * @param \Symfony\Component\HttpKernel\Profiler\Profile $profile
70 public function updateProfile(Profile $profile) {
71 if (!($ret = $this->localStorage->write($profile)) && NULL !== $this->localLogger) {
72 $this->localLogger->warning('Unable to store the profiler information.');