HomeController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. namespace Glacier\Controllers;
  4. use Glacier\Core\Logger;
  5. use Glacier\Core\Response;
  6. /**
  7. * 首页控制器(本期"开发中"占位;后期公司新闻 + 功能导航)。
  8. * P1 暂用内联 HTML,P2 切换为 Twig 模板渲染。
  9. */
  10. final class HomeController
  11. {
  12. public function index(array $params = []): never
  13. {
  14. Response::html($this->page('Glacier · 开发中', '<h1>Glacier 公司管理系统</h1><p>开发中,敬请期待。</p>'));
  15. }
  16. /** 参数路由演示(P1 验证用,后续移除)。 */
  17. public function demo(array $params = []): never
  18. {
  19. $name = $params['name'] ?? '';
  20. Logger::info('demo route hit', ['name' => $name]);
  21. Response::html($this->page('Demo · ' . $name, '<h1>参数路由演示</h1><p>参数 <code>name</code> = ' . e($name) . '</p>'));
  22. }
  23. /** 可选段演示(P1 验证用,后续移除)。 */
  24. public function demoPage(array $params = []): never
  25. {
  26. $page = $params['page'] ?? '1';
  27. Response::html($this->page('DemoPage · ' . $page, '<h1>可选段演示</h1><p>当前页 = ' . e($page) . '</p>'));
  28. }
  29. private function page(string $title, string $body): string
  30. {
  31. return '<!doctype html><html lang="zh-CN"><head><meta charset="utf-8">'
  32. . '<meta name="viewport" content="width=device-width, initial-scale=1">'
  33. . '<title>' . e($title) . '</title>'
  34. . '<style>body{font-family:system-ui,sans-serif;max-width:800px;margin:40px auto;padding:0 16px;color:#333}'
  35. . 'h1{color:#0b7a5f;border-bottom:2px solid #0b7a5f;padding-bottom:8px}'
  36. . 'code{background:#f0f0f0;padding:2px 6px;border-radius:4px}</style>'
  37. . '</head><body>' . $body . '</body></html>';
  38. }
  39. }