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

Update dependency laminas/laminas-servicemanager to v4 #309

Open
wants to merge 3 commits into
base: 2.21.x
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"laminas/laminas-coding-standard": "^2.4.0",
"laminas/laminas-eventmanager": "^3.6.0",
"laminas/laminas-hydrator": "^4.7",
"laminas/laminas-servicemanager": "^3.19.0",
"laminas/laminas-servicemanager": "^4.1",
"phpunit/phpunit": "^9.5.25"
},
"suggest": {
Expand Down
108 changes: 77 additions & 31 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 18 additions & 24 deletions src/Adapter/AdapterAbstractServiceFactory.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\AbstractFactoryInterface;
use Laminas\ServiceManager\Factory\AbstractFactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Psr\Container\ContainerInterface;

use function is_array;

Expand All @@ -20,11 +22,8 @@ class AdapterAbstractServiceFactory implements AbstractFactoryInterface

/**
* Can we create an adapter by the requested name?
*
* @param string $requestedName
* @return bool
*/
public function canCreate(ContainerInterface $container, $requestedName)
public function canCreate(ContainerInterface $container, string $requestedName): bool
{
$config = $this->getConfig($container);
if (empty($config)) {
Expand All @@ -38,47 +37,42 @@ public function canCreate(ContainerInterface $container, $requestedName)

/**
* Determine if we can create a service with name (SM v2 compatibility)
*
* @param string $name
* @param string $requestedName
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
public function canCreateServiceWithName(
ServiceLocatorInterface $serviceLocator,
string $name,
string $requestedName
): bool {
return $this->canCreate($serviceLocator, $requestedName);
}

/**
* Create a DB adapter
*
* @param string $requestedName
* @param array $options
* @param array|null $options
* @return Adapter
*/
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
public function __invoke(ContainerInterface $container, string $requestedName, ?array $options = null): mixed
{
$config = $this->getConfig($container);
return new Adapter($config[$requestedName]);
}

/**
* Create service with name
*
* @param string $name
* @param string $requestedName
* @return Adapter
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
public function createServiceWithName(
ServiceLocatorInterface $serviceLocator,
string $name,
string $requestedName
): Adapter {
return $this($serviceLocator, $requestedName);
}

/**
* Get db configuration, if any
*
* @return array
*/
protected function getConfig(ContainerInterface $container)
protected function getConfig(ContainerInterface $container): array
{
if ($this->config !== null) {
return $this->config;
Expand Down
14 changes: 6 additions & 8 deletions src/Adapter/AdapterServiceFactory.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Psr\Container\ContainerInterface;

class AdapterServiceFactory implements FactoryInterface
{
/**
* Create db adapter service
*
* @param string $requestedName
* @param array $options
* @return Adapter
*/
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
public function __invoke(ContainerInterface $container, string $requestedName, ?array $options = null): mixed
{
$config = $container->get('config');
return new Adapter($config['db']);
}

/**
* Create db adapter service (v2)
*
* @return Adapter
*/
public function createService(ServiceLocatorInterface $container)
public function createService(ServiceLocatorInterface $container): Adapter
{
return $this($container, Adapter::class);
}
Expand Down
13 changes: 7 additions & 6 deletions test/unit/Adapter/AdapterAbstractServiceFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Db\Adapter;

use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Adapter\AdapterAbstractServiceFactory;
use Laminas\ServiceManager\Config;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\ServiceManager;
Expand All @@ -18,11 +19,11 @@ class AdapterAbstractServiceFactoryTest extends TestCase
protected function setUp(): void
{
$this->serviceManager = new ServiceManager();

$config = new Config([
'abstract_factories' => [AdapterAbstractServiceFactory::class],
]);
$config->configureServiceManager($this->serviceManager);
$this->serviceManager->configure(
[
'abstract_factories' => [AdapterAbstractServiceFactory::class],
]
);

$this->serviceManager->setService('config', [
'db' => [
Expand Down
9 changes: 5 additions & 4 deletions test/unit/Adapter/AdapterServiceDelegatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Db\Adapter\AdapterServiceDelegator;
use Laminas\Db\Adapter\Driver\DriverInterface;
use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\AbstractSingleInstancePluginManager;
use Laminas\ServiceManager\ServiceManager;
use LaminasTest\Db\Adapter\TestAsset\ConcreteAdapterAwareObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -209,8 +209,9 @@ public function testDelegatorWithPluginManager()
],
];

/** @var AbstractPluginManager $pluginManager */
$pluginManager = new class ($container, $pluginManagerConfig) extends AbstractPluginManager {
/** @var AbstractSingleInstancePluginManager $pluginManager */
$pluginManager = new class ($container, $pluginManagerConfig) extends AbstractSingleInstancePluginManager {
protected string $instanceOf = ConcreteAdapterAwareObject::class;
};

$options = [
Expand All @@ -219,7 +220,7 @@ public function testDelegatorWithPluginManager()
];

/** @var ConcreteAdapterAwareObject $result */
$result = $pluginManager->get(
$result = $pluginManager->build(
ConcreteAdapterAwareObject::class,
$options
);
Expand Down