Dependency injection
This commit is contained in:
parent
a0a4ff15ee
commit
0c5b54c79e
3 changed files with 30 additions and 19 deletions
12
example.php
12
example.php
|
|
@ -10,12 +10,8 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
// Initialisation of the parser
|
||||
$parser = new CsvParser(__DIR__.'/tests/fixtures/example.csv');
|
||||
$parser->setHasLegend(true);
|
||||
|
||||
// Initialisation of the validator
|
||||
$validator = new Validator($parser, Validation::createValidator());
|
||||
$validator = new Validator();
|
||||
|
||||
// The first field must contain an email
|
||||
$validator->addFieldConstraint(0, new Email());
|
||||
|
|
@ -33,7 +29,11 @@ $validator->addDataConstraint(new Callback(function($data, ExecutionContextInter
|
|||
}
|
||||
}));
|
||||
|
||||
$validator->validate();
|
||||
// Initialisation of the parser
|
||||
$parser = new CsvParser(__DIR__.'/tests/fixtures/example.csv');
|
||||
$parser->setHasLegend(true);
|
||||
|
||||
$validator->validate($parser);
|
||||
|
||||
if ($validator->isValid() === false) {
|
||||
foreach ($validator->getErrors() as $error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue