<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 2019-04-11
* Time: 20:35
*/
namespace App\Service;
use App\Entity\Location\City;
use App\Repository\CityRepository;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class DefaultCityProvider
{
protected string $cityName;
protected string $timezone;
protected string $timezoneCityName;
private ?City $city = null;
public function __construct(
protected CityRepository $cityRepository,
ParameterBagInterface $parameterBag
)
{
$this->cityName = $parameterBag->get('default_city');
$this->timezone = $parameterBag->get('default_timezone');
$this->timezoneCityName = $parameterBag->get('default_timezone.city_name');
}
public function getDefaultCity(): ?City
{
if (null === $this->city) {
$this->city = $this->cityRepository->ofUriIdentity($this->cityName);
}
return $this->city;
}
public function getDefaultTimezone(): string
{
return $this->timezone;
}
public function getDefaultTimezoneCityName(): string
{
return $this->timezoneCityName;
}
}