Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove laminas-modulemanager support #384

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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