Skip to content

Commit

Permalink
Update dependency laminas/laminas-servicemanager to v4
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Böhringer <[email protected]>
  • Loading branch information
tomboe311 committed Jul 9, 2024
1 parent aea5732 commit 366d3e5
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 66 deletions.
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
5 changes: 3 additions & 2 deletions test/unit/Adapter/AdapterServiceDelegatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laminas\Db\Adapter\AdapterServiceDelegator;
use Laminas\Db\Adapter\Driver\DriverInterface;
use Laminas\ServiceManager\AbstractPluginManager;

Check failure on line 10 in test/unit/Adapter/AdapterServiceDelegatorTest.php

View workflow job for this annotation

GitHub Actions / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Type Laminas\ServiceManager\AbstractPluginManager is not used in this file.
use Laminas\ServiceManager\AbstractSingleInstancePluginManager;
use Laminas\ServiceManager\ServiceManager;
use LaminasTest\Db\Adapter\TestAsset\ConcreteAdapterAwareObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -209,8 +210,8 @@ public function testDelegatorWithPluginManager()
],
];

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

$options = [
Expand Down

0 comments on commit 366d3e5

Please sign in to comment.