Skip to content

Commit

Permalink
Re-use validator config via ConfigProvider
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Jun 19, 2024
1 parent f6ac1a6 commit 62bb96a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
8 changes: 0 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,6 @@
<code><![CDATA[(string) $name]]></code>
</RedundantCastGivenDocblockType>
</file>
<file src="src/ConfigProvider.php">
<UndefinedClass>
<code><![CDATA[ConfigInterface]]></code>
<code><![CDATA[StorageInterface]]></code>
<code><![CDATA[\Zend\Session\ManagerInterface]]></code>
<code><![CDATA[\Zend\Session\SessionManager]]></code>
</UndefinedClass>
</file>
<file src="src/Container.php">
<MethodSignatureMustProvideReturnType>
<code><![CDATA[offsetGet]]></code>
Expand Down
36 changes: 21 additions & 15 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand All @@ -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()
{
Expand All @@ -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,
Expand All @@ -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,
],
];
}
}
11 changes: 1 addition & 10 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Laminas\Session;

use Laminas\ServiceManager\Factory\InvokableFactory;

class Module
{
/**
Expand All @@ -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(),
];
}
}

0 comments on commit 62bb96a

Please sign in to comment.