Skip to content

Commit 2a3235a

Browse files
committed
[Validator] Fixed group sequence support in the XML and YAML drivers
1 parent a5451e4 commit 2a3235a

File tree

7 files changed

+34
-0
lines changed

7 files changed

+34
-0
lines changed

src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public function loadClassMetadata(ClassMetadata $metadata)
4343
if (isset($this->classes[$metadata->getClassName()])) {
4444
$xml = $this->classes[$metadata->getClassName()];
4545

46+
foreach ($xml->{'group-sequence'} as $groupSequence) {
47+
if (count($groupSequence->value) > 0) {
48+
$metadata->setGroupSequence($this->parseValues($groupSequence[0]->value));
49+
}
50+
}
51+
4652
foreach ($this->parseConstraints($xml->constraint) as $constraint) {
4753
$metadata->addConstraint($constraint);
4854
}

src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function loadClassMetadata(ClassMetadata $metadata)
5454
if (isset($this->classes[$metadata->getClassName()])) {
5555
$yaml = $this->classes[$metadata->getClassName()];
5656

57+
if (isset($yaml['group_sequence'])) {
58+
$metadata->setGroupSequence($yaml['group_sequence']);
59+
}
60+
5761
if (isset($yaml['constraints'])) {
5862
foreach ($this->parseNodes($yaml['constraints']) as $constraint) {
5963
$metadata->addConstraint($constraint);

src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,25 @@
5252
]]></xsd:documentation>
5353
</xsd:annotation>
5454
<xsd:choice minOccurs="0" maxOccurs="unbounded">
55+
<xsd:element name="group-sequence" type="group-sequence" minOccurs="0" maxOccurs="1" />
5556
<xsd:element name="constraint" type="constraint" minOccurs="0" maxOccurs="unbounded" />
5657
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
5758
<xsd:element name="getter" type="getter" minOccurs="0" maxOccurs="unbounded" />
5859
</xsd:choice>
5960
<xsd:attribute name="name" type="xsd:string" use="required" />
6061
</xsd:complexType>
62+
63+
<xsd:complexType name="group-sequence">
64+
<xsd:annotation>
65+
<xsd:documentation><![CDATA[
66+
Contains the group sequence of a class. Each group should be written
67+
into a "value" tag.
68+
]]></xsd:documentation>
69+
</xsd:annotation>
70+
<xsd:sequence>
71+
<xsd:element name="value" type="value" minOccurs="1" maxOccurs="unbounded" />
72+
</xsd:sequence>
73+
</xsd:complexType>
6174

6275
<xsd:complexType name="property">
6376
<xsd:annotation>

tests/Symfony/Tests/Component/Validator/Mapping/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function testLoadClassMetadata()
5151
$loader->loadClassMetadata($metadata);
5252

5353
$expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\Entity');
54+
$expected->setGroupSequence(array('Foo', 'Entity'));
5455
$expected->addConstraint(new ConstraintA());
5556
$expected->addConstraint(new ConstraintB());
5657
$expected->addPropertyConstraint('firstName', new NotNull());

tests/Symfony/Tests/Component/Validator/Mapping/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function testLoadClassMetadata()
6969
$loader->loadClassMetadata($metadata);
7070

7171
$expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\Entity');
72+
$expected->setGroupSequence(array('Foo', 'Entity'));
7273
$expected->addConstraint(new ConstraintA());
7374
$expected->addConstraint(new ConstraintB());
7475
$expected->addPropertyConstraint('firstName', new NotNull());

tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
<class name="Symfony\Tests\Component\Validator\Fixtures\Entity">
1010

11+
<group-sequence>
12+
<value>Foo</value>
13+
<value>Entity</value>
14+
</group-sequence>
15+
1116
<!-- CLASS CONSTRAINTS -->
1217

1318
<!-- Custom constraint -->

tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ namespaces:
22
custom: Symfony\Tests\Component\Validator\Fixtures\
33

44
Symfony\Tests\Component\Validator\Fixtures\Entity:
5+
group_sequence:
6+
- Foo
7+
- Entity
8+
59
constraints:
610
# Custom constraint
711
- Symfony\Tests\Component\Validator\Fixtures\ConstraintA: ~

0 commit comments

Comments
 (0)