src/Factory/Dto/WorkExample/WorkExampleWithAddressesDtoFactory.php line 48

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slivki\Factory\Dto\WorkExample;
  4. use Slivki\Dto\WorkExample\WorkExampleAddressWithDistanceDto;
  5. use Slivki\Dto\WorkExample\WorkExampleWithAddressesDto;
  6. use Slivki\Entity\GeoLocation;
  7. use Slivki\Entity\WorkExample;
  8. use Slivki\Response\Beauty\Offer\Factory\MasterResponseFactory;
  9. use Slivki\Services\Seo\SeoResourceService;
  10. use Slivki\ValueObject\Coordinate;
  11. use Symfony\Component\HttpFoundation\UrlHelper;
  12. use function array_map;
  13. final class WorkExampleWithAddressesDtoFactory
  14. {
  15.     private SeoResourceService $seoResourceService;
  16.     private UrlHelper $urlHelper;
  17.     private WorkExampleAddressWithDistanceDtoFactory $workExampleAddressWithDistanceDtoFactory;
  18.     private MasterResponseFactory $masterResponseFactory;
  19.     public function __construct(
  20.         SeoResourceService $seoResourceService,
  21.         UrlHelper $urlHelper,
  22.         WorkExampleAddressWithDistanceDtoFactory $workExampleAddressWithDistanceDtoFactory,
  23.         MasterResponseFactory $masterResponseFactory
  24.     ) {
  25.         $this->seoResourceService $seoResourceService;
  26.         $this->urlHelper $urlHelper;
  27.         $this->workExampleAddressWithDistanceDtoFactory $workExampleAddressWithDistanceDtoFactory;
  28.         $this->masterResponseFactory $masterResponseFactory;
  29.     }
  30.     public function create(WorkExample $workExample, ?Coordinate $currentUserPosition): WorkExampleWithAddressesDto
  31.     {
  32.         $offerId $workExample->getOffer()->getID();
  33.         return new WorkExampleWithAddressesDto(
  34.             $workExample->getId(),
  35.             $offerId,
  36.             $this->seoResourceService->getOfferUrlWithDomain($offerId),
  37.             array_map(
  38.                 fn (GeoLocation $geoLocation): WorkExampleAddressWithDistanceDto =>
  39.                 $this->workExampleAddressWithDistanceDtoFactory->create($geoLocation$currentUserPosition),
  40.                 $workExample->getGeoLocations()->toArray(),
  41.             ),
  42.             null !== $workExample->getBeautyMaster()
  43.                 ? $this->masterResponseFactory->create($workExample->getBeautyMaster())
  44.                 : null,
  45.             null === $workExample->getImageUrl() ? null $this->urlHelper->getAbsoluteUrl($workExample->getImageUrl()),
  46.             $workExample->getDescription(),
  47.             $workExample->getPrice(),
  48.         );
  49.     }
  50. }