[Validator] Fixed group sequence support in the XML and YAML drivers
This commit is contained in:
parent
a5451e48b7
commit
2a3235ac22
@ -43,6 +43,12 @@ class XmlFileLoader extends FileLoader
|
||||
if (isset($this->classes[$metadata->getClassName()])) {
|
||||
$xml = $this->classes[$metadata->getClassName()];
|
||||
|
||||
foreach ($xml->{'group-sequence'} as $groupSequence) {
|
||||
if (count($groupSequence->value) > 0) {
|
||||
$metadata->setGroupSequence($this->parseValues($groupSequence[0]->value));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->parseConstraints($xml->constraint) as $constraint) {
|
||||
$metadata->addConstraint($constraint);
|
||||
}
|
||||
|
@ -54,6 +54,10 @@ class YamlFileLoader extends FileLoader
|
||||
if (isset($this->classes[$metadata->getClassName()])) {
|
||||
$yaml = $this->classes[$metadata->getClassName()];
|
||||
|
||||
if (isset($yaml['group_sequence'])) {
|
||||
$metadata->setGroupSequence($yaml['group_sequence']);
|
||||
}
|
||||
|
||||
if (isset($yaml['constraints'])) {
|
||||
foreach ($this->parseNodes($yaml['constraints']) as $constraint) {
|
||||
$metadata->addConstraint($constraint);
|
||||
|
@ -52,12 +52,25 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="group-sequence" type="group-sequence" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="constraint" type="constraint" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="getter" type="getter" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="group-sequence">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Contains the group sequence of a class. Each group should be written
|
||||
into a "value" tag.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="value" minOccurs="1" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="property">
|
||||
<xsd:annotation>
|
||||
|
@ -51,6 +51,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\Entity');
|
||||
$expected->setGroupSequence(array('Foo', 'Entity'));
|
||||
$expected->addConstraint(new ConstraintA());
|
||||
$expected->addConstraint(new ConstraintB());
|
||||
$expected->addPropertyConstraint('firstName', new NotNull());
|
||||
|
@ -69,6 +69,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\Entity');
|
||||
$expected->setGroupSequence(array('Foo', 'Entity'));
|
||||
$expected->addConstraint(new ConstraintA());
|
||||
$expected->addConstraint(new ConstraintB());
|
||||
$expected->addPropertyConstraint('firstName', new NotNull());
|
||||
|
@ -8,6 +8,11 @@
|
||||
|
||||
<class name="Symfony\Tests\Component\Validator\Fixtures\Entity">
|
||||
|
||||
<group-sequence>
|
||||
<value>Foo</value>
|
||||
<value>Entity</value>
|
||||
</group-sequence>
|
||||
|
||||
<!-- CLASS CONSTRAINTS -->
|
||||
|
||||
<!-- Custom constraint -->
|
||||
|
@ -2,6 +2,10 @@ namespaces:
|
||||
custom: Symfony\Tests\Component\Validator\Fixtures\
|
||||
|
||||
Symfony\Tests\Component\Validator\Fixtures\Entity:
|
||||
group_sequence:
|
||||
- Foo
|
||||
- Entity
|
||||
|
||||
constraints:
|
||||
# Custom constraint
|
||||
- Symfony\Tests\Component\Validator\Fixtures\ConstraintA: ~
|
||||
|
Reference in New Issue
Block a user