From 0c5b54c79e85fe28ae43c2d407a78742ec6738b9 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 23 May 2016 20:19:13 +0200 Subject: [PATCH 01/16] Dependency injection --- README.md | 12 ++++++------ example.php | 12 ++++++------ src/Deblan/CsvValidator/Validator.php | 25 ++++++++++++++++++------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3a07c82..381aac3 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,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()); @@ -52,7 +48,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) { diff --git a/example.php b/example.php index 2a475df..05c5aff 100644 --- a/example.php +++ b/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) { diff --git a/src/Deblan/CsvValidator/Validator.php b/src/Deblan/CsvValidator/Validator.php index 8ee6624..3d0c083 100644 --- a/src/Deblan/CsvValidator/Validator.php +++ b/src/Deblan/CsvValidator/Validator.php @@ -7,6 +7,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Validator\RecursiveValidator; use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\Validation; /** * Class Validator @@ -55,10 +56,12 @@ class Validator * @param CsvParser $parser * @param RecursiveValidator $validator */ - public function __construct(CsvParser $parser, RecursiveValidator $validator) + public function __construct(RecursiveValidator $validator = null) { - $this->parser = $parser; - $this->parser->parse(); + if ($validator === null) { + $validator = Validation::createValidator(); + } + $this->validator = $validator; } @@ -110,12 +113,17 @@ class Validator /** * Run the validation */ - public function validate() + public function validate(CsvParser $parser) { - if ($this->hasValidate) { + if ($this->parser !== $parser) { + $this->parser = $parser; + $this->parser->parse(); + $this->errors = []; + } + elseif ($this->hasValidate) { return; } - + $this->validateLegend(); $this->validateDatas(); $this->validateFields(); @@ -123,7 +131,10 @@ class Validator $this->hasValidate = true; } - + + /** + * Validates the legend + */ protected function validateLegend() { if (!$this->parser->getHasLegend()) { From a87103518a2b4ae303ff925ca795b59b5997e342 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 23 May 2016 20:31:04 +0200 Subject: [PATCH 02/16] packaging --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 35c246e..7c845f2 100644 --- a/composer.json +++ b/composer.json @@ -18,5 +18,10 @@ "php": ">=5.6.0", "symfony/validator": "2.*", "deblan/csv": "dev-master" + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } } } From ea8c66512abc7bc70ae16703e4bf72507e512d87 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 23 May 2016 20:31:44 +0200 Subject: [PATCH 03/16] packaging --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7c845f2..c985967 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "v1.0-dev" } } } From 0c24bf2e3a3c68251c1e8bd0e6d819925a1fc3db Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 23 May 2016 20:32:12 +0200 Subject: [PATCH 04/16] packaging --- composer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/composer.json b/composer.json index c985967..35c246e 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,5 @@ "php": ">=5.6.0", "symfony/validator": "2.*", "deblan/csv": "dev-master" - }, - "extra": { - "branch-alias": { - "dev-master": "v1.0-dev" - } } } From a09bb929a0ee6c15430cb53121c182fd3df8e526 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 23 May 2016 20:43:08 +0200 Subject: [PATCH 05/16] packaging --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3a07c82..d92fc83 100644 --- a/README.md +++ b/README.md @@ -73,3 +73,4 @@ EOF; } } ``` + From 8ff4db14a27c105a7f673ed1d1ecfc9f0bd08efc Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 23 May 2016 20:59:27 +0200 Subject: [PATCH 06/16] packaging --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d92fc83..24cef8b 100644 --- a/README.md +++ b/README.md @@ -74,3 +74,4 @@ EOF; } ``` + From 0bb235e8dd58be0e24e27392fbd1511226fdee6a Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 24 May 2016 00:43:14 +0200 Subject: [PATCH 07/16] packaging --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 35c246e..e2125f0 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "require": { "php": ">=5.6.0", "symfony/validator": "2.*", - "deblan/csv": "dev-master" + "deblan/csv": "1.*" } } From 0f60a1a8b6acfbe35d52494ec1265ed01c4c80a7 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 24 May 2016 17:03:10 +0200 Subject: [PATCH 08/16] packaging --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index e2125f0..4370750 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,5 @@ "require": { "php": ">=5.6.0", "symfony/validator": "2.*", - "deblan/csv": "1.*" } } From 45c446bb14afcecb2893d2be1dad9a9defd7cead Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 24 May 2016 17:04:02 +0200 Subject: [PATCH 09/16] packaging --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 4370750..300e532 100644 --- a/composer.json +++ b/composer.json @@ -17,5 +17,6 @@ "require": { "php": ">=5.6.0", "symfony/validator": "2.*", + "deblan/csv": ">= 1.1" } } From 7aa3198e3fa5f7bdbbc5517213fe796e7d798c79 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 24 May 2016 17:06:05 +0200 Subject: [PATCH 10/16] packaging --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 300e532..d58d254 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "require": { "php": ">=5.6.0", "symfony/validator": "2.*", - "deblan/csv": ">= 1.1" + "deblan/csv": ">1.0" } } From 003621e8a7be2bc0c3a3ed71568064d54e1071da Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 24 May 2016 17:07:33 +0200 Subject: [PATCH 11/16] packaging --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d58d254..5cb1935 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "require": { "php": ">=5.6.0", "symfony/validator": "2.*", - "deblan/csv": ">1.0" + "deblan/csv": "1.1.x-dev" } } From e88a23bb1d1f68a0eeb10c9f7f2829e450d3c60e Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 24 May 2016 17:07:50 +0200 Subject: [PATCH 12/16] packaging --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5cb1935..258e14b 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "require": { "php": ">=5.6.0", "symfony/validator": "2.*", - "deblan/csv": "1.1.x-dev" + "deblan/csv": "1.1.x-dev" } } From 0ee2884b3d027ff1d6701a2028860a7737f85b47 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 30 May 2016 12:02:49 +0200 Subject: [PATCH 13/16] Renaming of method --- README.md | 2 +- example.php | 2 +- src/Deblan/CsvValidator/Validator.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 381aac3..fa1e271 100644 --- a/README.md +++ b/README.md @@ -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) { diff --git a/example.php b/example.php index 05c5aff..48250f6 100644 --- a/example.php +++ b/example.php @@ -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) { diff --git a/src/Deblan/CsvValidator/Validator.php b/src/Deblan/CsvValidator/Validator.php index 3d0c083..98702cc 100644 --- a/src/Deblan/CsvValidator/Validator.php +++ b/src/Deblan/CsvValidator/Validator.php @@ -98,12 +98,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; From 7ef39038631f5d9260b2628e2b00a1263b4e38e5 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 13 Oct 2016 15:51:11 +0200 Subject: [PATCH 14/16] Packaging --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 258e14b..6493934 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "require": { "php": ">=5.6.0", "symfony/validator": "2.*", - "deblan/csv": "1.1.x-dev" + "deblan/csv": "1.1" } } From 6be22908dc82edc9c92347d492bc6d6df3127321 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 13 Oct 2016 15:53:40 +0200 Subject: [PATCH 15/16] Packaging --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6493934..c9aa77f 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "require": { "php": ">=5.6.0", "symfony/validator": "2.*", - "deblan/csv": "1.1" + "deblan/csv": "v1.1" } } From cbd3ce7e69399c29028363e8852b24a9a4f70439 Mon Sep 17 00:00:00 2001 From: "gautier.deruette" Date: Thu, 1 Dec 2016 11:41:15 +0100 Subject: [PATCH 16/16] =?UTF-8?q?Mettre=20=C3=A0=20jour=20'src/Deblan/CsvV?= =?UTF-8?q?alidator/Validator.php'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Deblan/CsvValidator/Validator.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Deblan/CsvValidator/Validator.php b/src/Deblan/CsvValidator/Validator.php index 98702cc..e6650d0 100644 --- a/src/Deblan/CsvValidator/Validator.php +++ b/src/Deblan/CsvValidator/Validator.php @@ -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 */ @@ -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,