1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ArpTest\LaminasFactory\TestDouble; |
6
|
|
|
|
7
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
8
|
|
|
use Psr\Container\ContainerInterface; |
9
|
|
|
|
10
|
|
|
class ServiceConfigStdClassFactory extends AbstractFactory |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array<mixed>|null |
14
|
|
|
*/ |
15
|
|
|
private ?array $applicationOptions; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array<mixed>|null |
19
|
|
|
*/ |
20
|
|
|
private ?array $serviceOptions; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param array<mixed>|null $factoryOptions |
24
|
|
|
* @param array<mixed>|null $applicationOptions |
25
|
|
|
* @param array<mixed>|null $serviceOptions |
26
|
|
|
*/ |
27
|
|
|
public function __construct( |
28
|
|
|
?array $factoryOptions = null, |
29
|
|
|
?array $applicationOptions = null, |
30
|
|
|
?array $serviceOptions = null |
31
|
|
|
) { |
32
|
|
|
$this->applicationOptions = $applicationOptions; |
33
|
|
|
$this->serviceOptions = $serviceOptions; |
34
|
|
|
|
35
|
|
|
parent::__construct($factoryOptions); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param ContainerInterface $container |
40
|
|
|
* @param string $requestedName |
41
|
|
|
* @param array<mixed>|null $options |
42
|
|
|
* |
43
|
|
|
* @return \stdClass |
44
|
|
|
*/ |
45
|
|
|
public function __invoke( |
46
|
|
|
ContainerInterface $container, |
47
|
|
|
string $requestedName, |
48
|
|
|
array $options = null |
49
|
|
|
): \stdClass { |
50
|
|
|
$options = $options ?? $this->getServiceOptions($container, $requestedName); |
51
|
|
|
|
52
|
|
|
$object = new \stdClass(); |
53
|
|
|
$object->options = $options; |
54
|
|
|
|
55
|
|
|
return $object; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param ContainerInterface $container |
60
|
|
|
* @param string|null $optionsKey |
61
|
|
|
* |
62
|
|
|
* @return array<mixed> |
63
|
|
|
*/ |
64
|
|
|
public function getApplicationOptions(ContainerInterface $container, ?string $optionsKey = null): array |
65
|
|
|
{ |
66
|
|
|
return $this->applicationOptions ?? parent::getApplicationOptions($container, $optionsKey); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param ContainerInterface $container The dependency injection container |
71
|
|
|
* @param string $requestedName The name of the service being created |
72
|
|
|
* @param string|null $key The type of service that should be checked |
73
|
|
|
* |
74
|
|
|
* @return array<mixed> |
75
|
|
|
*/ |
76
|
|
|
public function getServiceOptions(ContainerInterface $container, string $requestedName, ?string $key = null): array |
77
|
|
|
{ |
78
|
|
|
return $this->serviceOptions ?? parent::getServiceOptions($container, $requestedName, $key); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|