Created
May 13, 2011 22:01
-
-
Save yethee/971396 to your computer and use it in GitHub Desktop.
Path mapping of DelegatingValidator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EntitiesList | |
{ | |
public $obj; | |
public $items = array(); | |
/** | |
* @assert:NotBlank() | |
*/ | |
public $scalar; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Entity | |
{ | |
/** | |
* @assert:NotBlank() | |
*/ | |
public $foo; | |
/** | |
* @assert:NotBlank() | |
*/ | |
public $bar; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EntityIterator implements \IteratorAggregate | |
{ | |
public $obj; | |
public $elements = array(); | |
/** | |
* @assert:NotBlank() | |
*/ | |
public $scalar; | |
public function getIterator() | |
{ | |
return new \ArrayIterator($this->elements); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EntityType extends \Symfony\Component\Form\AbstractType | |
{ | |
/** | |
* @param FormBuilder $builder | |
* @param array $options | |
*/ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder | |
->add('foo', 'text') | |
->add('bar', 'text'); | |
} | |
public function getDefaultOptions(array $options) | |
{ | |
return array( | |
'data_class' => 'Entity' | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$entities = new EntitiesList(); | |
$entities->items[] = new Entity(); | |
$entities->items[] = new Entity(); | |
$factory = $container->get('form.factory'); | |
$form = $factory->createBuilder('form', $entities) | |
->add('items', 'collection', array('type' => new EntityType())) | |
->add('obj', new EntityType()) | |
->add('scalar', 'text') | |
->getForm(); | |
$form->bind(); | |
/* | |
Expected pathes from violations: | |
children[items][0].data.foo | |
children[items][0].data.bar | |
children[items][1].data.foo | |
children[items][1].data.bar | |
children[obj].data.foo | |
children[obj].data.bar | |
data.scalar | |
Expected pathes if used the Valid validator for EntitiesList::$obj and EntitiesList::$items : | |
data.items[0].foo | |
data.items[0].bar | |
data.items[1].foo | |
data.items[1].bar | |
data.obj.foo | |
data.obj.bar | |
data.scalar | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$entity = new EntityIterator(); | |
$entity->elements[] = new Entity(); | |
$entity->elements[] = new Entity(); | |
$factory = $container->get('form.factory'); | |
$form = $factory->createBuilder('form', $entity) | |
->add('elements', 'collection', array('type' => new EntityType())) | |
->add('obj', new EntityType()) | |
->add('scalar', 'text') | |
->getForm(); | |
$form->bind(null); | |
/* | |
Expected pathes: | |
data[0].foo | |
data[0].bar | |
data[1].foo | |
data[1].bar | |
children[obj].data.foo | |
children[obj].data.bar | |
data.scalar | |
Expected pathes if used the Valid validator for EntityIterator::$obj : | |
data[0].foo | |
data[0].bar | |
data[1].foo | |
data[1].bar | |
data.obj.foo | |
data.obj.bar | |
data.scalar | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment