src/Entity/EndCustomer.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Model\Country;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(
  9.  *     name="end_customer",
  10.  *     options={"collate"="utf8_swedish_ci"}
  11.  * )
  12.  * @ORM\HasLifecycleCallbacks
  13.  * @ORM\InheritanceType("SINGLE_TABLE")
  14.  * @ORM\DiscriminatorColumn(
  15.  *     name="entity",
  16.  *     type="string",
  17.  *     length=50
  18.  * )
  19.  * @ORM\DiscriminatorMap({
  20.  *     "company"="CompanyEndCustomer",
  21.  *     "document"="DocumentEndCustomer"
  22.  * })
  23.  */
  24. abstract class EndCustomer implements EntityInterface
  25. {
  26.     /**
  27.      * @ORM\Id
  28.      * @ORM\Column(
  29.      *     type="integer"
  30.      * )
  31.      * @ORM\GeneratedValue(
  32.      *     strategy="AUTO"
  33.      * )
  34.      *
  35.      * @var int|null
  36.      */
  37.     protected ?int $id null;
  38.     /**
  39.      * @ORM\Column(
  40.      *     type="string",
  41.      *     length=5,
  42.      *     nullable=true
  43.      * )
  44.      *
  45.      * @var string|null
  46.      */
  47.     protected ?string $country null;
  48.     /**
  49.      * @ORM\Column(
  50.      *     type="string",
  51.      *     length=1000
  52.      * )
  53.      * @Assert\NotBlank
  54.      *
  55.      * @var string
  56.      */
  57.     protected string $name;
  58.     /**
  59.      * @param string $name
  60.      */
  61.     public function __construct(string $name)
  62.     {
  63.         $this->name $name;
  64.     }
  65.     public function __clone()
  66.     {
  67.         $this->id null;
  68.     }
  69.     /**
  70.      * @return string
  71.      */
  72.     public function __toString(): string
  73.     {
  74.         $str $this->name;
  75.         if (null !== $country $this->getCountryName()) {
  76.             $str .= ', ' $country;
  77.         }
  78.         return $str;
  79.     }
  80.     /**
  81.      * @return string|null
  82.      */
  83.     public function getCountry(): ?string
  84.     {
  85.         return $this->country;
  86.     }
  87.     /**
  88.      * @return string|null
  89.      */
  90.     public function getCountryName(): ?string
  91.     {
  92.         if (null !== $this->country) {
  93.             $country = new Country($this->country);
  94.             return $country->getName();
  95.         }
  96.         return null;
  97.     }
  98.     /**
  99.      * @return int|null
  100.      */
  101.     public function getId(): ?int
  102.     {
  103.         return $this->id;
  104.     }
  105.     /**
  106.      * @return string
  107.      */
  108.     public function getName(): string
  109.     {
  110.         return $this->name;
  111.     }
  112.     /**
  113.      * @return array
  114.      */
  115.     public function serialize(): array
  116.     {
  117.         return [
  118.             'id' => $this->getId(),
  119.             'name' => $this->getName(),
  120.             'country' => $this->getCountry(),
  121.         ];
  122.     }
  123.     /**
  124.      * @param string|null $country
  125.      */
  126.     public function setCountry(?string $country): void
  127.     {
  128.         $this->country $country;
  129.     }
  130.     /**
  131.      * @param string $name
  132.      */
  133.     public function setName(string $name): void
  134.     {
  135.         $this->name $name;
  136.     }
  137. }