src/Postroyka/AppBundle/Entity/Blacklist.php line 13

Open in your IDE?
  1. <?php
  2. namespace Postroyka\AppBundle\Entity;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity()
  7.  *
  8.  * @ORM\Table(name="blacklist")
  9.  */
  10. class Blacklist
  11. {
  12.     /**
  13.      * @var integer
  14.      *
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue(strategy="AUTO")
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @var DateTime
  22.      *
  23.      * @ORM\Column(type="datetime")
  24.      */
  25.     private $createdAt;
  26.     /**
  27.      * @var string
  28.      *
  29.      * @ORM\Column(type="string", nullable=true)
  30.      */
  31.     private $blockWay;
  32.     /**
  33.      * @var string
  34.      *
  35.      * @ORM\Column(type="string", nullable=true)
  36.      */
  37.     private $ip;
  38.     /**
  39.      * @param string $blockWay
  40.      * @param string $ip
  41.      */
  42.     public function __construct(string $blockWay, ?string $ip null)
  43.     {
  44.         $this->blockWay $blockWay;
  45.         $this->ip $ip ?: self::getClientIp();
  46.         $this->createdAt = new DateTime();
  47.     }
  48.     /**
  49.      * @return int
  50.      */
  51.     public function getId(): int
  52.     {
  53.         return $this->id;
  54.     }
  55.     /**
  56.      * @param int $id
  57.      */
  58.     public function setId(int $id): void
  59.     {
  60.         $this->id $id;
  61.     }
  62.     /**
  63.      * @return DateTime
  64.      */
  65.     public function getCreatedAt(): DateTime
  66.     {
  67.         return $this->createdAt;
  68.     }
  69.     /**
  70.      * @param DateTime $createdAt
  71.      */
  72.     public function setCreatedAt(DateTime $createdAt): void
  73.     {
  74.         $this->createdAt $createdAt;
  75.     }
  76.     /**
  77.      * @return string
  78.      */
  79.     public function getBlockWay(): string
  80.     {
  81.         return $this->blockWay;
  82.     }
  83.     /**
  84.      * @param string $blockWay
  85.      */
  86.     public function setBlockWay(string $blockWay): void
  87.     {
  88.         $this->blockWay $blockWay;
  89.     }
  90.     /**
  91.      * @return string
  92.      */
  93.     public function getIp(): string
  94.     {
  95.         return $this->ip;
  96.     }
  97.     /**
  98.      * @param string $ip
  99.      */
  100.     public function setIp(string $ip): void
  101.     {
  102.         $this->ip $ip;
  103.     }
  104.     static function getClientIp()
  105.     {
  106.         return isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] :
  107.             (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] :
  108.                 (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ""));
  109.     }
  110. }