src/Controller/DefaultController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. /**
  6.  * 作用说明:渲染默认入口模板,作为未命中具体接口时的基础页面入口? */
  7. class DefaultController  extends AbstractController
  8. {
  9.     private string $publicBaseUrl;
  10.     public function __construct(string $publicBaseUrl)
  11.     {
  12.         $this->publicBaseUrl rtrim($publicBaseUrl'/');
  13.     }
  14.     public function index(){
  15.         $indexFile $this->getParameter('kernel.project_dir') . '/public/index.html';
  16.         if (is_file($indexFile)) {
  17.             return new Response((string) file_get_contents($indexFile), 200, ['Content-Type' => 'text/html; charset=UTF-8']);
  18.         }
  19.         throw $this->createNotFoundException('Frontend entry file public/index.html was not built.');
  20.     }
  21.     public function paySession(string $payToken): Response
  22.     {
  23.         return $this->index();
  24.     }
  25.     private function absolutePublicUrl(string $path): string
  26.     {
  27.         return $this->publicBaseUrl !== '' $this->publicBaseUrl $path $path;
  28.     }
  29. }