forked from deblan/csv-validator
Compare commits
No commits in common. "master" and "1.1" have entirely different histories.
4 changed files with 10 additions and 9 deletions
|
|
@ -39,7 +39,7 @@ $validator->addFieldConstraint(0, new Email());
|
|||
$validator->addFieldConstraint(1, new Date());
|
||||
|
||||
// Validate the legend
|
||||
$validator->setExpectedLegend(array('foo', 'bar', 'bim'));
|
||||
$validator->setExceptedLegend(array('foo', 'bar', 'bim'));
|
||||
|
||||
// An line must contain 3 columns
|
||||
$validator->addDataConstraint(new Callback(function($data, ExecutionContextInterface $context) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@
|
|||
"require": {
|
||||
"php": ">=5.6.0",
|
||||
"symfony/validator": "2.*",
|
||||
"deblan/csv": "v1.1"
|
||||
"deblan/csv": "1.1.x-dev"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ $validator->addFieldConstraint(0, new Email());
|
|||
$validator->addFieldConstraint(1, new Date());
|
||||
|
||||
// Validate the legend
|
||||
$validator->setExpectedLegend(array('foo', 'bar', 'bim'));
|
||||
$validator->setExceptedLegend(array('foo', 'bar', 'bim'));
|
||||
|
||||
// An line must contain 3 columns
|
||||
$validator->addDataConstraint(new Callback(function($data, ExecutionContextInterface $context) {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ class Validator
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CsvParser $parser
|
||||
* @param RecursiveValidator $validator
|
||||
*/
|
||||
public function __construct(RecursiveValidator $validator = null)
|
||||
|
|
@ -67,7 +68,7 @@ class Validator
|
|||
/**
|
||||
* Append a constraint to a specific column
|
||||
*
|
||||
* @param integer $key The column number
|
||||
* @param $key The column number
|
||||
* @param Constraint $constraint The constraint
|
||||
* @return Validator
|
||||
*/
|
||||
|
|
@ -85,6 +86,7 @@ class Validator
|
|||
/**
|
||||
* Append a constraint to a specific line
|
||||
*
|
||||
* @param $key The column number
|
||||
* @param Constraint $constraint The constraint
|
||||
* @return Validator
|
||||
*/
|
||||
|
|
@ -96,12 +98,12 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the expected legend
|
||||
* Set the excepted legend
|
||||
*
|
||||
* @param array $legend Expected legend
|
||||
* @return Validator
|
||||
*/
|
||||
public function setExpectedLegend(array $legend)
|
||||
public function setExceptedLegend(array $legend)
|
||||
{
|
||||
$this->expectedLegend = $legend;
|
||||
|
||||
|
|
@ -110,7 +112,6 @@ class Validator
|
|||
|
||||
/**
|
||||
* Run the validation
|
||||
* @param CsvParser $parser
|
||||
*/
|
||||
public function validate(CsvParser $parser)
|
||||
{
|
||||
|
|
@ -160,7 +161,7 @@ class Validator
|
|||
|
||||
foreach ($this->parser->getDatas() as $line => $data) {
|
||||
foreach ($this->dataConstraints as $constraint) {
|
||||
$violations = $this->validator->validate($data, $constraint);
|
||||
$violations = $this->validator->validateValue($data, $constraint);
|
||||
|
||||
$this->mergeViolationsMessages($violations, $this->getTrueLine($line));
|
||||
}
|
||||
|
|
@ -187,7 +188,7 @@ class Validator
|
|||
);
|
||||
} else {
|
||||
foreach ($constraints as $constraint) {
|
||||
$violations = $this->validator->validate($data[$key], $constraint);
|
||||
$violations = $this->validator->validateValue($data[$key], $constraint);
|
||||
|
||||
$this->mergeViolationsMessages(
|
||||
$violations,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue