src/Controller/BackendBaseController.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpKernel\Exception\HttpException;
  5. class BackendBaseController extends AbstractController
  6. {
  7.     protected $translationDomain null;
  8.     
  9.     public static function getSubscribedServices()
  10.     {
  11.         $services array_merge(parent::getSubscribedServices(), [
  12.                 'translator' => '?' TranslatorInterface::class
  13.             ]);
  14.         
  15.         return $services;
  16.     }
  17.     public function beforeAction() { }
  18.     public function afterAction() { }
  19.     public function throwError400($message '')
  20.     {
  21.         throw new HttpException(400$message != '' $message 'Bad request.');
  22.     }
  23.     public function throwError403($message '')
  24.     {
  25.         throw new HttpException(403$message != '' $message 'Access denied.');
  26.     }
  27.     
  28.     public function getReturnUrl($defaultUrl null)
  29.     {
  30.         $request $this->get('request_stack')->getCurrentRequest();
  31.         
  32.         $returnUrl $request->get('returnUrl');
  33.         
  34.         if ($returnUrl == '')
  35.             $returnUrl $defaultUrl !== null $defaultUrl $this->generateUrl('app_project_index');
  36.             
  37.         return $returnUrl;
  38.     }
  39.     
  40.     public function returnToPreviousPage()
  41.     {
  42.         return $this->redirect($this->get('request_stack')->getCurrentRequest()->headers->get("referer"));
  43.     }
  44.     
  45.     public function translate($text, array $params = [])
  46.     {
  47.         return $this->get('translator')->translate($text$params$this->translationDomain);
  48.     }
  49. }