Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / DataCollector / DrupalDataCollector.php
1 <?php
2
3 namespace Drupal\webprofiler\DataCollector;
4
5 use Drupal;
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;
16
17 /**
18  * Class DrupalDataCollector
19  */
20 class DrupalDataCollector extends DataCollector implements DrupalDataCollectorInterface {
21
22   use StringTranslationTrait, DrupalDataCollectorTrait;
23
24   /**
25    * @var \Drupal\Core\Routing\RedirectDestinationInterface
26    */
27   private $redirectDestination;
28
29   /**
30    * @var \Drupal\Core\Routing\UrlGeneratorInterface
31    */
32   private $urlGenerator;
33
34   /**
35    * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirectDestination
36    * @param \Drupal\Core\Routing\UrlGeneratorInterface $urlGenerator
37    */
38   public function __construct(RedirectDestinationInterface $redirectDestination, UrlGeneratorInterface $urlGenerator) {
39     $this->redirectDestination = $redirectDestination;
40     $this->urlGenerator = $urlGenerator;
41   }
42
43   /**
44    * {@inheritdoc}
45    */
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();
50
51     try {
52       $process = new Process("git log -1 --pretty=format:'%H - %s (%ci)' --abbrev-commit");
53       $process->setTimeout(3600);
54       $process->mustRun();
55       $this->data['git_commit'] = $process->getOutput();
56
57       $process = new Process("git log -1 --pretty=format:'%h' --abbrev-commit");
58       $process->setTimeout(3600);
59       $process->mustRun();
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;
65     }
66   }
67
68   /**
69    * @return string
70    */
71   public function getVersion() {
72     return $this->data['version'];
73   }
74
75   /**
76    * @return string
77    */
78   public function getProfile() {
79     return $this->data['profile'];
80   }
81
82   /**
83    * @return string
84    */
85   public function getConfigUrl() {
86     return $this->data['config_url'];
87   }
88
89   /**
90    * @return string
91    */
92   public function getGitCommit() {
93     return $this->data['git_commit'];
94   }
95
96   /**
97    * @return string
98    */
99   public function getAbbrGitCommit() {
100     return $this->data['abbr_git_commit'];
101   }
102
103   /**
104    * Returns the name of the collector.
105    *
106    * @return string The collector name
107    *
108    * @api
109    */
110   public function getName() {
111     return 'drupal';
112   }
113
114   /**
115    * {@inheritdoc}
116    */
117   public function getTitle() {
118     return $this->t('Drupal');
119   }
120
121   /**
122    * {@inheritdoc}
123    */
124   public function hasPanel() {
125     return FALSE;
126   }
127
128   /**
129    * {@inheritdoc}
130    */
131   public function getIcon() {
132     return 'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPS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