setAPIKey($this->generateAPIKey()) ->setSecretKey($this->generateSecretKey()); // set date created $this->date_create = new DateTime(); $this->roles = new ArrayCollection(); } public function getID() { return $this->id; } public function setAPIKey($api_key) { $this->api_key = $api_key; return $this; } public function getAPIKey() { return $this->api_key; } public function setSecretKey($key) { $this->secret_key = $key; return $this; } public function getSecretKey() { return $this->secret_key; } public function setName($name) { $this->name = $name; return $this; } public function getName() { return $this->name; } public function getRoles() { $str_roles = []; foreach ($this->roles as $role) $str_roles[] = $role->getID(); return $str_roles; } public function getRoleObjects() { return $this->roles; } public function getDateCreate() { return $this->date_create; } public function getPassword() { // we don't need this for API return 'notneeded'; } public function getSalt() { return null; } public function getUsername() { // since it's an api, the api key IS the username return $this->api_key; } public function eraseCredentials() { return; } public function generateAPIKey() { return $this->generateKey('api'); } public function generateSecretKey() { return $this->generateKey('secret'); } protected function generateKey($prefix = '') { return md5(uniqid($prefix, true)); } }