. */ namespace Volkszaehler\Model; use Volkszaehler\Util; /** * Token entity * * @author Steffen Vogel * @package default * @todo this is a draft! has to be discussed and implemented * * @Entity * @Table(name="tokens") */ class Token { /** * @Id * @Column(type="smallint", nullable=false) * @GeneratedValue(strategy="AUTO") * * @todo wait until DDC-117 is fixed (PKs on FKs) */ protected $id; /** * @Column(type="string", nullable=false, unique=true) */ protected $token; /** * var integer timestamp until token is valid * * @Column(type="bigint") * @todo to be implemented */ protected $valid; /** * @ManyToOne(targetEntity="Entity", inversedBy="tokens") */ protected $entity; const LENGTH = 10; protected static $chars = array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'v', 'u', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'V', 'U', 'W', 'X', 'Y', 'Z' ); /** * Constructor * * @param integer $length of the token */ public function __construct() { $this->token = self::generate(); } protected static function generate($length = Token::LENGTH) { return Util\Random::getString(self::$chars, $length); } public function __toString() { return $this->getToken(); } public function getToken() { return $this->token; } } ?>