/web/modules/contrib/devel/webprofiler/src/DataCollector/PhpConfigDataCollector.php

https://gitlab.com/andecode/theme-spark · PHP · 163 lines · 69 code · 21 blank · 73 comment · 9 complexity · 394abcf16311f66af47ab320478b6290 MD5 · raw file

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