'\d+'], normalizationContext: ['groups' => ['address:read']], ), new GetCollection( normalizationContext: ['groups' => ['address:read']], ), new Post( normalizationContext: ['groups' => ['address:read']], denormalizationContext: ['groups' => ['address:write']], security: "is_granted('ROLE_ADMIN')", ), new Patch( normalizationContext: ['groups' => ['address:read']], denormalizationContext: ['groups' => ['address:write']], security: "is_granted('ROLE_ADMIN')", ), ], security: "is_granted('ROLE_USER')", )] class Address { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] #[Groups(['address:read', 'supplier:read', 'customer:read', 'shipment:read'])] private ?int $id = null; #[ORM\Column(length: 120)] #[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])] private string $label = ''; #[ORM\Column(length: 180)] #[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])] private string $street = ''; #[ORM\Column(name: 'street2', length: 180, nullable: true)] #[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])] private ?string $street2 = null; #[ORM\Column(name: 'postal_code', length: 20)] #[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])] private string $postalCode = ''; #[ORM\Column(length: 120)] #[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])] private string $city = ''; #[ORM\Column(name: 'country_code', length: 2)] #[Groups(['address:read', 'supplier:read', 'customer:read', 'address:write'])] private string $countryCode = ''; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: Supplier::class, mappedBy: 'addresses')] private Collection $suppliers; /** * @var Collection */ #[ORM\OneToMany(targetEntity: Shipment::class, mappedBy: 'address')] private Collection $shipments; public function __construct() { $this->suppliers = new ArrayCollection(); $this->shipments = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getLabel(): string { return $this->label; } public function setLabel(string $label): self { $this->label = $label; return $this; } public function getStreet(): string { return $this->street; } public function setStreet(string $street): self { $this->street = $street; return $this; } public function getStreet2(): ?string { return $this->street2; } public function setStreet2(?string $street2): self { $this->street2 = $street2; return $this; } public function getPostalCode(): string { return $this->postalCode; } public function setPostalCode(string $postalCode): self { $this->postalCode = $postalCode; return $this; } public function getCity(): string { return $this->city; } public function setCity(string $city): self { $this->city = $city; return $this; } public function getCountryCode(): string { return $this->countryCode; } public function setCountryCode(string $countryCode): self { $this->countryCode = $countryCode; return $this; } #[Groups(['address:read', 'supplier:read', 'reception:read', 'shipment:read', 'customer:read'])] public function getFullAddress(): string { $parts = array_filter([ $this->street, $this->street2, trim(sprintf('%s %s', $this->postalCode, $this->city)), ]); return implode(', ', $parts); } /** * @return Collection */ public function getSuppliers(): Collection { return $this->suppliers; } /** * @return Collection */ public function getShipments(): Collection { return $this->shipments; } public function addShipment(Shipment $shipment): static { if (!$this->shipments->contains($shipment)) { $this->shipments->add($shipment); $shipment->setAddress($this); } return $this; } public function removeShipment(Shipment $shipment): static { if ($this->shipments->removeElement($shipment)) { // set the owning side to null (unless already changed) if ($shipment->getAddress() === $this) { $shipment->setAddress(null); } } return $this; } }