From c15d5d67bb0700eff7fac2983be67aaa8fcaf143 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 22 Nov 2014 05:29:43 +0100 Subject: [PATCH 1/3] zendframework/zf2#6386 zendframework/zf2#6496 - fixing values passed internally to `ValidatorChain#attach()` by `ValidatorChain#merge()` --- src/ValidatorChain.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ValidatorChain.php b/src/ValidatorChain.php index 9d0e70f80..469160898 100644 --- a/src/ValidatorChain.php +++ b/src/ValidatorChain.php @@ -262,7 +262,7 @@ public function isValid($value, $context = null) public function merge(ValidatorChain $validatorChain) { foreach ($validatorChain->validators->toArray(PriorityQueue::EXTR_BOTH) as $item) { - $this->attach($item['data'], $item['priority']); + $this->attach($item['data']['instance'], $item['data']['breakChainOnFailure'], $item['priority']); } return $this; From a19c484171e1700f5858b87ab04d7bace7fb09ae Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 22 Nov 2014 05:49:13 +0100 Subject: [PATCH 2/3] zendframework/zf2#6386 zendframework/zf2#6496 - `ValidatorChain` must be cloneable --- test/ValidatorChainTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/ValidatorChainTest.php b/test/ValidatorChainTest.php index c3500d9fc..b7180e944 100644 --- a/test/ValidatorChainTest.php +++ b/test/ValidatorChainTest.php @@ -202,6 +202,26 @@ public function testMergeValidatorChains() $this->assertCount(2, $this->validator->getValidators()); } + /** + * @group 6386 + * @group 6496 + */ + public function testValidatorChainIsCloneable() + { + $this->validator->attach(new NotEmpty()); + + $this->assertCount(1, $this->validator->getValidators()); + + $clonedValidatorChain = clone $this->validator; + + $this->assertCount(1, $clonedValidatorChain->getValidators()); + + $clonedValidatorChain->attach(new NotEmpty()); + + $this->assertCount(1, $this->validator->getValidators()); + $this->assertCount(2, $clonedValidatorChain->getValidators()); + } + public function testCountGivesCountOfAttachedValidators() { $this->populateValidatorChain(); From 9ba3524e5450394c644ed7d001519417344cc49a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 22 Nov 2014 05:49:30 +0100 Subject: [PATCH 3/3] zendframework/zf2#6386 zendframework/zf2#6496 - `ValidatorChain` can be cloned, as the validator chain is now deep-cloned --- src/ValidatorChain.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ValidatorChain.php b/src/ValidatorChain.php index 469160898..0c8f1bded 100644 --- a/src/ValidatorChain.php +++ b/src/ValidatorChain.php @@ -299,6 +299,14 @@ public function __invoke($value) return $this->isValid($value); } + /** + * Deep clone handling + */ + public function __clone() + { + $this->validators = clone $this->validators; + } + /** * Prepare validator chain for serialization *