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());
|
$validator->addFieldConstraint(1, new Date());
|
||||||
|
|
||||||
// Validate the legend
|
// Validate the legend
|
||||||
$validator->setExpectedLegend(array('foo', 'bar', 'bim'));
|
$validator->setExceptedLegend(array('foo', 'bar', 'bim'));
|
||||||
|
|
||||||
// An line must contain 3 columns
|
// An line must contain 3 columns
|
||||||
$validator->addDataConstraint(new Callback(function($data, ExecutionContextInterface $context) {
|
$validator->addDataConstraint(new Callback(function($data, ExecutionContextInterface $context) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,6 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.6.0",
|
"php": ">=5.6.0",
|
||||||
"symfony/validator": "2.*",
|
"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());
|
$validator->addFieldConstraint(1, new Date());
|
||||||
|
|
||||||
// Validate the legend
|
// Validate the legend
|
||||||
$validator->setExpectedLegend(array('foo', 'bar', 'bim'));
|
$validator->setExceptedLegend(array('foo', 'bar', 'bim'));
|
||||||
|
|
||||||
// An line must contain 3 columns
|
// An line must contain 3 columns
|
||||||
$validator->addDataConstraint(new Callback(function($data, ExecutionContextInterface $context) {
|
$validator->addDataConstraint(new Callback(function($data, ExecutionContextInterface $context) {
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ class Validator
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
* @param CsvParser $parser
|
||||||
* @param RecursiveValidator $validator
|
* @param RecursiveValidator $validator
|
||||||
*/
|
*/
|
||||||
public function __construct(RecursiveValidator $validator = null)
|
public function __construct(RecursiveValidator $validator = null)
|
||||||
|
|
@ -67,7 +68,7 @@ class Validator
|
||||||
/**
|
/**
|
||||||
* Append a constraint to a specific column
|
* Append a constraint to a specific column
|
||||||
*
|
*
|
||||||
* @param integer $key The column number
|
* @param $key The column number
|
||||||
* @param Constraint $constraint The constraint
|
* @param Constraint $constraint The constraint
|
||||||
* @return Validator
|
* @return Validator
|
||||||
*/
|
*/
|
||||||
|
|
@ -85,6 +86,7 @@ class Validator
|
||||||
/**
|
/**
|
||||||
* Append a constraint to a specific line
|
* Append a constraint to a specific line
|
||||||
*
|
*
|
||||||
|
* @param $key The column number
|
||||||
* @param Constraint $constraint The constraint
|
* @param Constraint $constraint The constraint
|
||||||
* @return Validator
|
* @return Validator
|
||||||
*/
|
*/
|
||||||
|
|
@ -96,12 +98,12 @@ class Validator
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the expected legend
|
* Set the excepted legend
|
||||||
*
|
*
|
||||||
* @param array $legend Expected legend
|
* @param array $legend Expected legend
|
||||||
* @return Validator
|
* @return Validator
|
||||||
*/
|
*/
|
||||||
public function setExpectedLegend(array $legend)
|
public function setExceptedLegend(array $legend)
|
||||||
{
|
{
|
||||||
$this->expectedLegend = $legend;
|
$this->expectedLegend = $legend;
|
||||||
|
|
||||||
|
|
@ -110,7 +112,6 @@ class Validator
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the validation
|
* Run the validation
|
||||||
* @param CsvParser $parser
|
|
||||||
*/
|
*/
|
||||||
public function validate(CsvParser $parser)
|
public function validate(CsvParser $parser)
|
||||||
{
|
{
|
||||||
|
|
@ -160,7 +161,7 @@ class Validator
|
||||||
|
|
||||||
foreach ($this->parser->getDatas() as $line => $data) {
|
foreach ($this->parser->getDatas() as $line => $data) {
|
||||||
foreach ($this->dataConstraints as $constraint) {
|
foreach ($this->dataConstraints as $constraint) {
|
||||||
$violations = $this->validator->validate($data, $constraint);
|
$violations = $this->validator->validateValue($data, $constraint);
|
||||||
|
|
||||||
$this->mergeViolationsMessages($violations, $this->getTrueLine($line));
|
$this->mergeViolationsMessages($violations, $this->getTrueLine($line));
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +188,7 @@ class Validator
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
foreach ($constraints as $constraint) {
|
foreach ($constraints as $constraint) {
|
||||||
$violations = $this->validator->validate($data[$key], $constraint);
|
$violations = $this->validator->validateValue($data[$key], $constraint);
|
||||||
|
|
||||||
$this->mergeViolationsMessages(
|
$this->mergeViolationsMessages(
|
||||||
$violations,
|
$violations,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue