<?php
namespace Postroyka\AppBundle\Entity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*
* @ORM\Table(name="blacklist")
*/
class Blacklist
{
/**
* @var integer
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var DateTime
*
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @var string
*
* @ORM\Column(type="string", nullable=true)
*/
private $blockWay;
/**
* @var string
*
* @ORM\Column(type="string", nullable=true)
*/
private $ip;
/**
* @param string $blockWay
* @param string $ip
*/
public function __construct(string $blockWay, ?string $ip = null)
{
$this->blockWay = $blockWay;
$this->ip = $ip ?: self::getClientIp();
$this->createdAt = new DateTime();
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return DateTime
*/
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @param DateTime $createdAt
*/
public function setCreatedAt(DateTime $createdAt): void
{
$this->createdAt = $createdAt;
}
/**
* @return string
*/
public function getBlockWay(): string
{
return $this->blockWay;
}
/**
* @param string $blockWay
*/
public function setBlockWay(string $blockWay): void
{
$this->blockWay = $blockWay;
}
/**
* @return string
*/
public function getIp(): string
{
return $this->ip;
}
/**
* @param string $ip
*/
public function setIp(string $ip): void
{
$this->ip = $ip;
}
static function getClientIp()
{
return isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] :
(isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] :
(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ""));
}
}