Drupal investigation

ConfigDataCollector.php 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\DataCollector;
  11. use Symfony\Component\HttpKernel\KernelInterface;
  12. use Symfony\Component\HttpKernel\Kernel;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. /**
  16. * ConfigDataCollector.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class ConfigDataCollector extends DataCollector
  21. {
  22. /**
  23. * @var KernelInterface
  24. */
  25. private $kernel;
  26. private $name;
  27. private $version;
  28. private $cacheVersionInfo = true;
  29. /**
  30. * Constructor.
  31. *
  32. * @param string $name The name of the application using the web profiler
  33. * @param string $version The version of the application using the web profiler
  34. */
  35. public function __construct($name = null, $version = null)
  36. {
  37. $this->name = $name;
  38. $this->version = $version;
  39. }
  40. /**
  41. * Sets the Kernel associated with this Request.
  42. *
  43. * @param KernelInterface $kernel A KernelInterface instance
  44. */
  45. public function setKernel(KernelInterface $kernel = null)
  46. {
  47. $this->kernel = $kernel;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function collect(Request $request, Response $response, \Exception $exception = null)
  53. {
  54. $this->data = array(
  55. 'app_name' => $this->name,
  56. 'app_version' => $this->version,
  57. 'token' => $response->headers->get('X-Debug-Token'),
  58. 'symfony_version' => Kernel::VERSION,
  59. 'symfony_state' => 'unknown',
  60. 'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a',
  61. 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
  62. 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
  63. 'php_version' => PHP_VERSION,
  64. 'xdebug_enabled' => extension_loaded('xdebug'),
  65. 'eaccel_enabled' => extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'),
  66. 'apc_enabled' => extension_loaded('apc') && ini_get('apc.enabled'),
  67. 'xcache_enabled' => extension_loaded('xcache') && ini_get('xcache.cacher'),
  68. 'wincache_enabled' => extension_loaded('wincache') && ini_get('wincache.ocenabled'),
  69. 'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),
  70. 'bundles' => array(),
  71. 'sapi_name' => PHP_SAPI,
  72. );
  73. if (isset($this->kernel)) {
  74. foreach ($this->kernel->getBundles() as $name => $bundle) {
  75. $this->data['bundles'][$name] = $bundle->getPath();
  76. }
  77. $this->data['symfony_state'] = $this->determineSymfonyState();
  78. }
  79. }
  80. public function getApplicationName()
  81. {
  82. return $this->data['app_name'];
  83. }
  84. public function getApplicationVersion()
  85. {
  86. return $this->data['app_version'];
  87. }
  88. /**
  89. * Gets the token.
  90. *
  91. * @return string The token
  92. */
  93. public function getToken()
  94. {
  95. return $this->data['token'];
  96. }
  97. /**
  98. * Gets the Symfony version.
  99. *
  100. * @return string The Symfony version
  101. */
  102. public function getSymfonyVersion()
  103. {
  104. return $this->data['symfony_version'];
  105. }
  106. /**
  107. * Returns the state of the current Symfony release.
  108. *
  109. * @return string One of: unknown, dev, stable, eom, eol
  110. */
  111. public function getSymfonyState()
  112. {
  113. return $this->data['symfony_state'];
  114. }
  115. public function setCacheVersionInfo($cacheVersionInfo)
  116. {
  117. $this->cacheVersionInfo = $cacheVersionInfo;
  118. }
  119. /**
  120. * Gets the PHP version.
  121. *
  122. * @return string The PHP version
  123. */
  124. public function getPhpVersion()
  125. {
  126. return $this->data['php_version'];
  127. }
  128. /**
  129. * Gets the application name.
  130. *
  131. * @return string The application name
  132. */
  133. public function getAppName()
  134. {
  135. return $this->data['name'];
  136. }
  137. /**
  138. * Gets the environment.
  139. *
  140. * @return string The environment
  141. */
  142. public function getEnv()
  143. {
  144. return $this->data['env'];
  145. }
  146. /**
  147. * Returns true if the debug is enabled.
  148. *
  149. * @return bool true if debug is enabled, false otherwise
  150. */
  151. public function isDebug()
  152. {
  153. return $this->data['debug'];
  154. }
  155. /**
  156. * Returns true if the XDebug is enabled.
  157. *
  158. * @return bool true if XDebug is enabled, false otherwise
  159. */
  160. public function hasXDebug()
  161. {
  162. return $this->data['xdebug_enabled'];
  163. }
  164. /**
  165. * Returns true if EAccelerator is enabled.
  166. *
  167. * @return bool true if EAccelerator is enabled, false otherwise
  168. */
  169. public function hasEAccelerator()
  170. {
  171. return $this->data['eaccel_enabled'];
  172. }
  173. /**
  174. * Returns true if APC is enabled.
  175. *
  176. * @return bool true if APC is enabled, false otherwise
  177. */
  178. public function hasApc()
  179. {
  180. return $this->data['apc_enabled'];
  181. }
  182. /**
  183. * Returns true if Zend OPcache is enabled.
  184. *
  185. * @return bool true if Zend OPcache is enabled, false otherwise
  186. */
  187. public function hasZendOpcache()
  188. {
  189. return $this->data['zend_opcache_enabled'];
  190. }
  191. /**
  192. * Returns true if XCache is enabled.
  193. *
  194. * @return bool true if XCache is enabled, false otherwise
  195. */
  196. public function hasXCache()
  197. {
  198. return $this->data['xcache_enabled'];
  199. }
  200. /**
  201. * Returns true if WinCache is enabled.
  202. *
  203. * @return bool true if WinCache is enabled, false otherwise
  204. */
  205. public function hasWinCache()
  206. {
  207. return $this->data['wincache_enabled'];
  208. }
  209. /**
  210. * Returns true if any accelerator is enabled.
  211. *
  212. * @return bool true if any accelerator is enabled, false otherwise
  213. */
  214. public function hasAccelerator()
  215. {
  216. return $this->hasApc() || $this->hasZendOpcache() || $this->hasEAccelerator() || $this->hasXCache() || $this->hasWinCache();
  217. }
  218. public function getBundles()
  219. {
  220. return $this->data['bundles'];
  221. }
  222. /**
  223. * Gets the PHP SAPI name.
  224. *
  225. * @return string The environment
  226. */
  227. public function getSapiName()
  228. {
  229. return $this->data['sapi_name'];
  230. }
  231. /**
  232. * {@inheritdoc}
  233. */
  234. public function getName()
  235. {
  236. return 'config';
  237. }
  238. /**
  239. * Tries to retrieve information about the current Symfony version.
  240. *
  241. * @return string One of: dev, stable, eom, eol
  242. */
  243. private function determineSymfonyState()
  244. {
  245. $now = new \DateTime();
  246. $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
  247. $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month');
  248. if ($now > $eol) {
  249. $versionState = 'eol';
  250. } elseif ($now > $eom) {
  251. $versionState = 'eom';
  252. } elseif ('' !== Kernel::EXTRA_VERSION) {
  253. $versionState = 'dev';
  254. } else {
  255. $versionState = 'stable';
  256. }
  257. return $versionState;
  258. }
  259. }