<?phpnamespace App\Entity;use App\Repository\SharedAddressRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Gedmo\Blameable\Traits\BlameableEntity;use Gedmo\Timestampable\Traits\TimestampableEntity;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: SharedAddressRepository::class)]class SharedAddress{ use BlameableEntity; //Hook blameable behaviour. Updates createdBy, updatedBy fields use TimestampableEntity; //Hook timestampable behaviour. Updates createdAt, updatedAt fields #[ORM\Id] #[ORM\GeneratedValue(strategy: "IDENTITY")] #[ORM\Column] private ?int $id = null; #[ORM\ManyToOne(inversedBy: 'sharedAddressesToMe')] #[ORM\JoinColumn(nullable: false)] #[Assert\NotNull()] private ?User $userToShare = null; #[ORM\ManyToOne(inversedBy: 'sharedAddresses')] #[ORM\JoinColumn(nullable: false)] #[Assert\NotNull()] private ?Address $address = null; /** * We want to select in which products we want to share the address * * @var Collection */ #[ORM\ManyToMany(targetEntity: Product::class)] private Collection $sharedProducts; public function __construct() { $this->sharedProducts = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getUserToShare(): ?User { return $this->userToShare; } public function setUserToShare(?User $userToShare): self { $this->userToShare = $userToShare; return $this; } public function getAddress(): ?Address { return $this->address; } public function setAddress(?Address $address): self { $this->address = $address; return $this; } /** * @return Collection<int, Product> */ public function getSharedProducts(): Collection { return $this->sharedProducts; } public function addSharedProduct(Product $excludedProduct): self { if (!$this->sharedProducts->contains($excludedProduct)) { $this->sharedProducts->add($excludedProduct); } return $this; } public function removeSharedProduct(Product $excludedProduct): self { $this->sharedProducts->removeElement($excludedProduct); return $this; }}