app/Plugin/TwoFactorAuthCustomer42/Entity/TwoFactorAuthConfig.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\TwoFactorAuthCustomer42\Entity;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Eccube\Entity\AbstractEntity;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. /**
  18.  * TwoFactorConfig
  19.  *
  20.  * @ORM\Table(name="plg_two_factor_auth_config")
  21.  * @ORM\InheritanceType("SINGLE_TABLE")
  22.  * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  23.  * @ORM\HasLifecycleCallbacks()
  24.  * @ORM\Entity(repositoryClass="Plugin\TwoFactorAuthCustomer42\Repository\TwoFactorAuthConfigRepository")
  25.  * @UniqueEntity("id")
  26.  */
  27. class TwoFactorAuthConfig extends AbstractEntity
  28. {
  29.     /**
  30.      * @var int
  31.      *
  32.      * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue(strategy="IDENTITY")
  35.      */
  36.     private $id;
  37.     /**
  38.      * @var string
  39.      *
  40.      * @ORM\Column(name="api_key", type="string", nullable=true, length=200)
  41.      */
  42.     private $api_key null;
  43.     /**
  44.      * @var string
  45.      *
  46.      * @ORM\Column(name="api_secret", type="string", nullable=true, length=200)
  47.      */
  48.     private $api_secret null;
  49.     private $plain_api_secret;
  50.     /**
  51.      * @var string
  52.      *
  53.      * @ORM\Column(name="from_phone_number", type="string", nullable=true, length=200)
  54.      */
  55.     private $from_phone_number null;
  56.     /**
  57.      * @var string
  58.      *
  59.      * @ORM\Column(name="include_routes", type="text", nullable=true)
  60.      */
  61.     private $include_routes null;
  62.     /**
  63.      * Constructor.
  64.      */
  65.     public function __construct()
  66.     {
  67.     }
  68.     /**
  69.      * Get id.
  70.      *
  71.      * @return int
  72.      */
  73.     public function getId()
  74.     {
  75.         return $this->id;
  76.     }
  77.     /**
  78.      * Get api_key.
  79.      *
  80.      * @return string
  81.      */
  82.     public function getApiKey()
  83.     {
  84.         return $this->api_key;
  85.     }
  86.     /**
  87.      * Set api_key.
  88.      *
  89.      * @param string $apiKey
  90.      *
  91.      * @return TwoFactorAuthConfig
  92.      */
  93.     public function setApiKey($apiKey)
  94.     {
  95.         $this->api_key $apiKey;
  96.         return $this;
  97.     }
  98.     /**
  99.      * Get api_secret.
  100.      *
  101.      * @return string
  102.      */
  103.     public function getApiSecret()
  104.     {
  105.         return $this->api_secret;
  106.     }
  107.     /**
  108.      * Set api_secret.
  109.      *
  110.      * @param string $apiSecret
  111.      *
  112.      * @return TwoFactorAuthConfig
  113.      */
  114.     public function setApiSecret($apiSecret)
  115.     {
  116.         $this->api_secret $apiSecret;
  117.         return $this;
  118.     }
  119.     /**
  120.      * Get from phone number.
  121.      *
  122.      * @return string
  123.      */
  124.     public function getFromPhoneNumber()
  125.     {
  126.         return $this->from_phone_number;
  127.     }
  128.     /**
  129.      * Set from phone number.
  130.      *
  131.      * @param string $fromPhoneNumber
  132.      *
  133.      * @return TwoFactorAuthConfig
  134.      */
  135.     public function setFromPhoneNumber(string $fromPhoneNumber)
  136.     {
  137.         $this->from_phone_number $fromPhoneNumber;
  138.         return $this;
  139.     }
  140.     public function addIncludeRoute(string $route)
  141.     {
  142.         $routes $this->getRoutes($this->getIncludeRoutes());
  143.         if (!in_array($route$routes)) {
  144.             $this->setIncludeRoutes($this->include_routes.PHP_EOL.$route);
  145.         }
  146.         return $this;
  147.     }
  148.     private function getRoutes(?string $routes): array
  149.     {
  150.         if (!$routes) {
  151.             return [];
  152.         }
  153.         return explode(PHP_EOL$routes);
  154.     }
  155.     /**
  156.      * Get include_routes.
  157.      *
  158.      * @return string|null
  159.      */
  160.     public function getIncludeRoutes()
  161.     {
  162.         return $this->include_routes;
  163.     }
  164.     /**
  165.      * Set include_routes.
  166.      *
  167.      * @param string|null $include_routes
  168.      *
  169.      * @return TwoFactorAuthConfig
  170.      */
  171.     public function setIncludeRoutes($include_routes null)
  172.     {
  173.         $this->include_routes $include_routes;
  174.         return $this;
  175.     }
  176.     public function removeIncludeRoute(string $route)
  177.     {
  178.         $routes $this->getRoutes($this->getIncludeRoutes());
  179.         if (in_array($route$routes)) {
  180.             $routes array_diff($routes, [$route]);
  181.             $this->setIncludeRoutes($this->getRoutesAsString($routes));
  182.         }
  183.         return $this;
  184.     }
  185.     private function getRoutesAsString(array $routes): string
  186.     {
  187.         return implode(PHP_EOL$routes);
  188.     }
  189.     /**
  190.      * @param string|null $plain_api_secret
  191.      *
  192.      * @return TwoFactorAuthConfig
  193.      */
  194.     public function setPlainApiSecret(?string $plain_api_secret): TwoFactorAuthConfig
  195.     {
  196.         $this->plain_api_secret $plain_api_secret;
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return mixed
  201.      */
  202.     public function getPlainApiSecret(): ?string
  203.     {
  204.         return $this->plain_api_secret;
  205.     }
  206. }