Created
May 7, 2012 13:27
-
-
Save coreymcmahon/2627741 to your computer and use it in GitHub Desktop.
An Entity class for a User - http://www.symfonycentral.com/symfony-does-validation.html
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 | |
namespace MyCompany\BlogBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/* Include the required validators */ | |
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/* Note below: we can make assertions at the class / entity level */ | |
/** | |
* MyCompany\BlogBundle\Entity\User | |
* | |
* @ORM\Table() | |
* @ORM\Entity(repositoryClass="MyCompany\BlogBundle\Entity\UserRepository") | |
* | |
* @UniqueEntity("email") | |
* @UniqueEntity("username") | |
*/ | |
class User | |
{ | |
/** | |
* @var string $username | |
* | |
* @ORM\Column(name="username", type="string", length=255) | |
* | |
* @Assert\MinLength( | |
* limit=5, | |
* message="Username must have at least {{ limit }} characters." | |
* ) | |
* @Assert\MaxLength( | |
* limit=50, | |
* message="Username must have at most {{ limit }} characters." | |
* ) | |
*/ | |
private $username; | |
/** | |
* @var string $email | |
* | |
* @ORM\Column(name="email", type="string", length=255) | |
* | |
* @Assert\Email( | |
* message = "The value '{{ value }}' is not a valid email." | |
* ) | |
*/ | |
private $email; | |
/** | |
* @var string $password | |
* | |
* @ORM\Column(name="password", type="string", length=31) | |
* | |
* @Assert\MinLength( | |
* limit=5, | |
* message="Password must have at least {{ limit }} characters." | |
* ) | |
* @Assert\MaxLength( | |
* limit=50, | |
* message="Password must have at most {{ limit }} characters." | |
* ) | |
*/ | |
private $password; | |
/** | |
* @var integer $id | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/* | |
* Getters and setters omitted for brevity... | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment