src/Domain/Entity/Address.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use App\Domain\Entity\Behavior\Identifiable;
  7. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  8. use Gedmo\Timestampable\Traits\Timestampable;
  9. /**
  10.  * Class Address
  11.  *
  12.  * @package App\Domain\Entity
  13.  */
  14. #[ApiResource(
  15.     operations: [
  16.         new Get(),
  17.         new GetCollection(),
  18.     ],
  19.     normalizationContext: ['groups' => ['address_read']],
  20.     denormalizationContext: ['groups' => ['address_write']]
  21. )]
  22. class Address
  23. {
  24.     use Identifiable;
  25.     use SoftDeleteable;
  26.     use Timestampable;
  27.     /**
  28.      * Address constructor.
  29.      *
  30.      * @param string $cityName
  31.      * @param string $streetName
  32.      * @param string $zipCode
  33.      * @param string|null $country
  34.      * @param string|null $addressAddIn
  35.      * @param string|null $cedex
  36.      * @param string|null $cityCode
  37.      * @param string|null $isoCode
  38.      * @param float|null $lat
  39.      * @param string|null $latCardinality
  40.      * @param float|null $lat1
  41.      * @param float|null $lat2
  42.      * @param float|null $lat3
  43.      * @param float|null $lng
  44.      * @param string|null $lngCardinality
  45.      * @param float|null $lng1
  46.      * @param float|null $lng2
  47.      * @param float|null $lng3
  48.      * @param int|null $remoteId
  49.      */
  50.     public function __construct(
  51.         public string $cityName,
  52.         public string $streetName,
  53.         public string $zipCode,
  54.         public ?string $country,
  55.         public ?string $addressAddIn null,
  56.         public ?string $cedex null,
  57.         public ?string $cityCode null,
  58.         public ?string $isoCode null,
  59.         public ?float $lat null,
  60.         public ?string $latCardinality null,
  61.         public ?float $lat1 null,
  62.         public ?float $lat2 null,
  63.         public ?float $lat3 null,
  64.         public ?float $lng null,
  65.         public ?string $lngCardinality null,
  66.         public ?float $lng1 null,
  67.         public ?float $lng2 null,
  68.         public ?float $lng3 null,
  69.         public ?string $remoteId null,
  70.     ) {
  71.     }
  72.     /**
  73.      * elasticsearch goe_point format
  74.      *
  75.      * @return array[lon, lat]
  76.      */
  77.     public function getGeoPoint(): array
  78.     {
  79.         return [$this->lng$this->lat];
  80.     }
  81.     public function getFormattedAddress(): string
  82.     {
  83.         return "$this->streetName$this->country";
  84.     }
  85. }