Version 1
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / DataCollector / PhpConfigDataCollector.php
1 <?php
2
3 namespace Drupal\webprofiler\DataCollector;
4
5 use Drupal\Core\Routing\LinkGeneratorTrait;
6 use Drupal\Core\StringTranslation\StringTranslationTrait;
7 use Drupal\webprofiler\DrupalDataCollectorInterface;
8 use Symfony\Component\HttpKernel\DataCollector\DataCollector;
9 use Symfony\Component\HttpFoundation\Request;
10 use Symfony\Component\HttpFoundation\Response;
11
12 /**
13  * Provides a data collector to collect all kind of php information.
14  */
15 class PhpConfigDataCollector extends DataCollector implements DrupalDataCollectorInterface {
16
17   use StringTranslationTrait, DrupalDataCollectorTrait, LinkGeneratorTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public function collect(Request $request, Response $response, \Exception $exception = NULL) {
23     $this->data = [
24       'token' => $response->headers->get('X-Debug-Token'),
25       'php_version' => PHP_VERSION,
26       'xdebug_enabled' => extension_loaded('xdebug'),
27       'xhprof_enabled' => extension_loaded('xhprof'),
28       'eaccel_enabled' => extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'),
29       'apc_enabled' => extension_loaded('apc') && ini_get('apc.enabled'),
30       'xcache_enabled' => extension_loaded('xcache') && ini_get('xcache.cacher'),
31       'wincache_enabled' => extension_loaded('wincache') && ini_get('wincache.ocenabled'),
32       'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),
33       'sapi_name' => php_sapi_name()
34     ];
35   }
36
37   /**
38    * Gets the token.
39    *
40    * @return string The token
41    */
42   public function getToken() {
43     return $this->data['token'];
44   }
45
46   /**
47    * Gets the PHP version.
48    *
49    * @return string The PHP version
50    */
51   public function getPhpVersion() {
52     return $this->data['php_version'];
53   }
54
55   /**
56    * Returns true if the XDebug is enabled.
57    *
58    * @return Boolean true if XDebug is enabled, false otherwise
59    */
60   public function hasXDebug() {
61     return $this->data['xdebug_enabled'];
62   }
63
64   /**
65    * Returns true if the XHProf is enabled.
66    *
67    * @return Boolean true if XHProf is enabled, false otherwise
68    */
69   public function hasXHProf() {
70     return $this->data['xhprof_enabled'];
71   }
72
73   /**
74    * Returns true if EAccelerator is enabled.
75    *
76    * @return Boolean true if EAccelerator is enabled, false otherwise
77    */
78   public function hasEAccelerator() {
79     return $this->data['eaccel_enabled'];
80   }
81
82   /**
83    * Returns true if APC is enabled.
84    *
85    * @return Boolean true if APC is enabled, false otherwise
86    */
87   public function hasApc() {
88     return $this->data['apc_enabled'];
89   }
90
91   /**
92    * Returns true if Zend OPcache is enabled
93    *
94    * @return Boolean true if Zend OPcache is enabled, false otherwise
95    */
96   public function hasZendOpcache() {
97     return $this->data['zend_opcache_enabled'];
98   }
99
100   /**
101    * Returns true if XCache is enabled.
102    *
103    * @return Boolean true if XCache is enabled, false otherwise
104    */
105   public function hasXCache() {
106     return $this->data['xcache_enabled'];
107   }
108
109   /**
110    * Returns true if WinCache is enabled.
111    *
112    * @return Boolean true if WinCache is enabled, false otherwise
113    */
114   public function hasWinCache() {
115     return $this->data['wincache_enabled'];
116   }
117
118   /**
119    * Returns true if any accelerator is enabled.
120    *
121    * @return Boolean true if any accelerator is enabled, false otherwise
122    */
123   public function hasAccelerator() {
124     return $this->hasApc() || $this->hasZendOpcache() || $this->hasEAccelerator() || $this->hasXCache() || $this->hasWinCache();
125   }
126
127   /**
128    * Gets the PHP SAPI name.
129    *
130    * @return string The environment
131    */
132   public function getSapiName() {
133     return $this->data['sapi_name'];
134   }
135
136   /**
137    * {@inheritdoc}
138    */
139   public function getTitle() {
140     return $this->t('PHP Config');
141   }
142
143   /**
144    * {@inheritdoc}
145    */
146   public function getPanelSummary() {
147     return $this->t('PHP: @version', ['@version' => $this->getPhpVersion()]);
148   }
149
150   /**
151    * {@inheritdoc}
152    */
153   public function getName() {
154     return 'php_config';
155   }
156
157   /**
158    * {@inheritdoc}
159    */
160   public function getIcon() {
161     return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAMAAAC5xgRsAAAAZlBMVEX///////////////////////////////////////////////////////////////////////////////////////////+ZmZmZmZlISEhJSUmdnZ1HR0fR0dFZWVlpaWlfX18/Pz+puygPAAAAIXRSTlMACwwlJygpLzIzNjs8QEtMUmd6e32AucDBw8fIydTm6u5l8MjvAAAAo0lEQVR42r2P2Q6CMBBFL6XsZRGRfZv//0nbDBNEE19MnJeTc5ILKf58ahiUwzy/AJpIWwREwQnEXRdbGCLjrO+djWRvVMiJcigxB7viGogxDdJpSmHEmCVPS7YczJvgUu+CS30IvtbNYZMvsGVo2mVpG/kbm4auiCpdcC3YPCAhSpAdUzaAn6qPKZtUT6ZSzb4bi2hdo9MQ1nX4ASjfV+/4/Z40pyCHrNTbIgAAAABJRU5ErkJggg==';
162   }
163 }