<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\HttpException;
class BackendBaseController extends AbstractController
{
protected $translationDomain = null;
public static function getSubscribedServices()
{
$services = array_merge(parent::getSubscribedServices(), [
'translator' => '?' . TranslatorInterface::class
]);
return $services;
}
public function beforeAction() { }
public function afterAction() { }
public function throwError400($message = '')
{
throw new HttpException(400, $message != '' ? $message : 'Bad request.');
}
public function throwError403($message = '')
{
throw new HttpException(403, $message != '' ? $message : 'Access denied.');
}
public function getReturnUrl($defaultUrl = null)
{
$request = $this->get('request_stack')->getCurrentRequest();
$returnUrl = $request->get('returnUrl');
if ($returnUrl == '')
$returnUrl = $defaultUrl !== null ? $defaultUrl : $this->generateUrl('app_project_index');
return $returnUrl;
}
public function returnToPreviousPage()
{
return $this->redirect($this->get('request_stack')->getCurrentRequest()->headers->get("referer"));
}
public function translate($text, array $params = [])
{
return $this->get('translator')->translate($text, $params, $this->translationDomain);
}
}