- * [
- * \Laminas\Filter\FilterPluginManager::class => 'FilterManager',
- * \Laminas\Validator\ValidatorPluginManager::class => 'ValidatorManager',
- * ]
- *
- *
- * @var string[]
- */
- protected $aliases = [];
+ private ConstructorParameterResolverInterface $constructorParameterResolver;
/**
* Allows overriding the internal list of aliases. These should be of the
* form `class name => well-known service name`; see the documentation for
* the `$aliases` property for details on what is accepted.
*
- * @param string[] $aliases
+ * @param arrayFactory-Driven Dependency Injection Container
+ +$ composer require laminas/laminas-servicemanager
+ $requestedName
new $requestedName()
- new $requestedName()
- new $requestedName(...$parameters)
- function (ReflectionParameter $parameter) use ($container, $requestedName) {
- $requestedName
- $requestedName
- $requestedName
- $requestedName
- new $requestedName()
- new $requestedName()
+ new $requestedName(...$parameters)
DispatchableInterface
- is_string($type)
- DispatchableInterface
- 'Holistic'
assertInstanceOf
- assertInstanceOf
- assertInstanceOf
- assertInstanceOf
- assertInstanceOf
- assertInstanceOf
- assertInstanceOf
- assertInstanceOf
- array
- setServiceLocator
@@ -334,9 +292,6 @@
getServiceLocator
- $object['get'][0]
$names[$name]
$object[$shared ? $method : 'build']
- $first
$idx1
$idx2
@@ -379,14 +334,6 @@
$nonSharedObj1
$nonSharedObj2
$obj
- $object1
- $object1
- $object1
- $object1
- $object2
- $object2
- $object2
- $object2
$object[$shared ? $method : 'build'][]
$second
$shared
@@ -467,15 +414,9 @@
$context
$name
- $a
- $alias
- $alias
- $b
- $headAlias
+ $inc
$inc
- $instance
$instance1
$instance1
$instance2
@@ -492,10 +433,6 @@
$inc
$instance->foo
- $instance->option
- $container
$container
diff --git a/src/Tool/ConstructorParameterResolver.php b/src/Tool/ConstructorParameterResolver.php
index 9e00fca7..3ce5500f 100644
--- a/src/Tool/ConstructorParameterResolver.php
+++ b/src/Tool/ConstructorParameterResolver.php
@@ -4,6 +4,7 @@
namespace Laminas\ServiceManager\Tool;
+use ArrayAccess;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Psr\Container\ContainerInterface;
use ReflectionClass;
@@ -13,6 +14,7 @@
use function array_map;
use function assert;
use function class_exists;
+use function in_array;
use function interface_exists;
use function sprintf;
@@ -25,7 +27,7 @@ final class ConstructorParameterResolver implements ConstructorParameterResolver
public function resolveConstructorParameters(
string $className,
ContainerInterface $container,
- array $aliases
+ array $aliases = []
): array {
$parameters = $this->resolveConstructorParameterServiceNamesOrFallbackTypes($className, $container, $aliases);
@@ -83,7 +85,10 @@ private function resolveParameterWithConfigService(
): FallbackConstructorParameter|ServiceFromContainerConstructorParameter {
if ($parameter->getName() === 'config') {
$type = $parameter->getType();
- if ($type instanceof ReflectionNamedType && $type->getName() === 'array') {
+ if (
+ $type instanceof ReflectionNamedType
+ && in_array($type->getName(), ['array', ArrayAccess::class], true)
+ ) {
return new ServiceFromContainerConstructorParameter('config');
}
}
@@ -108,10 +113,6 @@ private function resolveParameter(
$type = $parameter->getType();
$type = $type instanceof ReflectionNamedType ? $type->getName() : null;
- if ($type === 'array') {
- return new FallbackConstructorParameter([]);
- }
-
if ($type === null || (! class_exists($type) && ! interface_exists($type))) {
if (! $parameter->isDefaultValueAvailable()) {
throw new ServiceNotFoundException(sprintf(
@@ -150,7 +151,7 @@ private function resolveParameter(
public function resolveConstructorParameterServiceNamesOrFallbackTypes(
string $className,
ContainerInterface $container,
- array $aliases,
+ array $aliases = [],
): array {
$reflectionClass = new ReflectionClass($className);
diff --git a/src/Tool/ConstructorParameterResolverInterface.php b/src/Tool/ConstructorParameterResolverInterface.php
index 3e9f725b..7e34af7c 100644
--- a/src/Tool/ConstructorParameterResolverInterface.php
+++ b/src/Tool/ConstructorParameterResolverInterface.php
@@ -18,7 +18,7 @@ interface ConstructorParameterResolverInterface
public function resolveConstructorParameters(
string $className,
ContainerInterface $container,
- array $aliases,
+ array $aliases = [],
): array;
/**
@@ -32,6 +32,6 @@ public function resolveConstructorParameters(
public function resolveConstructorParameterServiceNamesOrFallbackTypes(
string $className,
ContainerInterface $container,
- array $aliases,
+ array $aliases = [],
): array;
}
diff --git a/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php b/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php
index a775e8a2..c77461e9 100644
--- a/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php
+++ b/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php
@@ -4,14 +4,15 @@
namespace LaminasTest\ServiceManager\AbstractFactory;
-use ArrayAccess;
use Laminas\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory;
-use Laminas\ServiceManager\Exception\ServiceNotFoundException;
+use Laminas\ServiceManager\Exception\ExceptionInterface;
+use Laminas\ServiceManager\Exception\InvalidArgumentException;
+use Laminas\ServiceManager\Tool\ConstructorParameterResolverInterface;
+use LaminasTest\ServiceManager\AbstractFactory\TestAsset\ClassWithConstructorAcceptingAnyArgument;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
-
-use function sprintf;
+use stdClass;
/**
* @covers \Laminas\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory
@@ -23,40 +24,41 @@ final class ReflectionBasedAbstractFactoryTest extends TestCase
private ReflectionBasedAbstractFactory $factory;
+ /** @var ConstructorParameterResolverInterface&MockObject */
+ private ConstructorParameterResolverInterface $constructorParameterResolver;
+
protected function setUp(): void
{
parent::setUp();
- $this->container = $this->createMock(ContainerInterface::class);
- $this->factory = new ReflectionBasedAbstractFactory();
+ $this->container = $this->createMock(ContainerInterface::class);
+ $this->constructorParameterResolver = $this->createMock(ConstructorParameterResolverInterface::class);
+ $this->factory = new ReflectionBasedAbstractFactory(
+ [],
+ $this->constructorParameterResolver
+ );
}
- public function nonClassRequestedNames(): array
+ /**
+ * @return arrayarray
enum_exists($service)
+ $config['service_manager']
@@ -422,8 +427,6 @@
$instance2
$instance2
$service
- $service
- $service
$serviceFromAlias
$serviceFromServiceNameAfterUsingAlias
@@ -442,6 +445,21 @@
$name
array<non-empty-string,array{string}>
+ WhateverEnum
+ WhateverEnum
+ case
+ $test
From 9035a2d89b12a549d28061b0a00feea684612f0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maximilian=20B=C3=B6sing?=
<2189546+boesing@users.noreply.github.com>
Date: Mon, 10 Apr 2023 00:31:46 +0200
Subject: [PATCH 31/32] qa: fix line-length coding-standard issue
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
---
test/Command/AheadOfTimeFactoryCreatorCommandTest.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/test/Command/AheadOfTimeFactoryCreatorCommandTest.php b/test/Command/AheadOfTimeFactoryCreatorCommandTest.php
index 2afed3f8..b5ce594c 100644
--- a/test/Command/AheadOfTimeFactoryCreatorCommandTest.php
+++ b/test/Command/AheadOfTimeFactoryCreatorCommandTest.php
@@ -285,7 +285,8 @@ public function testWillDetectAlreadyExistingFactories(): void
$this->assertErrorRaised(
'There is already an existing factory class registered for'
- . ' "LaminasTest\\ServiceManager\\TestAsset\\SimpleDependencyObject": LaminasTest\\ServiceManager\\TestAsset\\SimpleDependencyObjectFactory'
+ . ' "LaminasTest\\ServiceManager\\TestAsset\\SimpleDependencyObject":'
+ . ' LaminasTest\\ServiceManager\\TestAsset\\SimpleDependencyObjectFactory'
);
require $generatedFactoryAssetPath;
From 89976b0a8032ea43fe344fb633e677c4fb4c6375 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maximilian=20B=C3=B6sing?=
<2189546+boesing@users.noreply.github.com>
Date: Mon, 10 Apr 2023 00:32:49 +0200
Subject: [PATCH 32/32] docs: remove superfluous whitespace at the end of the
line
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
---
docs/book/v4/console-tools.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/docs/book/v4/console-tools.md b/docs/book/v4/console-tools.md
index 76689519..73a89f51 100644
--- a/docs/book/v4/console-tools.md
+++ b/docs/book/v4/console-tools.md
@@ -11,6 +11,7 @@ To run the console tools with `laminas-servicemanager` v4, the [`laminas/laminas
> ```shell
> $ composer require laminas/laminas-cli
> ```
+>
> _In case laminas-cli is only required to consume these console tools, you might consider using the `--dev` flag._
## Available Commands
@@ -99,4 +100,4 @@ Options:
This utility will generate factories in the same way as [servicemanager:generate-factory-for-class](#generate-factory-for-class). The main difference is, that it will scan the whole project configuration for the usage of `ReflectionBasedAbstractFactory` within **any** ServiceManager look-a-like configuration (i.e. explicit usage within `factories`) and auto-generates factories for all of these services **plus** creates a configuration file which overrides **all** ServiceManager look-a-like configurations so that these consume the generated factories.
-For more details and how to set up a project so that all factories are properly replaced, refer to the [dedicated command documentation](ahead-of-time-factories.md).
+For more details and how to set up a project so that all factories are properly replaced, refer to the [dedicated command documentation](ahead-of-time-factories.md).