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());
|
$validator->addFieldConstraint(1, new Date());
|
||||||
|
|
||||||
// Validate the legend
|
// Validate the legend
|
||||||
$validator->setExceptedLegend(array('foo', 'bar', 'bim'));
|
$validator->setExpectedLegend(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": "1.1.x-dev"
|
"deblan/csv": "v1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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->setExceptedLegend(array('foo', 'bar', 'bim'));
|
$validator->setExpectedLegend(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,7 +53,6 @@ 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)
|
||||||
|
|
@ -68,7 +67,7 @@ class Validator
|
||||||
/**
|
/**
|
||||||
* Append a constraint to a specific column
|
* Append a constraint to a specific column
|
||||||
*
|
*
|
||||||
* @param $key The column number
|
* @param integer $key The column number
|
||||||
* @param Constraint $constraint The constraint
|
* @param Constraint $constraint The constraint
|
||||||
* @return Validator
|
* @return Validator
|
||||||
*/
|
*/
|
||||||
|
|
@ -86,7 +85,6 @@ 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
|
||||||
*/
|
*/
|
||||||
|
|
@ -98,12 +96,12 @@ class Validator
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the excepted legend
|
* Set the expected legend
|
||||||
*
|
*
|
||||||
* @param array $legend Expected legend
|
* @param array $legend Expected legend
|
||||||
* @return Validator
|
* @return Validator
|
||||||
*/
|
*/
|
||||||
public function setExceptedLegend(array $legend)
|
public function setExpectedLegend(array $legend)
|
||||||
{
|
{
|
||||||
$this->expectedLegend = $legend;
|
$this->expectedLegend = $legend;
|
||||||
|
|
||||||
|
|
@ -112,6 +110,7 @@ class Validator
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the validation
|
* Run the validation
|
||||||
|
* @param CsvParser $parser
|
||||||
*/
|
*/
|
||||||
public function validate(CsvParser $parser)
|
public function validate(CsvParser $parser)
|
||||||
{
|
{
|
||||||
|
|
@ -161,7 +160,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->validateValue($data, $constraint);
|
$violations = $this->validator->validate($data, $constraint);
|
||||||
|
|
||||||
$this->mergeViolationsMessages($violations, $this->getTrueLine($line));
|
$this->mergeViolationsMessages($violations, $this->getTrueLine($line));
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +187,7 @@ class Validator
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
foreach ($constraints as $constraint) {
|
foreach ($constraints as $constraint) {
|
||||||
$violations = $this->validator->validateValue($data[$key], $constraint);
|
$violations = $this->validator->validate($data[$key], $constraint);
|
||||||
|
|
||||||
$this->mergeViolationsMessages(
|
$this->mergeViolationsMessages(
|
||||||
$violations,
|
$violations,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue