src/App/Entity/System/Twilio/TwilioCallerId.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System\Twilio;
  3. use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableInterface;
  4. use Cms\CoreBundle\Model\Interfaces\Loggable\LoggableInterface;
  5. use Cms\TenantBundle\Entity\TenantedEntity;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JsonSerializable;
  8. use Ramsey\Uuid\UuidInterface;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. /**
  11.  * Class TwilioCallerId
  12.  * @package App\Entity\System\Twilio
  13.  *
  14.  * @ORM\Entity(
  15.  *     repositoryClass = "App\Doctrine\Repository\System\Twilio\TwilioCallerIdRepository",
  16.  * )
  17.  * @ORM\Table(
  18.  *     name = "sys__twilio_caller_id",
  19.  *     uniqueConstraints = {
  20.  *         @ORM\UniqueConstraint(
  21.  *             name = "uidx__tenant__phone_number",
  22.  *             columns = {
  23.  *                 "tenant",
  24.  *                 "phoneNumber",
  25.  *             },
  26.  *         ),
  27.  *         @ORM\UniqueConstraint(
  28.  *             name = "uidx__tenant__name",
  29.  *             columns = {
  30.  *                 "tenant",
  31.  *                 "name",
  32.  *             },
  33.  *         ),
  34.  *     },
  35.  * )
  36.  */
  37. class TwilioCallerId extends TenantedEntity implements JsonSerializableLoggableInterface
  38. {
  39.     const STATUSES__SUCCESS 'success';
  40.     const STATUSES__FAILED 'failed';
  41.     /**
  42.      * @var TwilioConfig|null
  43.      *
  44.      * @ORM\ManyToOne(
  45.      *     targetEntity = "App\Entity\System\Twilio\TwilioConfig",
  46.      *     inversedBy = "callerIds",
  47.      * )
  48.      * @ORM\JoinColumn(
  49.      *     name = "config",
  50.      *     referencedColumnName = "id",
  51.      *     nullable = false,
  52.      *     onDelete = "CASCADE",
  53.      * )
  54.      */
  55.     protected ?TwilioConfig $config null;
  56.     /**
  57.      * @var string|null
  58.      *
  59.      * @ORM\Column(
  60.      *     type = "string",
  61.      *     nullable = false,
  62.      * )
  63.      *
  64.      * @Groups("message_details")
  65.      */
  66.     protected ?string $name null;
  67.     /**
  68.      * @var string|null
  69.      *
  70.      * @ORM\Column(
  71.      *     type = "string",
  72.      *     nullable = false,
  73.      * )
  74.      */
  75.     protected ?string $phoneNumber null;
  76.     /**
  77.      * @var string|null
  78.      *
  79.      * @ORM\Column(
  80.      *     type = "string",
  81.      *     nullable = true,
  82.      * )
  83.      */
  84.     protected ?string $verificationExtension null;
  85.     /**
  86.      * @var string|null
  87.      *
  88.      * @ORM\Column(
  89.      *     type = "string",
  90.      *     nullable = true,
  91.      * )
  92.      */
  93.     protected ?string $verificationValidationCode null;
  94.     /**
  95.      * @var string|null
  96.      *
  97.      * @ORM\Column(
  98.      *     type = "string",
  99.      *     nullable = true,
  100.      * )
  101.      */
  102.     protected ?string $verificationCallSid null;
  103.     /**
  104.      * @var string|null
  105.      *
  106.      * @ORM\Column(
  107.      *     type = "string",
  108.      *     nullable = true,
  109.      * )
  110.      */
  111.     protected ?string $verificationStatus null;
  112.     /**
  113.      * @var string|null
  114.      *
  115.      * @ORM\Column(
  116.      *     type = "string",
  117.      *     nullable = true,
  118.      * )
  119.      */
  120.     protected ?string $twilioOutgoingCallerIdSid null;
  121.     /**
  122.      * @return TwilioConfig|null
  123.      */
  124.     public function getConfig(): ?TwilioConfig
  125.     {
  126.         return $this->config;
  127.     }
  128.     /**
  129.      * @param TwilioConfig $config
  130.      * @return $this
  131.      */
  132.     public function setConfig(TwilioConfig $config): self
  133.     {
  134.         $this->config $config;
  135.         return $this;
  136.     }
  137.     /**
  138.      * @return string|null
  139.      */
  140.     public function getName(): ?string
  141.     {
  142.         return $this->name;
  143.     }
  144.     /**
  145.      * @param string $name
  146.      * @return $this
  147.      */
  148.     public function setName(string $name): self
  149.     {
  150.         $this->name $name;
  151.         return $this;
  152.     }
  153.     /**
  154.      * @return string|null
  155.      */
  156.     public function getPhoneNumber(): ?string
  157.     {
  158.         return $this->phoneNumber;
  159.     }
  160.     /**
  161.      * @param string $phoneNumber
  162.      * @return $this
  163.      */
  164.     public function setPhoneNumber(string $phoneNumber): self
  165.     {
  166.         $this->phoneNumber $phoneNumber;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return string|null
  171.      */
  172.     public function getVerificationExtension(): ?string
  173.     {
  174.         return $this->verificationExtension;
  175.     }
  176.     /**
  177.      * @param string|null $verificationExtension
  178.      * @return $this
  179.      */
  180.     public function setVerificationExtension(?string $verificationExtension): self
  181.     {
  182.         $this->verificationExtension $verificationExtension;
  183.         return $this;
  184.     }
  185.     /**
  186.      * @return string|null
  187.      */
  188.     public function getVerificationValidationCode(): ?string
  189.     {
  190.         return $this->verificationValidationCode;
  191.     }
  192.     /**
  193.      * @param string|null $verificationValidationCode
  194.      * @return $this
  195.      */
  196.     public function setVerificationValidationCode(?string $verificationValidationCode): self
  197.     {
  198.         $this->verificationValidationCode $verificationValidationCode;
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return string|null
  203.      */
  204.     public function getVerificationCallSid(): ?string
  205.     {
  206.         return $this->verificationCallSid;
  207.     }
  208.     /**
  209.      * @param string|null $verificationCallSid
  210.      * @return $this
  211.      */
  212.     public function setVerificationCallSid(?string $verificationCallSid): self
  213.     {
  214.         $this->verificationCallSid $verificationCallSid;
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return string|null
  219.      */
  220.     public function getVerificationStatus(): ?string
  221.     {
  222.         return $this->verificationStatus;
  223.     }
  224.     /**
  225.      * @param string|null $verificationStatus
  226.      * @return $this
  227.      */
  228.     public function setVerificationStatus(?string $verificationStatus): self
  229.     {
  230.         $this->verificationStatus $verificationStatus;
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return string|null
  235.      */
  236.     public function getTwilioOutgoingCallerIdSid(): ?string
  237.     {
  238.         return $this->twilioOutgoingCallerIdSid;
  239.     }
  240.     /**
  241.      * @param string|null $twilioOutgoingCallerIdSid
  242.      * @return $this
  243.      */
  244.     public function setTwilioOutgoingCallerIdSid(?string $twilioOutgoingCallerIdSid): self
  245.     {
  246.         $this->twilioOutgoingCallerIdSid $twilioOutgoingCallerIdSid;
  247.         return $this;
  248.     }
  249.     /**
  250.      * @return bool
  251.      */
  252.     public function isInitiated(): bool
  253.     {
  254.         return ( ! empty($this->getVerificationCallSid()));
  255.     }
  256.     /**
  257.      * @return bool
  258.      */
  259.     public function isCompleted(): bool
  260.     {
  261.         return ( ! empty($this->getVerificationStatus()));
  262.     }
  263.     /**
  264.      * @return bool
  265.      */
  266.     public function isSuccessful(): bool
  267.     {
  268.         return ($this->getVerificationStatus() === self::STATUSES__SUCCESS);
  269.     }
  270.     /**
  271.      * @return bool
  272.      */
  273.     public function isFailed(): bool
  274.     {
  275.         return ($this->getVerificationStatus() === self::STATUSES__FAILED);
  276.     }
  277.     /**
  278.      * @return bool
  279.      */
  280.     public function isVerified(): bool
  281.     {
  282.         return ( ! empty($this->getTwilioOutgoingCallerIdSid()));
  283.     }
  284.     /**
  285.      * {@inheritDoc}
  286.      */
  287.     public function jsonSerialize(): array
  288.     {
  289.         static $refl null;
  290.         $formatter = static function ($value, callable $formatter) {
  291.             switch (true) {
  292.                 case is_scalar($value):
  293.                     return $value;
  294.                 case is_array($value):
  295.                     $data = [];
  296.                     foreach ($value as $k => $v) {
  297.                         $data[$k] = $formatter($v$formatter);
  298.                     }
  299.                     ksort($data);
  300.                     return $data;
  301.                 case $value instanceof UuidInterface:
  302.                     return $value->__toString();
  303.                 case $value instanceof IdentifiableInterface:
  304.                     return $value->getId();
  305.                 case $value instanceof \DateTimeInterface:
  306.                     return $value->format(\DateTimeInterface::RFC3339);
  307.                 case $value instanceof JsonSerializable:
  308.                     return $value->jsonSerialize();
  309.                 default:
  310.                     return null;
  311.             }
  312.         };
  313.         if ( ! $refl) {
  314.             $refl = new \ReflectionObject($this);
  315.         }
  316.         $data = [];
  317.         foreach ($refl->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) {
  318.             $property->setAccessible(true);
  319.             $data[$property->getName()] = $formatter(
  320.                 $property->getValue($this),
  321.                 $formatter
  322.             );
  323.             $property->setAccessible(false);
  324.         }
  325.         ksort($data);
  326.         return $data;
  327.     }
  328.     /**
  329.      * {@inheritDoc}
  330.      */
  331.     public function getLoggableDetails(): array
  332.     {
  333.         return [
  334.             'id' => (string) $this->getId(),
  335.             'title' => $this->getName(),
  336.         ];
  337.     }
  338. }