src/Service/DefaultCityProvider.php line 31

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-04-11
  5.  * Time: 20:35
  6.  */
  7. namespace App\Service;
  8. use App\Entity\Location\City;
  9. use App\Repository\CityRepository;
  10. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  11. class DefaultCityProvider
  12. {
  13.     protected string $cityName;
  14.     protected string $timezone;
  15.     protected string $timezoneCityName;
  16.     private ?City $city null;
  17.     public function __construct(
  18.         protected CityRepository $cityRepository,
  19.         ParameterBagInterface $parameterBag
  20.     )
  21.     {
  22.         $this->cityName $parameterBag->get('default_city');
  23.         $this->timezone $parameterBag->get('default_timezone');
  24.         $this->timezoneCityName $parameterBag->get('default_timezone.city_name');
  25.     }
  26.     public function getDefaultCity(): ?City
  27.     {
  28.         if (null === $this->city) {
  29.             $this->city $this->cityRepository->ofUriIdentity($this->cityName);
  30.         }
  31.         return $this->city;
  32.     }
  33.     public function getDefaultTimezone(): string
  34.     {
  35.         return $this->timezone;
  36.     }
  37.     public function getDefaultTimezoneCityName(): string
  38.     {
  39.         return $this->timezoneCityName;
  40.     }
  41. }