Skip to content

Commit

Permalink
Merge pull request #384 from gsteel/v3/remove-module-manager-support
Browse files Browse the repository at this point in the history
Remove `laminas-modulemanager` support
  • Loading branch information
gsteel authored Aug 1, 2024
2 parents eead6a2 + e291698 commit 72ef168
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 112 deletions.
16 changes: 0 additions & 16 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@
</PossiblyUnusedProperty>
</file>
<file src="src/Module.php">
<PossiblyUnusedParam>
<code><![CDATA[$moduleManager]]></code>
</PossiblyUnusedParam>
<UndefinedDocblockClass>
<code><![CDATA[ModuleManager]]></code>
</UndefinedDocblockClass>
<UnusedClass>
<code><![CDATA[Module]]></code>
</UnusedClass>
Expand Down Expand Up @@ -181,16 +175,6 @@
<code><![CDATA[setValidatorPluginManager]]></code>
</MissingReturnType>
</file>
<file src="src/ValidatorPluginManagerFactory.php">
<MixedArgument>
<code><![CDATA[$config['validators']]]></code>
</MixedArgument>
</file>
<file src="src/ValidatorProviderInterface.php">
<UnusedClass>
<code><![CDATA[ValidatorProviderInterface]]></code>
</UnusedClass>
</file>
<file src="test/AbstractValidatorTest.php">
<MixedArgument>
<code><![CDATA[$message]]></code>
Expand Down
22 changes: 0 additions & 22 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Laminas\Validator;

use Laminas\ModuleManager\ModuleManager;
use Laminas\ServiceManager\ServiceManager;

/** @psalm-import-type ServiceManagerConfiguration from ServiceManager */
Expand All @@ -24,25 +23,4 @@ public function getConfig(): array
'service_manager' => $provider->getDependencyConfig(),
];
}

/**
* Register a specification for the ValidatorManager with the ServiceListener.
*
* @deprecated ModuleManager support will be removed in version 3.0 of this component
*
* @param ModuleManager $moduleManager
*/
public function init($moduleManager): void
{
$event = $moduleManager->getEvent();
$container = $event->getParam('ServiceManager');
$serviceListener = $container->get('ServiceListener');

$serviceListener->addServiceManager(
'ValidatorManager',
'validators',
ValidatorProviderInterface::class,
'getValidatorConfig'
);
}
}
33 changes: 11 additions & 22 deletions src/ValidatorPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,24 @@
use Laminas\ServiceManager\ServiceManager;
use Psr\Container\ContainerInterface;

use function assert;
use function is_array;

/**
* @link ServiceManager
*
* @psalm-import-type ServiceManagerConfiguration from ServiceManager
*/
/** @psalm-import-type ServiceManagerConfiguration from ServiceManager */
final class ValidatorPluginManagerFactory
{
public function __invoke(ContainerInterface $container): ValidatorPluginManager
{
// If this is in a laminas-mvc application, the ServiceListener will inject
// merged configuration during bootstrap.
if ($container->has('ServiceListener')) {
return new ValidatorPluginManager($container);
}
$config = $container->has('config')
? $container->get('config')
: [];
assert(is_array($config));

// If we do not have a config service, nothing more to do
if (! $container->has('config')) {
return new ValidatorPluginManager($container);
}
/** @psalm-var ServiceManagerConfiguration $validators */
$validators = isset($config['validators']) && is_array($config['validators'])
? $config['validators']
: [];

$config = $container->get('config');

// If we do not have validators configuration, nothing more to do
if (! isset($config['validators']) || ! is_array($config['validators'])) {
return new ValidatorPluginManager($container);
}

return new ValidatorPluginManager($container, $config['validators']);
return new ValidatorPluginManager($container, $validators);
}
}
28 changes: 0 additions & 28 deletions src/ValidatorProviderInterface.php

This file was deleted.

24 changes: 0 additions & 24 deletions test/ValidatorPluginManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace LaminasTest\Validator;

use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\Validator\Digits;
use Laminas\Validator\ValidatorInterface;
use Laminas\Validator\ValidatorPluginManager;
Expand Down Expand Up @@ -49,29 +48,6 @@ public function testConfiguresValidatorServicesWhenFound(): void
self::assertSame($validator, $validators->get('test-too'));
}

public function testDoesNotConfigureValidatorServicesWhenServiceListenerPresent(): void
{
$container = $this->createMock(ServiceLocatorInterface::class);

$container
->expects(self::once())
->method('has')
->with('ServiceListener')
->willReturn(true);

$container
->expects(self::never())
->method('get')
->with('config');

$factory = new ValidatorPluginManagerFactory();
$validators = $factory($container);

self::assertInstanceOf(ValidatorPluginManager::class, $validators);
self::assertFalse($validators->has('test'));
self::assertFalse($validators->has('test-too'));
}

public function testDoesNotConfigureValidatorServicesWhenConfigServiceNotPresent(): void
{
$container = new InMemoryContainer();
Expand Down

0 comments on commit 72ef168

Please sign in to comment.