I'm trying to validate data in an imported csv file with Symfony2's validation component (as of the 2.1 branch) using an external yml ruleset (not in a Symfony project):
use Symfony\Component\Validator\Validation;
$builder = Validation::createValidatorBuilder();
$builder->addYamlMapping('rules.yml');
$validator = $builder->getValidator();
$row = (object)array('name' => 'foo');
$violations = $validator->validate($row);
This is my yml file:
stdClass:
properties:
name:
- MinLength: 10
Now there is the problem that it does not seem to be possible with the Validator Component to validate objects with dynamic properties (like the stdClass or any other class with magic getters and setters).
When I run that code I get a message saying:
[Symfony\Component\Validator\Exception\ValidatorException]
Property forename does not exist in class stdClass
This is due to the PropertyMetaclass.php in the highlighted line where the existence is checked by using property_exists() which obviously does not work as it's checking against the class and not the object.
Does anyone know how I can get the Validator to work with objects having dynamic properties?