Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
- }
- }
Add Comment
Please, Sign In to add comment