Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Entity;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Security\Core\User\UserInterface;
- /**
- * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
- * @ORM\Table(name="user")
- */
- class User implements UserInterface, \JsonSerializable
- {
- /**
- * @ORM\Id()
- * @ORM\GeneratedValue()
- * @ORM\Column(type="integer")
- * @var int|null $id
- */
- private $id;
- /**
- * @ORM\Column(type="string", length=180, unique=true)
- * @var string $email
- */
- private $email;
- /**
- * @ORM\Column(type="string", length=180, unique=true)
- * @var string $username
- */
- private $username;
- /**
- * @var string The hashed password
- * @ORM\Column(type="string")
- */
- private $password;
- /**
- * @ORM\ManyToMany(targetEntity="App\Entity\Role", inversedBy="users")
- * @ORM\JoinTable(name="user_role", joinColumns={
- * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
- * }, inverseJoinColumns={
- * @ORM\JoinColumn(name="role_id", referencedColumnName="id")
- * })
- * @var Role[]|null $roles
- */
- private $roles;
- public function __construct()
- {
- $this->roles = new ArrayCollection();
- }
- /**
- * @return int|null
- */
- public function getId(): ?int
- {
- return $this->id;
- }
- /**
- * @param int|null $id
- */
- public function setId(?int $id): void
- {
- $this->id = $id;
- }
- /**
- * @return string
- */
- public function getEmail(): string
- {
- return $this->email;
- }
- /**
- * @param string $email
- */
- public function setEmail(string $email): void
- {
- $this->email = $email;
- }
- /**
- * A visual identifier that represents this user.
- *
- * @see UserInterface
- */
- public function getUsername(): string
- {
- return (string) $this->username;
- }
- /**
- * @see UserInterface
- */
- public function getRoles()
- {
- return $this->roles;
- }
- /**
- * @see UserInterface
- */
- public function getPassword(): string
- {
- return (string) $this->password;
- }
- /**
- * @param string $password
- * @return User
- */
- public function setPassword(string $password): void
- {
- $this->password = $password;
- }
- /**
- * @see UserInterface
- */
- public function getSalt()
- {
- // not needed when using the "bcrypt" algorithm in security.yaml
- }
- /**
- * @see UserInterface
- */
- public function eraseCredentials()
- {
- // If you store any temporary, sensitive data on the user, clear it here
- // $this->plainPassword = null;
- }
- /**
- * @return array|mixed
- */
- public function jsonSerialize()
- {
- return [
- 'id' => $this->getId(),
- 'email' => $this->getEmail(),
- 'username' => $this->getUsername(),
- 'roles' => $this->getRoles()
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement