From 62bb96afe4c8c346f2cdaa5c0d9f3357b15a2299 Mon Sep 17 00:00:00 2001 From: George Steel Date: Tue, 18 Jun 2024 15:19:46 +0100 Subject: [PATCH] Re-use validator config via ConfigProvider Signed-off-by: George Steel --- psalm-baseline.xml | 8 -------- src/ConfigProvider.php | 36 +++++++++++++++++++++--------------- src/Module.php | 11 +---------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 1af928fe..7113be59 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -382,14 +382,6 @@ - - - - - - - - diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index ccf97767..a127b6e6 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -3,9 +3,9 @@ namespace Laminas\Session; use Laminas\ServiceManager\Factory\InvokableFactory; -use Zend\Session\Config\ConfigInterface; -use Zend\Session\Storage\StorageInterface; +use Laminas\ServiceManager\ServiceManager; +/** @psalm-import-type ServiceManagerConfiguration from ServiceManager */ class ConfigProvider { /** @@ -17,21 +17,14 @@ public function __invoke() { return [ 'dependencies' => $this->getDependencyConfig(), - 'validators' => [ - 'factories' => [ - Validator\Csrf::class => InvokableFactory::class, - ], - 'aliases' => [ - 'csrf' => Validator\Csrf::class, - ], - ], + 'validators' => $this->getValidatorConfig(), ]; } /** * Retrieve dependency config for laminas-session. * - * @return array + * @return ServiceManagerConfiguration */ public function getDependencyConfig() { @@ -43,10 +36,10 @@ public function getDependencyConfig() SessionManager::class => ManagerInterface::class, // Legacy Zend Framework aliases - \Zend\Session\SessionManager::class => SessionManager::class, - ConfigInterface::class => Config\ConfigInterface::class, - \Zend\Session\ManagerInterface::class => ManagerInterface::class, - StorageInterface::class => Storage\StorageInterface::class, + 'Zend\Session\SessionManager' => SessionManager::class, + 'Zend\Session\Config\ConfigInterface' => Config\ConfigInterface::class, + 'Zend\Session\ManagerInterface' => ManagerInterface::class, + 'Zend\Session\Storage\StorageInterface' => Storage\StorageInterface::class, ], 'factories' => [ Config\ConfigInterface::class => Service\SessionConfigFactory::class, @@ -55,4 +48,17 @@ public function getDependencyConfig() ], ]; } + + /** @return ServiceManagerConfiguration */ + public function getValidatorConfig(): array + { + return [ + 'factories' => [ + Validator\Csrf::class => InvokableFactory::class, + ], + 'aliases' => [ + 'csrf' => Validator\Csrf::class, + ], + ]; + } } diff --git a/src/Module.php b/src/Module.php index f2236d7a..21455477 100644 --- a/src/Module.php +++ b/src/Module.php @@ -2,8 +2,6 @@ namespace Laminas\Session; -use Laminas\ServiceManager\Factory\InvokableFactory; - class Module { /** @@ -16,14 +14,7 @@ public function getConfig() $provider = new ConfigProvider(); return [ 'service_manager' => $provider->getDependencyConfig(), - 'validators' => [ - 'factories' => [ - Validator\Csrf::class => InvokableFactory::class, - ], - 'aliases' => [ - 'csrf' => Validator\Csrf::class, - ], - ], + 'validators' => $provider->getValidatorConfig(), ]; } }