From 88215db74f5e62f360ab105a6eddd5a54a8848e8 Mon Sep 17 00:00:00 2001 From: RJ Garcia Date: Thu, 13 Apr 2017 15:38:05 -0700 Subject: [PATCH] Preparing 0.3.3 release - Fixed bug with Kernel not passing context Signed-off-by: RJ Garcia --- CHANGELOG.md | 6 ++++++ src/Kernel.php | 1 + src/ValidationServiceProvider.php | 2 +- src/WrappedValidator.php | 6 ++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dce2ff0..8ede1af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## 0.3.3 - 2017-04-13 + +### Fixed + +- Kernel bug where context was not passed in + ## 0.3.2 - 2017-04-13 ### Fixed diff --git a/src/Kernel.php b/src/Kernel.php index bb817de..77b4edf 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -55,6 +55,7 @@ public function make($validations) { $this[MessageStore::class], $this[FormatMessage::class], $this[FormatViolations::class], + $this['krak.validation.context']->getArrayCopy(), $validations ); } diff --git a/src/ValidationServiceProvider.php b/src/ValidationServiceProvider.php index e8b2f48..97afeff 100644 --- a/src/ValidationServiceProvider.php +++ b/src/ValidationServiceProvider.php @@ -37,7 +37,7 @@ public function register(Cargo\Container $c) { $c['krak.validation.default_message'] = "The {{attribute}} is invalid."; $c['krak.validation.validators'] = new ArrayObject(); $c['krak.validation.context'] = new ArrayObject([ - 'container' => $c, + 'container' => Cargo\toInterop($c), ]); } } diff --git a/src/WrappedValidator.php b/src/WrappedValidator.php index 7f494e4..2aa1d2b 100644 --- a/src/WrappedValidator.php +++ b/src/WrappedValidator.php @@ -7,16 +7,18 @@ class WrappedValidator implements FormatMessage, FormatViolations { private $message_store; private $format_message; private $format_violations; + private $context; private $validations; private $result; private $has_run; - public function __construct(ValidationContext $validation_context, MessageStore $message_store, FormatMessage $format_message, FormatViolations $format_violations, $validations) { + public function __construct(ValidationContext $validation_context, MessageStore $message_store, FormatMessage $format_message, FormatViolations $format_violations, array $context, $validations) { $this->validation_context = $validation_context; $this->message_store = $message_store; $this->format_message = $format_message; $this->format_violations = $format_violations; + $this->context = $context; $this->validations = $validations; $this->has_run = false; } @@ -42,7 +44,7 @@ public function messages($data) { } public function validate($value, array $ctx = []) { - $violation = $this->validation_context->validate($value, $this->validations, $ctx); + $violation = $this->validation_context->validate($value, $this->validations, array_merge($this->context, $ctx)); $this->has_run = true; if (!$violation) { return;