src/Entity/Customer.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CustomerRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. #[ORM\Entity(repositoryClassCustomerRepository::class)]
  9. class Customer
  10. {
  11.     use TimestampableEntity;
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length500)]
  17.     private ?string $name null;
  18.     #[ORM\OneToMany(mappedBy'customer'targetEntityOrder::class)]
  19.     private Collection $orders;
  20.     public function __construct()
  21.     {
  22.         $this->orders = new ArrayCollection();
  23.     }
  24.     public function getId(): ?int
  25.     {
  26.         return $this->id;
  27.     }
  28.     public function getName(): ?string
  29.     {
  30.         return $this->name;
  31.     }
  32.     public function setName(string $name): self
  33.     {
  34.         $this->name $name;
  35.         return $this;
  36.     }
  37.     /**
  38.      * @return Collection<int, Order>
  39.      */
  40.     public function getOrders(): Collection
  41.     {
  42.         return $this->orders;
  43.     }
  44.     public function addOrder(Order $order): self
  45.     {
  46.         if (!$this->orders->contains($order)) {
  47.             $this->orders->add($order);
  48.             $order->setCustomer($this);
  49.         }
  50.         return $this;
  51.     }
  52.     public function removeOrder(Order $order): self
  53.     {
  54.         if ($this->orders->removeElement($order)) {
  55.             // set the owning side to null (unless already changed)
  56.             if ($order->getCustomer() === $this) {
  57.                 $order->setCustomer(null);
  58.             }
  59.         }
  60.         return $this;
  61.     }
  62. }