From 8b28942dddbb5cefe85759dbf7ebd4cf2a38ee12 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 23 Feb 2016 14:21:34 -0600 Subject: [PATCH 1/2] Extract constructor from trait to implementations - See zendframwork/zf2#7676 --- src/Validator/ValidatorChainEM2.php | 23 +++++++++++++++++++++++ src/Validator/ValidatorChainEM3.php | 23 +++++++++++++++++++++++ src/Validator/ValidatorChainTrait.php | 20 -------------------- 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/Validator/ValidatorChainEM2.php b/src/Validator/ValidatorChainEM2.php index f023a66f..24641663 100644 --- a/src/Validator/ValidatorChainEM2.php +++ b/src/Validator/ValidatorChainEM2.php @@ -9,6 +9,7 @@ namespace Zend\Session\Validator; use Zend\EventManager\EventManager; +use Zend\Session\Storage\StorageInterface; /** * Validator chain for validating sessions (for use with zend-eventmanager v2) @@ -17,6 +18,28 @@ class ValidatorChainEM2 extends EventManager { use ValidatorChainTrait; + /** + * Construct the validation chain + * + * Retrieves validators from session storage and attaches them. + * + * Duplicated in ValidatorChainEM3 to prevent trait collision with parent. + * + * @param StorageInterface $storage + */ + public function __construct(StorageInterface $storage) + { + parent::__construct(); + + $this->storage = $storage; + $validators = $storage->getMetadata('_VALID'); + if ($validators) { + foreach ($validators as $validator => $data) { + $this->attachValidator('session.validate', [new $validator($data), 'isValid'], 1); + } + } + } + /** * Attach a listener to the session validator chain. * diff --git a/src/Validator/ValidatorChainEM3.php b/src/Validator/ValidatorChainEM3.php index 7c5f94fb..7c0f0dcf 100644 --- a/src/Validator/ValidatorChainEM3.php +++ b/src/Validator/ValidatorChainEM3.php @@ -9,6 +9,7 @@ namespace Zend\Session\Validator; use Zend\EventManager\EventManager; +use Zend\Session\Storage\StorageInterface; /** * Validator chain for validating sessions (for use with zend-eventmanager v3) @@ -17,6 +18,28 @@ class ValidatorChainEM3 extends EventManager { use ValidatorChainTrait; + /** + * Construct the validation chain + * + * Retrieves validators from session storage and attaches them. + * + * Duplicated in ValidatorChainEM2 to prevent trait collision with parent. + * + * @param StorageInterface $storage + */ + public function __construct(StorageInterface $storage) + { + parent::__construct(); + + $this->storage = $storage; + $validators = $storage->getMetadata('_VALID'); + if ($validators) { + foreach ($validators as $validator => $data) { + $this->attachValidator('session.validate', [new $validator($data), 'isValid'], 1); + } + } + } + /** * Attach a listener to the session validator chain. * diff --git a/src/Validator/ValidatorChainTrait.php b/src/Validator/ValidatorChainTrait.php index 01275b44..4a80e1f8 100644 --- a/src/Validator/ValidatorChainTrait.php +++ b/src/Validator/ValidatorChainTrait.php @@ -20,26 +20,6 @@ trait ValidatorChainTrait */ protected $storage; - /** - * Construct the validation chain - * - * Retrieves validators from session storage and attaches them. - * - * @param StorageInterface $storage - */ - public function __construct(StorageInterface $storage) - { - parent::__construct(); - - $this->storage = $storage; - $validators = $storage->getMetadata('_VALID'); - if ($validators) { - foreach ($validators as $validator => $data) { - $this->attachValidator('session.validate', [new $validator($data), 'isValid'], 1); - } - } - } - /** * Retrieve session storage object * From 43d09e80f3ff09903013707dad758df2e06176e9 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 23 Feb 2016 14:46:21 -0600 Subject: [PATCH 2/2] Added CHANGELOG for #30 --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5edd866c..f77e1634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.6.1 - TBD +## 2.6.1 - 2016-02-23 ### Added @@ -18,7 +18,11 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#29](https://github.com/zendframework/zend-session/pull/29) extracts the + constructor defined in `Zend\Session\Validator\ValidatorChainTrait` and pushes + it into each of the `ValidatorChainEM2` and `ValidatorChainEM3` + implementations, to prevent colliding constructor definitions due to + inheritance + trait usage. ## 2.6.0 - 2016-02-23