LocationResponseMapper.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Rest\EntityMapper;
  6. use Temando\Shipping\Model\LocationInterface;
  7. use Temando\Shipping\Model\LocationInterfaceFactory;
  8. use Temando\Shipping\Rest\Response\DataObject\Location;
  9. /**
  10. * Map API data to application data object
  11. *
  12. * @package Temando\Shipping\Rest
  13. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  14. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  15. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. * @link http://www.temando.com/
  17. */
  18. class LocationResponseMapper
  19. {
  20. /**
  21. * @var LocationInterfaceFactory
  22. */
  23. private $locationFactory;
  24. /**
  25. * LocationResponseMapper constructor.
  26. * @param LocationInterfaceFactory $locationFactory
  27. */
  28. public function __construct(LocationInterfaceFactory $locationFactory)
  29. {
  30. $this->locationFactory = $locationFactory;
  31. }
  32. /**
  33. * @param Location $apiLocation
  34. * @return LocationInterface
  35. */
  36. public function map(Location $apiLocation)
  37. {
  38. $location = $this->locationFactory->create(['data' => [
  39. LocationInterface::LOCATION_ID => $apiLocation->getId(),
  40. LocationInterface::NAME => $apiLocation->getAttributes()->getName(),
  41. LocationInterface::UNIQUE_IDENTIFIER => $apiLocation->getAttributes()->getUniqueId(),
  42. LocationInterface::TYPE => $apiLocation->getAttributes()->getType(),
  43. LocationInterface::STREET => $apiLocation->getAttributes()->getAddress()->getLines(),
  44. LocationInterface::POSTAL_CODE => $apiLocation->getAttributes()->getAddress()->getPostalCode(),
  45. LocationInterface::IS_DEFAULT => (bool)$apiLocation->getAttributes()->getIsDefault(),
  46. ]]);
  47. return $location;
  48. }
  49. }