Last active
February 2, 2019 22:26
-
-
Save rabbl/fa04d4c8385159310e47f46e0c1ed06a to your computer and use it in GitHub Desktop.
User.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/Entity/User.php | |
declare(strict_types=1); | |
namespace App\Entity; | |
use ApiPlatform\Core\Annotation\ApiResource; | |
use Doctrine\ORM\Mapping as ORM; | |
use Ramsey\Uuid\Uuid; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
/** | |
* @ApiResource | |
* @ORM\Entity | |
* @ORM\Table(name="users") | |
* @ApiResource | |
*/ | |
final class User implements UserInterface | |
{ | |
/** | |
* @var Uuid | |
* | |
* @ORM\Id | |
* @ORM\Column(name="id", type="uuid", unique=true, nullable=false) | |
*/ | |
private $id; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="username", type="string", length=255, unique=true, nullable=false) | |
*/ | |
private $username; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="password", type="string", length=255, nullable=false) | |
*/ | |
private $password; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="enabled", type="boolean", nullable=false) | |
*/ | |
private $enabled; | |
/** | |
* @var array | |
* | |
* @ORM\Column(name="roles", type="json_array", nullable=false) | |
*/ | |
private $roles; | |
/** | |
* User constructor. | |
* @param string $username | |
* @param string $password | |
* @param array $roles | |
* @param bool $enabled | |
* @throws \Exception | |
*/ | |
public function __construct(string $username, string $password, array $roles = [], bool $enabled = true) | |
{ | |
$this->id = Uuid::uuid4(); | |
$this->username = $username; | |
$this->password = $password; | |
$this->enabled = $enabled; | |
$this->roles = $roles; | |
} | |
public function getId(): Uuid | |
{ | |
return $this->id; | |
} | |
public function getUsername(): string | |
{ | |
return $this->username; | |
} | |
public function setUsername(string $username): void | |
{ | |
$this->username = $username; | |
} | |
public function getPassword(): string | |
{ | |
return $this->password; | |
} | |
public function setPassword(string $password): void | |
{ | |
$this->password = $password; | |
} | |
public function isEnabled(): bool | |
{ | |
return $this->enabled; | |
} | |
public function setEnabled(bool $enabled): void | |
{ | |
$this->enabled = $enabled; | |
} | |
public function getRoles(): array | |
{ | |
return $this->roles; | |
} | |
public function setRoles(array $roles): void | |
{ | |
$this->roles = $roles; | |
} | |
public function getSalt(): string | |
{ | |
return ''; | |
} | |
public function eraseCredentials() | |
{ | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment