作者:skalli350
项目:project-maste
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('title', new NotBlank());
$metadata->addPropertyConstraint('coment', new NotBlank());
$metadata->addPropertyConstraint('author', new NotBlank());
$metadata->addPropertyConstraint('photo', new NotBlank());
}
作者:skoo
项目:symfony-sandbo
/**
* {@inheritDoc}
*/
public function loadClassMetadata(ClassMetadata $metadata)
{
$annotClass = 'Symfony\\Component\\Validator\\Constraints\\Validation';
$reflClass = $metadata->getReflectionClass();
$loaded = false;
if ($annot = $this->reader->getClassAnnotation($reflClass, $annotClass)) {
foreach ($annot->constraints as $constraint) {
$metadata->addConstraint($constraint);
}
$loaded = true;
}
foreach ($reflClass->getProperties() as $property) {
if ($annot = $this->reader->getPropertyAnnotation($property, $annotClass)) {
foreach ($annot->constraints as $constraint) {
$metadata->addPropertyConstraint($property->getName(), $constraint);
}
$loaded = true;
}
}
foreach ($reflClass->getMethods() as $method) {
if ($annot = $this->reader->getMethodAnnotation($method, $annotClass)) {
foreach ($annot->constraints as $constraint) {
// TODO: clean this up
$name = lcfirst(substr($method->getName(), 0, 3) == 'get' ? substr($method->getName(), 3) : substr($method->getName(), 2));
$metadata->addGetterConstraint($name, $constraint);
}
$loaded = true;
}
}
return $loaded;
}
作者:RogerWeb
项目:symfon
/**
* This is a functinoal test as there is a large integration necessary to get the validator working.
*/
public function testValidateUniqueness()
{
$entityManagerName = "foo";
$em = $this->createTestEntityManager();
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema(array($em->getClassMetadata('Symfony\\Tests\\Bridge\\Doctrine\\Form\\Fixtures\\SingleIdentEntity')));
$entity1 = new SingleIdentEntity(1, 'Foo');
$registry = $this->createRegistryMock($entityManagerName, $em);
$uniqueValidator = new UniqueEntityValidator($registry);
$metadata = new ClassMetadata('Symfony\\Tests\\Bridge\\Doctrine\\Form\\Fixtures\\SingleIdentEntity');
$metadata->addConstraint(new UniqueEntity(array('fields' => array('name'), 'em' => $entityManagerName)));
$metadataFactory = $this->createMetadataFactoryMock($metadata);
$validatorFactory = $this->createValidatorFactory($uniqueValidator);
$validator = new Validator($metadataFactory, $validatorFactory);
$violationsList = $validator->validate($entity1);
$this->assertEquals(0, $violationsList->count(), "No violations found on entity before it is saved to the database.");
$em->persist($entity1);
$em->flush();
$violationsList = $validator->validate($entity1);
$this->assertEquals(0, $violationsList->count(), "No violations found on entity after it was saved to the database.");
$entity2 = new SingleIdentEntity(2, 'Foo');
$violationsList = $validator->validate($entity2);
$this->assertEquals(1, $violationsList->count(), "No violations found on entity after it was saved to the database.");
$violation = $violationsList[0];
$this->assertEquals('This value is already used.', $violation->getMessage());
$this->assertEquals('name', $violation->getPropertyPath());
$this->assertEquals('Foo', $violation->getInvalidValue());
}
作者:bsa-gi
项目:silex-mv
/**
* Load validator metadata
*
* @param Symfony\Component\Validator\Mapping\ClassMetadata $metadata
*/
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('created', new Assert\NotBlank());
$metadata->addPropertyConstraint('title', new Assert\NotBlank());
$metadata->addPropertyConstraint('title', new Assert\Length(array('min' => 5)));
$metadata->addPropertyConstraint('body', new Assert\NotBlank());
}
作者:pdt25
项目:vbscrape
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('teamA', new Assert\Valid());
$metadata->addPropertyConstraint('teamB', new Assert\Valid());
$metadata->addPropertyConstraint('setScores', new Assert\Valid());
$metadata->addPropertyConstraint('gameTimeLengthInSeconds', new Assert\Range(['min' => 0, 'max' => 65535]));
}
作者:hrobbe
项目:sf2_blo
/**
* @param ClassMetadata $metadata
*/
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('title', new NotBlank(array('message' => 'You must enter a title')));
$metadata->addPropertyConstraint('blog', new NotBlank(array('message' => 'You must enter little bit blog?')));
$metadata->addPropertyConstraint('author', new NotBlank(array('message' => 'You must enter your name!')));
$metadata->addPropertyConstraint('tags', new NotBlank(array('message' => 'You must enter minimal one tag')));
}
作者:aesten
项目:webpag
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new NotBlank());
$metadata->addPropertyConstraint('email', new Email());
$metadata->addPropertyConstraint('short_name', new NotBlank());
$metadata->addPropertyConstraint('address', new NotBlank());
}
作者:notbrai
项目:symfon
/**
* Test MetaData merge with parent annotation.
*/
public function testLoadClassMetadataAndMerge()
{
$loader = new AnnotationLoader();
// Load Parent MetaData
$parent_metadata = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\EntityParent');
$loader->loadClassMetadata($parent_metadata);
$metadata = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\Entity');
// Merge parent metaData.
$metadata->mergeConstraints($parent_metadata);
$loader->loadClassMetadata($metadata);
$expected_parent = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\EntityParent');
$expected_parent->addPropertyConstraint('other', new NotNull());
$expected_parent->getReflectionClass();
$expected = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\Entity');
$expected->mergeConstraints($expected_parent);
$expected->setGroupSequence(array('Foo', 'Entity'));
$expected->addConstraint(new NotNull());
$expected->addConstraint(new ConstraintA());
$expected->addConstraint(new Min(3));
$expected->addConstraint(new Choice(array('A', 'B')));
$expected->addConstraint(new All(array(new NotNull(), new Min(3))));
$expected->addConstraint(new All(array('constraints' => array(new NotNull(), new Min(3)))));
$expected->addConstraint(new Collection(array('fields' => array('foo' => array(new NotNull(), new Min(3)), 'bar' => new Min(5)))));
$expected->addPropertyConstraint('firstName', new Choice(array('message' => 'Must be one of %choices%', 'choices' => array('A', 'B'))));
$expected->addGetterConstraint('lastName', new NotNull());
// load reflection class so that the comparison passes
$expected->getReflectionClass();
$this->assertEquals($expected, $metadata);
}
作者:neemz
项目:patchwor
/**
* Valorizes model validation metadata
*
* @return void
*/
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addGetterConstraint('title', new Assert\NotBlank());
$metadata->addGetterConstraint('content', new Assert\NotBlank());
$metadata->addGetterConstraint('image', new Assert\NotBlank());
$metadata->addGetterConstraint('image', new Assert\Image(['maxWidth' => 400]));
}
作者:romanvelie
项目:form
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new NotBlank());
$metadata->addPropertyConstraint('name', new Length(['min' => 5, 'max' => 10, 'minMessage' => 'Your name must be at least {{ limit }} characters long', 'maxMessage' => 'Your name cannot be longer than {{ limit }} characters']));
$metadata->addPropertyConstraint('password', new NotBlank());
$metadata->addPropertyConstraint('password', new Length(['min' => 5, 'max' => 10, 'minMessage' => 'Your password must be at least {{ limit }} characters long', 'maxMessage' => 'Your password cannot be longer than {{ limit }} characters']));
}
作者:nickdunn
项目:nickblo
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new NotBlank());
$metadata->addPropertyConstraint('email', new NotBlank());
$metadata->addPropertyConstraint('email', new Email(array('message' => 'Please provide a valid email address.')));
$metadata->addPropertyConstraint('subject', new NotBlank());
}
作者:robziener
项目:symfony2bundle
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new Constraints\NotBlank());
$metadata->addPropertyConstraint('name', new Constraints\MinLength(2));
$metadata->addPropertyConstraint('username', new Constraints\NotBlank());
$metadata->addPropertyConstraint('username', new Constraints\MinLength(2));
}
作者:zyxis
项目:cantig
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('login', new NotBlank());
$metadata->addPropertyConstraint('login', new Length(array('min' => 6, 'max' => 40)));
$metadata->addPropertyConstraint('email', new Length(array('min' => 2, 'max' => 100)));
$metadata->addPropertyConstraint('email', new Email());
}
作者:xoo
项目:blogTutoria
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('title', new NotBlank(array('message' => 'You must enter a title')));
$metadata->addPropertyConstraint('author', new NotBlank(array('message' => 'You must enter a author')));
$metadata->addPropertyConstraint('blog', new NotBlank(array('message' => 'You must enter the text')));
$metadata->addPropertyConstraint('blog', new Length(array('min' => 50)));
}
作者:miknat
项目:grac
public function loadClassMetadata(ClassMetadata $metadata)
{
/** @var \ReflectionClass $refClass */
$refClass = $metadata->getReflectionClass();
$baseClass = $this->classNameProvider->getBaseClass($refClass->name);
if (!$baseClass) {
return false;
}
if (!array_key_exists($baseClass, $this->config->models)) {
return false;
}
foreach ($this->config->models[$baseClass]->properties as $propName => $property) {
if ($property->validation) {
if (!is_array($property->validation)) {
throw new \LogicException("Configuration error: {$baseClass}:{$propName}:validation must be array");
}
foreach ($property->validation as $index => $rule) {
if (!is_array($rule) or count($rule) != 1) {
throw new \LogicException("Configuration error: {$baseClass}:{$propName}:validation: rule #{$index} must be array of 1 element which contains array");
}
$constraintClass = array_keys($rule)[0];
$constraintOptions = $rule[$constraintClass];
$fullClass = $this->getFullConstraintClass($constraintClass);
$metadata->addGetterConstraint($propName, new $fullClass($constraintOptions));
}
}
}
return true;
}
作者:argentinalui
项目:jsdatatables-sile
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('column', new Assert\NotBlank());
$metadata->addPropertyConstraint('column', new Assert\Type(['type' => 'integer']));
$metadata->addPropertyConstraint('dir', new Assert\NotBlank());
$metadata->addPropertyConstraint('dir', new Assert\Choice(['choices' => ['asc', 'desc']]));
}
作者:inklab
项目:kommerce-cor
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
$metadata->addPropertyConstraint('name', new Assert\Length(['max' => 32]));
$metadata->addPropertyConstraint('description', new Assert\NotBlank());
$metadata->addPropertyConstraint('description', new Assert\Length(['max' => 255]));
}
作者:inklab
项目:kommerce-cor
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
$metadata->addPropertyConstraint('name', new Assert\Length(['max' => 255]));
$metadata->addPropertyConstraint('sortOrder', new Assert\NotNull());
$metadata->addPropertyConstraint('sortOrder', new Assert\Range(['min' => 0, 'max' => 65535]));
}
作者:jimty051
项目:myprojec
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new NotBlank());
$metadata->addPropertyConstraint('email', new Email());
$metadata->addPropertyConstraint('subject', new NotBlank());
//$metadata->addPropertyConstraint('subject', new MaxLength(50));
// $metadata->addPropertyConstraint('body', new MinLength(50));
}
作者:inklab
项目:kommerce-cor
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$integerColumns = ['origSubtotal', 'subtotal', 'taxSubtotal', 'discount', 'shipping', 'shippingDiscount', 'tax', 'total', 'savings'];
foreach ($integerColumns as $columnName) {
$metadata->addPropertyConstraint($columnName, new Assert\NotNull());
$metadata->addPropertyConstraint($columnName, new Assert\Range(['min' => 0, 'max' => 4294967295]));
}
}