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