src/Model/Alias.php line 92

Open in your IDE?
  1. <?php
  2. namespace App\Model;
  3. use App\Util\Api;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use App\Validator\Constraints as KalmaAssert;
  6. class Alias implements \JsonSerializable
  7. {
  8.     
  9.     /* @Assert\Regex(
  10.         pattern = "/^[a-z0-9]+[a-z0-9-_.@+]*$/",
  11.         message = "alias.src.invalid"
  12.         )*/
  13.         
  14.     /**
  15.      * @Assert\NotBlank()
  16.      
  17.      * @KalmaAssert\KalmaEmailOrUsername()
  18.      * @Assert\Length(
  19.         min = 2,
  20.         minMessage = "alias.src.minLength"
  21.      )
  22.      */
  23.     private $src;
  24.     
  25.     /* @Assert\Regex(
  26.         pattern = "/^[a-z0-9_.@+]+$/",
  27.         message = "alias.dest.invalid"
  28.         )
  29.      */
  30.     
  31.     /**
  32.      * @Assert\NotBlank()
  33.      * @KalmaAssert\KalmaEmailOrUsername()
  34.      * @Assert\Length(
  35.         min = 2,
  36.         minMessage = "alias.dest.minLength"
  37.      )
  38.      */
  39.     private $dest;
  40.     private $description;
  41.     
  42.     const TOKEN_SALT 'TLfKBbrHusct3KvLdyhjks968NxZEPD9';
  43.     const SRC_REGEX '/^[a-z0-9]+[a-z0-9-_.,@+]*$/';
  44.     const SRC_REGEX_EDIT '/^[a-z0-9]+[a-z0-9-_.@+]*$/'// without a comma
  45.     const DEST_REGEX '/^[a-z0-9]+[a-z0-9-_.@,+]+$/';
  46.     const DEST_REGEX_EDIT '/^[a-z0-9]+[a-z0-9-_.@+]+$/'// without a comma
  47.     
  48.     public function __toString()
  49.     {
  50.         return $this->src ' -> ' $this->dest;
  51.     }
  52.     
  53.     public function getSrc(): ?string
  54.     {
  55.         return $this->src;
  56.     }
  57.     
  58.     public function setSrc(string $src): self
  59.     {
  60.         $this->src $src;
  61.         
  62.         return $this;
  63.     }
  64.     
  65.     public function getDest(): ?string
  66.     {
  67.         return $this->dest;
  68.     }
  69.     
  70.     public function setDest(string $dest): self
  71.     {
  72.         $this->dest $dest;
  73.         
  74.         return $this;
  75.     }
  76.     
  77.     public function getDescription(): ?string
  78.     {
  79.         return $this->description;
  80.     }
  81.     
  82.     public function setDescription(string $description): self
  83.     {
  84.         $this->description $description;
  85.         
  86.         return $this;
  87.     }
  88.     
  89.     public function jsonSerialize()
  90.     {
  91.         $vars get_object_vars($this);
  92.         return $vars;
  93.     }
  94.     
  95.     /**
  96.      * token crated from fields src and dest to prevent URL manipulations
  97.      * @return string token
  98.      */
  99.     public function token() :string
  100.     {
  101.         return md5($this->src Alias::TOKEN_SALT $this->dest);
  102.     }
  103.     
  104.     public function md5() : String
  105.     {
  106.         return md5($this->src $this->dest);
  107.     }
  108.     
  109.     /**
  110.      * delete alias
  111.      * @return TRUE - success, FALSE - failure
  112.      */
  113.     public function delete() : bool
  114.     {
  115.         return Api::deleteAlias($this);
  116.     }
  117.     
  118. }