vendor/can/rest/src/Can/RestBundle/Controller/FallbackController.php line 55

Open in your IDE?
  1. <?php
  2. namespace Can\RestBundle\Controller;
  3. use Can\RestBundle\Caching\CacheHeader;
  4. use Can\RestBundle\EventListener\ErrorListener;
  5. use Can\RestBundle\Problem\ProblemConfiguration;
  6. use Symfony\Component\ErrorHandler\Exception\FlattenException;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  10. use Exception;
  11. use Throwable;
  12. /**
  13.  * Fallback controller.
  14.  *
  15.  * This controller is used when a problem occurs handling a request which is
  16.  * outside the scope of the REST service.
  17.  *
  18.  * Most often, if the REST service does not live together with other services
  19.  * in the same application, all request to undefined endpoints (which will
  20.  * result in a 404 response) are forwarded here.
  21.  *
  22.  * Feel free to extend this controller to implement a more elaborated error
  23.  * handling logic.
  24.  *
  25.  * @see ErrorListener
  26.  * @see ProblemConfiguration::$catchAll
  27.  *
  28.  * @package can/rest-bundle
  29.  * @author lechecacharro <lechecacharro@gmail.com>
  30.  */
  31. class FallbackController
  32. {
  33.     /**
  34.      * @noinspection PhpUnusedParameterInspection
  35.      *
  36.      * Fallback Action.
  37.      *
  38.      * The default implementation just returns an immutable 410 (Gone)
  39.      * response.
  40.      *
  41.      * @see ErrorListener
  42.      *
  43.      * @param Request                                  $request
  44.      * @param FlattenException | Exception | Throwable $exception
  45.      * @param DebugLoggerInterface | null              $logger
  46.      *
  47.      * @return Response
  48.      */
  49.     public function index(Request $request$exceptionDebugLoggerInterface $logger null): Response
  50.     {
  51.         return $this->gone();
  52.     }
  53.     /**
  54.      * @return Response
  55.      */
  56.     protected function gone(): Response
  57.     {
  58.         // Response is not going to change over time
  59.         $response = new Response(''410);
  60.         $response->headers->set(CacheHeader::CACHE_CONTROL'public, max-age=31536000, immutable');
  61.         $response->headers->set(CacheHeader::EXPIRESdate('r'strtotime('+1 year')));
  62.         return $response;
  63.     }
  64. }