src/Application/UseCase/Zones/GetNearestTownByLatLongHandler.php line 34

Open in your IDE?
  1. <?php
  2. namespace Whater\Application\UseCase\Zones;
  3. use Whater\Application\UseCase\AbstractCommandHandler;
  4. use Whater\Application\UseCase\Zones\CommandRequest\GetNearestTownByLatLongCommand;
  5. use Whater\Domain\Zones\Model\Town;
  6. use Whater\Domain\Zones\Repository\TownRepositoryInterface;
  7. /**
  8. * Class GetNearestTownByLatLongHandler
  9. * @package Whater\Application\UseCase\User
  10. */
  11. class GetNearestTownByLatLongHandler extends AbstractCommandHandler
  12. {
  13. /**
  14. * @var TownRepositoryInterface
  15. */
  16. private $repositoryTown;
  17. /**
  18. * @param TownRepositoryInterface $repositoryTown
  19. */
  20. public function __construct(TownRepositoryInterface $repositoryTown)
  21. {
  22. $this->repositoryTown = $repositoryTown;
  23. }
  24. /**
  25. * @param GetNearestTownByLatLongCommand $getNearestTownByLatLongCommand
  26. * @return null|Town
  27. */
  28. public function handle(GetNearestTownByLatLongCommand $getNearestTownByLatLongCommand): ?Town
  29. {
  30. // search nearest town in 20 Kms
  31. $town = $this->repositoryTown->findOneByNearestLatLong(
  32. $getNearestTownByLatLongCommand->latitude(),
  33. $getNearestTownByLatLongCommand->longitude(),
  34. $getNearestTownByLatLongCommand->kilometers(),
  35. $getNearestTownByLatLongCommand->searchName(),
  36. $getNearestTownByLatLongCommand->countryCode()
  37. );
  38. return $town;
  39. }
  40. }