Skip to content

Instantly share code, notes, and snippets.

@o
Created May 3, 2012 18:51
Show Gist options
  • Save o/2588085 to your computer and use it in GitHub Desktop.
Save o/2588085 to your computer and use it in GitHub Desktop.
A sample user entity with Doctrine 2
<?php
namespace Import\Bundle\TestBundle\Entity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass="Import\Bundle\TestBundle\Entity\UserRepository")
* @ORM\Table(name="user")
* @UniqueEntity("email")
*/
class User implements AdvancedUserInterface {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;
/**
* @ORM\Column(type="string", name="email", length=64, unique=true)
* @Assert\NotBlank()
* @Assert\Email()
*/
protected $email;
/**
* @ORM\Column(type="string", name="name", length=16)
* @Assert\NotBlank()
* @Assert\MinLength(3)
*/
protected $name;
/**
* @ORM\Column(type="string", name="salt", length=32)
* @Assert\NotBlank()
*/
protected $salt;
/**
* @ORM\Column(type="string", name="password", length=32)
* @Assert\NotBlank()
*/
protected $password;
/**
* @ORM\Column(type="datetime", name="created_at")
* @Assert\NotBlank()
* @Assert\DateTime()
*/
protected $createdAt;
/**
* @ORM\Column(type="string", name="confirmation_token", length=32, nullable=true)
*/
protected $confirmationToken;
/**
* @ORM\Column(type="boolean", name="is_verified")
* @Assert\NotNull()
*/
protected $isVerified;
/**
* @ORM\Column(type="boolean", name="is_admin")
* @Assert\NotNull()
*/
protected $isAdmin;
/**
* @ORM\Column(type="boolean", name="is_active")
* @Assert\NotNull()
*/
protected $isActive;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set email
*
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set salt
*
* @param string $salt
*/
public function setSalt($salt)
{
$this->salt = $salt;
}
/**
* Get salt
*
* @return string
*/
public function getSalt()
{
return $this->salt;
}
/**
* Set password
*
* @param string $password
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set createdAt
*
* @param datetime $createdAt
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
}
/**
* Get createdAt
*
* @return datetime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set confirmationToken
*
* @param string $confirmationToken
*/
public function setConfirmationToken($confirmationToken)
{
$this->confirmationToken = $confirmationToken;
}
/**
* Get confirmationToken
*
* @return string
*/
public function getConfirmationToken()
{
return $this->confirmationToken;
}
/**
* Set isVerified
*
* @param boolean $isVerified
*/
public function setIsVerified($isVerified)
{
$this->isVerified = $isVerified;
}
/**
* Get isVerified
*
* @return boolean
*/
public function getIsVerified()
{
return $this->isVerified;
}
/**
* Set isAdmin
*
* @param boolean $isAdmin
*/
public function setIsAdmin($isAdmin)
{
$this->isAdmin = $isAdmin;
}
/**
* Get isAdmin
*
* @return boolean
*/
public function getIsAdmin()
{
return $this->isAdmin;
}
/**
* Set isActive
*
* @param boolean $isActive
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
//... AdvancedUserInterface related methods
public function equals(UserInterface $user) {}
public function eraseCredentials() {}
public function getRoles() {}
public function getUsername() {}
public function isAccountNonExpired() {}
public function isAccountNonLocked() {}
public function isCredentialsNonExpired() {}
public function isEnabled() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment