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