Skip to content

Commit eed3c9a

Browse files
author
Bernhard Schussek
committed
[Validator] Added abstract method Constraint::targets() to define whether constraints can be put onto properties, classes or both
1 parent 6ad22fd commit eed3c9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+409
-99
lines changed

src/Symfony/Component/Validator/Constraint.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,24 @@
2828
*/
2929
abstract class Constraint
3030
{
31+
/**
32+
* The name of the group given to all constraints with no explicit group
33+
* @var string
34+
*/
3135
const DEFAULT_GROUP = 'Default';
3236

37+
/**
38+
* Marks a constraint that can be put onto classes
39+
* @var string
40+
*/
41+
const CLASS_CONSTRAINT = 'class';
42+
43+
/**
44+
* Marks a constraint that can be put onto properties
45+
* @var string
46+
*/
47+
const PROPERTY_CONSTRAINT = 'property';
48+
3349
/**
3450
* @var array
3551
*/
@@ -173,4 +189,15 @@ public function validatedBy()
173189
{
174190
return get_class($this) . 'Validator';
175191
}
192+
193+
/**
194+
* Returns whether the constraint can be put onto classes, properties or
195+
* both
196+
*
197+
* This method should return one or more of the constants
198+
* Constraint::CLASS_CONSTRAINT and Constraint::PROPERTY_CONSTRAINT.
199+
*
200+
* @return string|array One or more constant values
201+
*/
202+
abstract public function targets();
176203
}

src/Symfony/Component/Validator/Constraints/All.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ public function requiredOptions()
2424
{
2525
return array('constraints');
2626
}
27+
28+
/**
29+
* {@inheritDoc}
30+
*/
31+
public function targets()
32+
{
33+
return self::PROPERTY_CONSTRAINT;
34+
}
2735
}

src/Symfony/Component/Validator/Constraints/AssertFalse.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@
1414
class AssertFalse extends \Symfony\Component\Validator\Constraint
1515
{
1616
public $message = 'This value should be false';
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
public function targets()
22+
{
23+
return self::PROPERTY_CONSTRAINT;
24+
}
1725
}

src/Symfony/Component/Validator/Constraints/AssertTrue.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@
1414
class AssertTrue extends \Symfony\Component\Validator\Constraint
1515
{
1616
public $message = 'This value should be true';
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
public function targets()
22+
{
23+
return self::PROPERTY_CONSTRAINT;
24+
}
1725
}

src/Symfony/Component/Validator/Constraints/AssertType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ public function requiredOptions()
3131
{
3232
return array('type');
3333
}
34+
35+
/**
36+
* {@inheritDoc}
37+
*/
38+
public function targets()
39+
{
40+
return self::PROPERTY_CONSTRAINT;
41+
}
3442
}

src/Symfony/Component/Validator/Constraints/Blank.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@
1414
class Blank extends \Symfony\Component\Validator\Constraint
1515
{
1616
public $message = 'This value should be blank';
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
public function targets()
22+
{
23+
return self::PROPERTY_CONSTRAINT;
24+
}
1725
}

src/Symfony/Component/Validator/Constraints/Choice.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ public function defaultOption()
2929
{
3030
return 'choices';
3131
}
32+
33+
/**
34+
* {@inheritDoc}
35+
*/
36+
public function targets()
37+
{
38+
return self::PROPERTY_CONSTRAINT;
39+
}
3240
}

src/Symfony/Component/Validator/Constraints/Collection.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ public function requiredOptions()
2323
{
2424
return array('fields');
2525
}
26+
27+
/**
28+
* {@inheritDoc}
29+
*/
30+
public function targets()
31+
{
32+
return self::PROPERTY_CONSTRAINT;
33+
}
2634
}

src/Symfony/Component/Validator/Constraints/Country.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@
1414
class Country extends \Symfony\Component\Validator\Constraint
1515
{
1616
public $message = 'This value is not a valid country';
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
public function targets()
22+
{
23+
return self::PROPERTY_CONSTRAINT;
24+
}
1725
}

src/Symfony/Component/Validator/Constraints/Date.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@
1414
class Date extends \Symfony\Component\Validator\Constraint
1515
{
1616
public $message = 'This value is not a valid date';
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
public function targets()
22+
{
23+
return self::PROPERTY_CONSTRAINT;
24+
}
1725
}

0 commit comments

Comments
 (0)