vendor/roothirsch/core-bundle/Site/SiteProvider.php line 64

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\CoreBundle\Site;
  3. use Doctrine\DBAL\Exception\InvalidFieldNameException;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Gedmo\Translatable\Entity\Repository\TranslationRepository;
  6. use Gedmo\Translatable\Entity\Translation;
  7. use Roothirsch\CoreBundle\Site\Entity\Site;
  8. use Roothirsch\CoreBundle\Site\Repository\SiteRepository;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. class SiteProvider
  11. {
  12. /**
  13. * @var Entity\Site|null
  14. */
  15. private $site;
  16. /**
  17. * Undocumented variable
  18. *
  19. * @var Request
  20. */
  21. protected $request;
  22. private $repository;
  23. private TranslationRepository $translationRepository;
  24. /**
  25. * @return string
  26. */
  27. public function getTitle()
  28. {
  29. $translations = $this->getTranslations();
  30. if($this->request) {
  31. if(array_key_exists($this->request->getLocale(), $translations)){
  32. return $translations[$this->request->getLocale()]['title'];
  33. }
  34. }
  35. return $this->getSite()->getTitle();
  36. }
  37. /**
  38. * @return string
  39. */
  40. public function getLogo()
  41. {
  42. return $this->getSite()->getLogo();
  43. }
  44. /**
  45. * @return string
  46. */
  47. public function getTheme()
  48. {
  49. if(!$this->request){
  50. return $this->getSite()->getTheme();
  51. }
  52. $overrideTheme = $this->request->get('_override_theme', false);
  53. if ($overrideTheme !== false) {
  54. return $overrideTheme;
  55. }
  56. return $this->getSite()->getTheme();
  57. }
  58. public function getWebsite(){
  59. return $this->getSite()->getWebsite();
  60. }
  61. public function getHostUrl(){
  62. return $this->request->server->get("HTTP_ORIGIN");
  63. }
  64. public function getAddress(){
  65. return $this->getSite()->getAddress();
  66. }
  67. public function getCompany(){
  68. return $this->getSite()->getCompany();
  69. }
  70. public function getTax() {
  71. return $this->getSite()->getTax();
  72. }
  73. /**
  74. * SettingsProvider constructor.
  75. */
  76. public function __construct(RequestStack $requestStack, EntityManagerInterface $entityManager)
  77. {
  78. try {
  79. $this->translationRepository = $entityManager->getRepository(Translation::class);
  80. $this->repository = $entityManager->getRepository(Site::class);
  81. $this->request = $requestStack->getCurrentRequest();
  82. } catch(InvalidFieldNameException $e) {
  83. }
  84. }
  85. public function getSite() {
  86. if (empty($this->site)) {
  87. $this->site = $this->repository->findOneBy(["id"=>1]);
  88. }
  89. return $this->site;
  90. }
  91. public function getTranslations()
  92. {
  93. return $this->translationRepository->findTranslations($this->getSite());
  94. }
  95. }