2015-02-11 09:59:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\Models\Cache;
|
2015-02-12 00:27:25 +01:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2015-02-11 09:59:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
* @Cache("READ_ONLY")
|
|
|
|
* @Table("cache_token")
|
|
|
|
*/
|
|
|
|
class Token
|
|
|
|
{
|
|
|
|
const CLASSNAME = __CLASS__;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @Column(type="string")
|
|
|
|
*/
|
|
|
|
protected $token;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(type="date")
|
|
|
|
*/
|
|
|
|
protected $expiresAt;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToOne(targetEntity="Client")
|
|
|
|
*/
|
|
|
|
protected $client;
|
|
|
|
|
2015-02-12 00:27:25 +01:00
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="Login", cascade={"persist", "remove"}, mappedBy="token")
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $logins;
|
|
|
|
|
2015-02-12 18:53:21 +01:00
|
|
|
/**
|
|
|
|
* @ManyToOne(targetEntity="Action", cascade={"persist", "remove"}, inversedBy="tokens")
|
|
|
|
* @JoinColumn(name="action_id", referencedColumnName="id")
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $action;
|
|
|
|
|
2015-02-11 09:59:41 +01:00
|
|
|
public function __construct($token, Client $client = null)
|
|
|
|
{
|
|
|
|
$this->token = $token;
|
2015-02-12 00:27:25 +01:00
|
|
|
$this->logins = new ArrayCollection();
|
2015-02-11 09:59:41 +01:00
|
|
|
$this->client = $client;
|
|
|
|
$this->expiresAt = new \DateTime(date('Y-m-d H:i:s', strtotime("+7 day")));
|
|
|
|
}
|
|
|
|
|
2015-02-12 00:27:25 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getLogins()
|
|
|
|
{
|
|
|
|
return $this->logins;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Login $login
|
|
|
|
*/
|
|
|
|
public function addLogin(Login $login)
|
|
|
|
{
|
|
|
|
$this->logins[] = $login;
|
|
|
|
$login->setToken($this);
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:53:21 +01:00
|
|
|
public function getAction()
|
|
|
|
{
|
|
|
|
return $this->action;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAction(Action $action)
|
|
|
|
{
|
|
|
|
$this->action = $action;
|
|
|
|
}
|
|
|
|
|
2015-02-11 09:59:41 +01:00
|
|
|
public function getToken()
|
|
|
|
{
|
|
|
|
return $this->token;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getExpiresAt()
|
|
|
|
{
|
|
|
|
return $this->expiresAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getClient()
|
|
|
|
{
|
|
|
|
return $this->client;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setToken($token)
|
|
|
|
{
|
|
|
|
$this->token = $token;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setExpiresAt(DateTime $expiresAt)
|
|
|
|
{
|
|
|
|
$this->expiresAt = $expiresAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setClient(Client $client)
|
|
|
|
{
|
|
|
|
$this->client = $client;
|
|
|
|
}
|
|
|
|
}
|