File tree 3 files changed +11
-0
lines changed
src/Symfony/Component/Validator 3 files changed +11
-0
lines changed Original file line number Diff line number Diff line change 16
16
use Symfony \Component \Validator \Constraints \Callback ;
17
17
use Symfony \Component \Validator \Constraints \GroupSequence ;
18
18
use Symfony \Component \Validator \Constraints \GroupSequenceProvider ;
19
+ use Symfony \Component \Validator \Constraints \TargetAwareConstraintInterface ;
19
20
use Symfony \Component \Validator \Exception \MappingException ;
20
21
use Symfony \Component \Validator \Mapping \ClassMetadata ;
21
22
@@ -51,6 +52,10 @@ public function loadClassMetadata(ClassMetadata $metadata)
51
52
} elseif ($ constraint instanceof GroupSequenceProvider) {
52
53
$ metadata ->setGroupSequenceProvider (true );
53
54
} elseif ($ constraint instanceof Constraint) {
55
+ if ($ constraint instanceof TargetAwareConstraintInterface) {
56
+ $ constraint ->target = $ metadata ->getClassName ();
57
+ }
58
+
54
59
$ metadata ->addConstraint ($ constraint );
55
60
}
56
61
Original file line number Diff line number Diff line change 13
13
14
14
use Symfony \Component \Validator \Constraints \NotNull ;
15
15
16
+ /**
17
+ * @Symfony\Component\Validator\Tests\Fixtures\ConstraintD
18
+ */
16
19
class EntityParent
17
20
{
18
21
protected $ firstName ;
Original file line number Diff line number Diff line change 22
22
use Symfony \Component \Validator \Mapping \ClassMetadata ;
23
23
use Symfony \Component \Validator \Mapping \Loader \AnnotationLoader ;
24
24
use Symfony \Component \Validator \Tests \Fixtures \ConstraintA ;
25
+ use Symfony \Component \Validator \Tests \Fixtures \ConstraintD ;
25
26
26
27
class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
27
28
{
@@ -89,6 +90,7 @@ public function testLoadParentClassMetadata()
89
90
$ loader ->loadClassMetadata ($ parent_metadata );
90
91
91
92
$ expected_parent = new ClassMetadata ('Symfony\Component\Validator\Tests\Fixtures\EntityParent ' );
93
+ $ expected_parent ->addConstraint (new ConstraintD (array ('target ' => 'Symfony\Component\Validator\Tests\Fixtures\EntityParent ' )));
92
94
$ expected_parent ->addPropertyConstraint ('other ' , new NotNull ());
93
95
$ expected_parent ->getReflectionClass ();
94
96
@@ -113,6 +115,7 @@ public function testLoadClassMetadataAndMerge()
113
115
$ loader ->loadClassMetadata ($ metadata );
114
116
115
117
$ expected_parent = new ClassMetadata ('Symfony\Component\Validator\Tests\Fixtures\EntityParent ' );
118
+ $ expected_parent ->addConstraint (new ConstraintD (array ('target ' => 'Symfony\Component\Validator\Tests\Fixtures\EntityParent ' )));
116
119
$ expected_parent ->addPropertyConstraint ('other ' , new NotNull ());
117
120
$ expected_parent ->getReflectionClass ();
118
121
You can’t perform that action at this time.
0 commit comments