2
0

debugbar.html.php 9.5 KB

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