Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Validator] Added abstract method Constraint::targets() to define whe…
…ther constraints can be put onto properties, classes or both
  • Loading branch information
Bernhard Schussek committed Jan 19, 2011
1 parent 6ad22fd commit eed3c9a
Show file tree
Hide file tree
Showing 44 changed files with 409 additions and 99 deletions.
27 changes: 27 additions & 0 deletions src/Symfony/Component/Validator/Constraint.php
Expand Up @@ -28,8 +28,24 @@
*/
abstract class Constraint
{
/**
* The name of the group given to all constraints with no explicit group
* @var string
*/
const DEFAULT_GROUP = 'Default';

/**
* Marks a constraint that can be put onto classes
* @var string
*/
const CLASS_CONSTRAINT = 'class';

/**
* Marks a constraint that can be put onto properties
* @var string
*/
const PROPERTY_CONSTRAINT = 'property';

/**
* @var array
*/
Expand Down Expand Up @@ -173,4 +189,15 @@ public function validatedBy()
{
return get_class($this) . 'Validator';
}

/**
* Returns whether the constraint can be put onto classes, properties or
* both
*
* This method should return one or more of the constants
* Constraint::CLASS_CONSTRAINT and Constraint::PROPERTY_CONSTRAINT.
*
* @return string|array One or more constant values
*/
abstract public function targets();
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/All.php
Expand Up @@ -24,4 +24,12 @@ public function requiredOptions()
{
return array('constraints');
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/AssertFalse.php
Expand Up @@ -14,4 +14,12 @@
class AssertFalse extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value should be false';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/AssertTrue.php
Expand Up @@ -14,4 +14,12 @@
class AssertTrue extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value should be true';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/AssertType.php
Expand Up @@ -31,4 +31,12 @@ public function requiredOptions()
{
return array('type');
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Blank.php
Expand Up @@ -14,4 +14,12 @@
class Blank extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value should be blank';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Choice.php
Expand Up @@ -29,4 +29,12 @@ public function defaultOption()
{
return 'choices';
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Collection.php
Expand Up @@ -23,4 +23,12 @@ public function requiredOptions()
{
return array('fields');
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Country.php
Expand Up @@ -14,4 +14,12 @@
class Country extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value is not a valid country';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Date.php
Expand Up @@ -14,4 +14,12 @@
class Date extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value is not a valid date';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/DateTime.php
Expand Up @@ -14,4 +14,12 @@
class DateTime extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value is not a valid datetime';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Email.php
Expand Up @@ -15,4 +15,12 @@ class Email extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value is not a valid email address';
public $checkMX = false;

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/File.php
Expand Up @@ -19,4 +19,12 @@ class File extends \Symfony\Component\Validator\Constraint
public $notReadableMessage = 'The file is not readable';
public $maxSizeMessage = 'The file is too large ({{ size }}). Allowed maximum size is {{ limit }}';
public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Ip.php
Expand Up @@ -45,4 +45,12 @@ public function __construct($options = null)
throw new ConstraintDefinitionException(sprintf('The option "version" must be one of "%s"', implode('", "', self::$versions)));
}
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Language.php
Expand Up @@ -14,4 +14,12 @@
class Language extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value is not a valid language';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Locale.php
Expand Up @@ -14,4 +14,12 @@
class Locale extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value is not a valid locale';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Max.php
Expand Up @@ -31,4 +31,12 @@ public function requiredOptions()
{
return array('limit');
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/MaxLength.php
Expand Up @@ -32,4 +32,12 @@ public function requiredOptions()
{
return array('limit');
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Min.php
Expand Up @@ -31,4 +31,12 @@ public function requiredOptions()
{
return array('limit');
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/MinLength.php
Expand Up @@ -32,4 +32,12 @@ public function requiredOptions()
{
return array('limit');
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/NotBlank.php
Expand Up @@ -14,4 +14,12 @@
class NotBlank extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value should not be blank';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/NotNull.php
Expand Up @@ -14,4 +14,12 @@
class NotNull extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value should not be null';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Null.php
Expand Up @@ -14,4 +14,12 @@
class Null extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value should be null';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Regex.php
Expand Up @@ -32,4 +32,12 @@ public function requiredOptions()
{
return array('pattern');
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Time.php
Expand Up @@ -14,4 +14,12 @@
class Time extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value is not a valid time';

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Url.php
Expand Up @@ -15,4 +15,12 @@ class Url extends \Symfony\Component\Validator\Constraint
{
public $message = 'This value is not a valid URL';
public $protocols = array('http', 'https');

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Valid.php
Expand Up @@ -28,4 +28,12 @@ public function __construct($options = null)
throw new ConstraintDefinitionException('The constraint Valid does not accept any options');
}
}

/**
* {@inheritDoc}
*/
public function targets()
{
return self::PROPERTY_CONSTRAINT;
}
}

0 comments on commit eed3c9a

Please sign in to comment.