2
0

debugbar.html.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. /**
  3. * @var array $profiler [
  4. * '@timestamp' => (new DateTimeImmutable())->format('c'),
  5. * 'log.level' => 'debug',
  6. * 'id' => $request->getAttribute('request_id', 'unknown'),
  7. * 'event.duration' => $duration,
  8. * 'metrics' => [
  9. * 'memory.usage' => $this->convertMemory(memory_get_usage(true)),
  10. * 'memory.peak' => $this->convertMemory(memory_get_peak_usage(true)),
  11. * 'load_time.ms' => $duration * 1000,
  12. * 'load_time.s' => number_format($duration, 3),
  13. * ],
  14. * 'http.request' => [
  15. * 'method' => $request->getMethod(),
  16. * 'url' => $request->getUri()->__toString(),
  17. * 'path' => $request->getUri()->getPath(),
  18. * 'body' => $request->getBody()->getContents(),
  19. * 'headers' => $request->getHeaders(),
  20. * 'query' => $request->getQueryParams(),
  21. * 'post' => $request->getParsedBody() ?? [],
  22. * 'cookies' => $request->getCookieParams(),
  23. * 'protocol' => $request->getProtocolVersion(),
  24. * 'server' => $request->getServerParams(),
  25. * ],
  26. * ]
  27. */
  28. ?>
  29. <div id="__michel_debug_app"></div>
  30. <template id="__michel_debug_template">
  31. <style>
  32. .__michel_debug_navbar {
  33. background-color: #1e232d;
  34. position: fixed;
  35. right: 0;
  36. bottom: 0;
  37. width: 100%;
  38. display: flex;
  39. height: 40px;
  40. font-family: Inter, sans-serif;
  41. white-space: nowrap;
  42. z-index: 10000;
  43. }
  44. .__michel_debug_navbar a {
  45. color: rgb(166, 223, 239);
  46. display: block;
  47. text-align: center;
  48. padding: 12px 14px;
  49. text-decoration: none;
  50. font-size: 12px;
  51. }
  52. .__michel_debug_navbar a:hover {
  53. background-color: #07193e;
  54. }
  55. .__michel_debug_navbar a:hover > .__michel_debug_value {
  56. transform: scale(1.05);
  57. }
  58. .__michel_debug_value {
  59. font-weight: bold;
  60. font-size: 11px;
  61. color: #ececec;
  62. display: inline-block;
  63. }
  64. .__michel_dropup {
  65. position: relative;
  66. display: inline-block;
  67. }
  68. .__michel_dropup-content {
  69. font-size: 12px;
  70. display: none;
  71. position: absolute;
  72. background-color: #1e232d;
  73. max-width: 450px;
  74. max-height: 480px;
  75. bottom: 40px;
  76. overflow: hidden;
  77. overflow-y: auto;
  78. padding: 10px;
  79. z-index: 100000;
  80. vertical-align: baseline;
  81. letter-spacing: normal;
  82. white-space: nowrap;
  83. }
  84. .__michel_dropup-content a:hover {
  85. background-color: inherit;
  86. }
  87. .__michel_dropup:hover .__michel_dropup-content {
  88. display: block;
  89. }
  90. .__michel_table {
  91. border-collapse: collapse;
  92. border-spacing: 0;
  93. width: 100%;
  94. border: 0px;
  95. color: #a4a4a4;
  96. }
  97. .__michel_table th, td {
  98. text-align: left;
  99. padding: 6px;
  100. }
  101. .__michel_label {
  102. padding: 4px;
  103. }
  104. .__michel_label_success {
  105. background-color: #04AA6D;
  106. }
  107. /* Green */
  108. .__michel_label_info {
  109. background-color: #2196F3;
  110. }
  111. /* Blue */
  112. .__michel_label_warning {
  113. background-color: #ff9800;
  114. }
  115. /* Orange */
  116. .__michel_label_danger {
  117. background-color: #f44336;
  118. }
  119. /* Red */
  120. .__michel_label_other {
  121. background-color: #e7e7e7;
  122. color: black;
  123. }
  124. /* Gray */
  125. </style>
  126. <div class="__michel_debug_navbar">
  127. <div class="__michel_dropup">
  128. <a href="#response">
  129. <?php if ($profiler['__response_code'] >= 200 && $profiler['__response_code'] < 300) : ?>
  130. 🚦 <span class="__michel_label __michel_label_success"><span
  131. class="__michel_debug_value"><?php echo $profiler['__response_code'] ?></span></span>
  132. <?php elseif ($profiler['__response_code'] >= 300 && $profiler['__response_code'] < 400) : ?>
  133. 🚦 <span class="__michel_label __michel_label_info"><span
  134. class="__michel_debug_value"><?php echo $profiler['__response_code'] ?></span></span>
  135. <?php elseif ($profiler['__response_code'] >= 400 && $profiler['__response_code'] < 500) : ?>
  136. 🚦 <span class="__michel_label __michel_label_warning"><span
  137. class="__michel_debug_value"><?php echo $profiler['__response_code'] ?></span></span>
  138. <?php else : ?>
  139. 🚦 <span class="__michel_label __michel_label_danger"><span
  140. class="__michel_debug_value"><?php echo $profiler['__response_code'] ?></span></span>
  141. <?php endif; ?>
  142. </a>
  143. <div class="__michel_dropup-content">
  144. <table class="__michel_table">
  145. <tr>
  146. <td>HTTP status <Ver></Ver></td>
  147. <td class="__michel_debug_value" title="<?php echo $profiler['__response_code'] ?>"><?php echo $profiler['__response_code'] ?></td>
  148. </tr>
  149. <?php if (isset($profiler['__controller'])) : ?>
  150. <tr>
  151. <td>Controller</td>
  152. <td class="__michel_debug_value" title="<?php echo $profiler['__controller'] ?>"><?php echo $profiler['__controller'] ?></td>
  153. </tr>
  154. <?php endif; ?>
  155. <?php if (isset($profiler['__route_name'])) : ?>
  156. <tr>
  157. <td>Route name</td>
  158. <td class="__michel_debug_value" title="<?php echo $profiler['__route_name'] ?>"><?php echo $profiler['__route_name'] ?></td>
  159. </tr>
  160. <?php endif; ?>
  161. </table>
  162. </div>
  163. </div>
  164. <a href="#time">
  165. 🕒 [REQ] <span class="__michel_debug_value"><?php echo $profiler['metrics']['load_time.ms'] ?> ms</span>
  166. </a>
  167. <a href="#memory">
  168. 💾 [MEM] <span class="__michel_debug_value"><?php echo $profiler['metrics']['memory.peak.human'] ?></span>
  169. </a>
  170. <a href="#request">
  171. 🌐 [METHOD] <span class="__michel_debug_value"><?php echo $profiler['http.request']['method'] ?></span>
  172. </a>
  173. <a href="#env">
  174. 🛠️ [ENV] <span class="__michel_debug_value"><?php echo strtoupper($profiler['environment']) ?></span>
  175. </a>
  176. <div class="__michel_dropup">
  177. <a href="#">
  178. 🐘 [PHP] <span class="__michel_debug_value"><?php echo $profiler['php_version'] ?></span>
  179. </a>
  180. <div class="__michel_dropup-content">
  181. <table class="__michel_table">
  182. <tr>
  183. <td>PHP Version</td>
  184. <td class="__michel_debug_value"
  185. title="<?php echo $profiler['php_version'] ?>"><?php echo $profiler['php_version'] ?></td>
  186. </tr>
  187. <tr>
  188. <td>PHP Extensions</td>
  189. <td class="__michel_debug_value"
  190. title="<?php echo $profiler['php_extensions'] ?>"><?php echo $profiler['php_extensions'] ?></td>
  191. </tr>
  192. <tr>
  193. <td>PHP SAPI</td>
  194. <td class="__michel_debug_value"
  195. title="<?php echo $profiler['php_sapi'] ?>"><?php echo $profiler['php_sapi'] ?></td>
  196. </tr>
  197. <tr>
  198. <td>PHP Memory Limit</td>
  199. <td class="__michel_debug_value"
  200. title="<?php echo $profiler['php_memory_limit'] ?>"><?php echo $profiler['php_memory_limit'] ?></td>
  201. </tr>
  202. <tr>
  203. <td>PHP Timezone</td>
  204. <td class="__michel_debug_value"
  205. title="<?php echo $profiler['php_timezone'] ?>"><?php echo $profiler['php_timezone'] ?></td>
  206. </tr>
  207. </table>
  208. </div>
  209. </div>
  210. <?php if (isset($profiler['__middlewares_executed'])) : ?>
  211. <div class="__michel_dropup">
  212. <a href="#" title="Middlewares executed">
  213. 🔀 [MID] <span class="__michel_debug_value"><?php echo count($profiler['__middlewares_executed']) ?></span>
  214. </a>
  215. <div class="__michel_dropup-content">
  216. <table class="__michel_table">
  217. <?php foreach ($profiler['__middlewares_executed'] as $index => $middleware) : ?>
  218. <tr>
  219. <td>
  220. <span class="__michel_debug_value"><?php echo sprintf('%s. %s', $index + 1, $middleware) ?></span>
  221. </td>
  222. </tr>
  223. <?php endforeach; ?>
  224. </table>
  225. </div>
  226. </div>
  227. <?php endif; ?>
  228. </div>
  229. </template>
  230. <script>
  231. (function() {
  232. const host = document.getElementById('__michel_debug_app');
  233. const template = document.getElementById('__michel_debug_template');
  234. const shadow = host.attachShadow({mode: 'open'});
  235. shadow.appendChild(template.content.cloneNode(true));
  236. })();
  237. </script>