1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GacelaTest\Benchmark\Framework\ClassResolver\AnonymousGlobal; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\AbstractConfig; |
8
|
|
|
use Gacela\Framework\AbstractDependencyProvider; |
9
|
|
|
use Gacela\Framework\AbstractFacade; |
10
|
|
|
use Gacela\Framework\AbstractFactory; |
11
|
|
|
use Gacela\Framework\ClassResolver\GlobalInstance\AnonymousGlobal; |
12
|
|
|
use Gacela\Framework\Container\Container; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @BeforeMethods("setUp") |
16
|
|
|
*/ |
17
|
|
|
final class AnonymousGlobalsBench |
18
|
|
|
{ |
19
|
|
|
private AbstractFacade $facade; |
20
|
|
|
|
21
|
|
|
public function setUp(): void |
22
|
|
|
{ |
23
|
|
|
$this->abstractConfig(); |
24
|
|
|
$this->abstractDependencyProvider(); |
25
|
|
|
$this->abstractFactory(); |
26
|
|
|
$this->abstractFacade(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function bench_class_resolving(): void |
30
|
|
|
{ |
31
|
|
|
$this->facade->getConfigValues(); |
|
|
|
|
32
|
|
|
$this->facade->getValueFromDependencyProvider(); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function abstractConfig(): void |
36
|
|
|
{ |
37
|
|
|
AnonymousGlobal::addGlobal( |
38
|
|
|
$this, |
39
|
|
|
new class() extends AbstractConfig { |
40
|
|
|
public function getValues(): array |
41
|
|
|
{ |
42
|
|
|
return ['1', 2, [3]]; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function abstractDependencyProvider(): void |
49
|
|
|
{ |
50
|
|
|
AnonymousGlobal::addGlobal( |
51
|
|
|
$this, |
52
|
|
|
new class() extends AbstractDependencyProvider { |
53
|
|
|
public function provideModuleDependencies(Container $container): void |
54
|
|
|
{ |
55
|
|
|
$container->set('key', 'value'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function abstractFactory(): void |
62
|
|
|
{ |
63
|
|
|
AnonymousGlobal::addGlobal( |
64
|
|
|
$this, |
65
|
|
|
new class() extends AbstractFactory { |
66
|
|
|
public function createDomainClass(): object |
67
|
|
|
{ |
68
|
|
|
/** @var array $configValues */ |
69
|
|
|
$configValues = $this->getConfig()->getValues(); |
70
|
|
|
|
71
|
|
|
/** @var string $valueFromDependencyProvider */ |
72
|
|
|
$valueFromDependencyProvider = $this->getProvidedDependency('key'); |
73
|
|
|
|
74
|
|
|
return new class($configValues, $valueFromDependencyProvider) { |
75
|
|
|
private array $configValues; |
76
|
|
|
private string $valueFromDependencyProvider; |
77
|
|
|
|
78
|
|
|
public function __construct( |
79
|
|
|
array $configValues, |
80
|
|
|
string $valueFromDependencyProvider |
81
|
|
|
) { |
82
|
|
|
$this->configValues = $configValues; |
83
|
|
|
$this->valueFromDependencyProvider = $valueFromDependencyProvider; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getConfigValues(): array |
87
|
|
|
{ |
88
|
|
|
return $this->configValues; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getValueFromDependencyProvider(): string |
92
|
|
|
{ |
93
|
|
|
return $this->valueFromDependencyProvider; |
94
|
|
|
} |
95
|
|
|
}; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function abstractFacade(): void |
102
|
|
|
{ |
103
|
|
|
$this->facade = new class() extends AbstractFacade { |
104
|
|
|
public function getConfigValues(): array |
105
|
|
|
{ |
106
|
|
|
return $this->getFactory() |
107
|
|
|
->createDomainClass() |
108
|
|
|
->getConfigValues(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getValueFromDependencyProvider(): string |
112
|
|
|
{ |
113
|
|
|
return $this->getFactory() |
114
|
|
|
->createDomainClass() |
115
|
|
|
->getValueFromDependencyProvider(); |
116
|
|
|
} |
117
|
|
|
}; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|