<?phpnamespace Roothirsch\CoreBundle\Site;use Doctrine\DBAL\Exception\InvalidFieldNameException;use Doctrine\ORM\EntityManagerInterface;use Gedmo\Translatable\Entity\Repository\TranslationRepository;use Gedmo\Translatable\Entity\Translation;use Roothirsch\CoreBundle\Site\Entity\Site;use Roothirsch\CoreBundle\Site\Repository\SiteRepository;use Symfony\Component\HttpFoundation\RequestStack;class SiteProvider{ /** * @var Entity\Site|null */ private $site; /** * Undocumented variable * * @var Request */ protected $request; private $repository; private TranslationRepository $translationRepository; /** * @return string */ public function getTitle() { $translations = $this->getTranslations(); if($this->request) { if(array_key_exists($this->request->getLocale(), $translations)){ return $translations[$this->request->getLocale()]['title']; } } return $this->getSite()->getTitle(); } /** * @return string */ public function getLogo() { return $this->getSite()->getLogo(); } /** * @return string */ public function getTheme() { if(!$this->request){ return $this->getSite()->getTheme(); } $overrideTheme = $this->request->get('_override_theme', false); if ($overrideTheme !== false) { return $overrideTheme; } return $this->getSite()->getTheme(); } public function getWebsite(){ return $this->getSite()->getWebsite(); } public function getHostUrl(){ return $this->request->server->get("HTTP_ORIGIN"); } public function getAddress(){ return $this->getSite()->getAddress(); } public function getCompany(){ return $this->getSite()->getCompany(); } public function getTax() { return $this->getSite()->getTax(); } public function isMaintenanceEnabled() { return $this->getSite()->isMaintenanceEnabled(); } public function getMaintenanceMessage() { $translations = $this->getTranslations(); if($this->request) { if(array_key_exists($this->request->getLocale(), $translations) && isset($translations[$this->request->getLocale()]['maintenanceMessage'])){ return $translations[$this->request->getLocale()]['maintenanceMessage']; } } return $this->getSite()->getMaintenanceMessage(); } /** * SettingsProvider constructor. */ public function __construct(RequestStack $requestStack, EntityManagerInterface $entityManager) { try { $this->translationRepository = $entityManager->getRepository(Translation::class); $this->repository = $entityManager->getRepository(Site::class); $this->request = $requestStack->getCurrentRequest(); } catch(InvalidFieldNameException $e) { } } public function getSite() { if (empty($this->site)) { $this->site = $this->repository->findOneBy(["id"=>1]); } return $this->site; } public function getTranslations() { return $this->translationRepository->findTranslations($this->getSite()); }}