merged branch bschussek/group-sequence (PR #5045)
Commits
-------
2a3235a
[Validator] Fixed group sequence support in the XML and YAML drivers
Discussion
----------
[Validator] Fixed group sequence support in the XML and YAML drivers
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -
This commit is contained in:
commit
24e3e2a1cd
@ -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