3 namespace Drupal\webprofiler\DataCollector;
6 use Drupal\Core\Routing\RedirectDestinationInterface;
7 use Drupal\Core\Routing\UrlGeneratorInterface;
8 use Drupal\webprofiler\DrupalDataCollectorInterface;
9 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 use Symfony\Component\HttpFoundation\Request;
11 use Symfony\Component\HttpFoundation\Response;
12 use Symfony\Component\HttpKernel\DataCollector\DataCollector;
13 use Symfony\Component\Process\Exception\ProcessFailedException;
14 use Symfony\Component\Process\Exception\RuntimeException;
15 use Symfony\Component\Process\Process;
18 * Class DrupalDataCollector
20 class DrupalDataCollector extends DataCollector implements DrupalDataCollectorInterface {
22 use StringTranslationTrait, DrupalDataCollectorTrait;
25 * @var \Drupal\Core\Routing\RedirectDestinationInterface
27 private $redirectDestination;
30 * @var \Drupal\Core\Routing\UrlGeneratorInterface
32 private $urlGenerator;
35 * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirectDestination
36 * @param \Drupal\Core\Routing\UrlGeneratorInterface $urlGenerator
38 public function __construct(RedirectDestinationInterface $redirectDestination, UrlGeneratorInterface $urlGenerator) {
39 $this->redirectDestination = $redirectDestination;
40 $this->urlGenerator = $urlGenerator;
46 public function collect(Request $request, Response $response, \Exception $exception = NULL) {
47 $this->data['version'] = Drupal::VERSION;
48 $this->data['profile'] = drupal_get_profile();
49 $this->data['config_url'] = (new Drupal\Core\Url('webprofiler.settings', [], ['query' => $this->redirectDestination->getAsArray()]))->toString();
52 $process = new Process("git log -1 --pretty=format:'%H - %s (%ci)' --abbrev-commit");
53 $process->setTimeout(3600);
55 $this->data['git_commit'] = $process->getOutput();
57 $process = new Process("git log -1 --pretty=format:'%h' --abbrev-commit");
58 $process->setTimeout(3600);
60 $this->data['abbr_git_commit'] = $process->getOutput();
61 } catch (ProcessFailedException $e) {
62 $this->data['git_commit'] = $this->data['git_commit_abbr'] = NULL;
63 } catch (RuntimeException $e) {
64 $this->data['git_commit'] = $this->data['git_commit_abbr'] = NULL;
71 public function getVersion() {
72 return $this->data['version'];
78 public function getProfile() {
79 return $this->data['profile'];
85 public function getConfigUrl() {
86 return $this->data['config_url'];
92 public function getGitCommit() {
93 return $this->data['git_commit'];
99 public function getAbbrGitCommit() {
100 return $this->data['abbr_git_commit'];
104 * Returns the name of the collector.
106 * @return string The collector name
110 public function getName() {
117 public function getTitle() {
118 return $this->t('Drupal');
124 public function hasPanel() {
131 public function getIcon() {
132 return 'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCRDU5MUVDNzVGRTkxMUUzODdBMEJDOEZFRjA2QUY5MiIgeG1wTU06RG9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