-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStreamFactories.php
More file actions
183 lines (148 loc) · 6.12 KB
/
StreamFactories.php
File metadata and controls
183 lines (148 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
declare(strict_types=1);
namespace PsrDiscovery\Implementations\Psr17;
use Psr\Http\Message\StreamFactoryInterface;
use PsrDiscovery\Collections\CandidatesCollection;
use PsrDiscovery\Contracts\Implementations\Psr17\StreamFactoriesContract;
use PsrDiscovery\Discover;
use PsrDiscovery\Entities\CandidateEntity;
use PsrDiscovery\Implementations\Implementation;
final class StreamFactories extends Implementation implements StreamFactoriesContract
{
private static ?CandidatesCollection $candidates = null;
private static ?CandidatesCollection $extendedCandidates = null;
private static ?StreamFactoryInterface $singleton = null;
private static ?StreamFactoryInterface $using = null;
public static function add(CandidateEntity $candidate): void
{
self::$candidates ??= CandidatesCollection::create();
parent::add($candidate);
self::use(null);
}
/**
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
*/
public static function allCandidates(): CandidatesCollection
{
if (self::$extendedCandidates instanceof CandidatesCollection) {
return self::$extendedCandidates;
}
self::$extendedCandidates = CandidatesCollection::create();
self::$extendedCandidates->set(self::candidates());
return self::$extendedCandidates;
}
/**
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
*/
public static function candidates(): CandidatesCollection
{
if (self::$candidates instanceof CandidatesCollection) {
return self::$candidates;
}
self::$candidates = CandidatesCollection::create();
self::$candidates->add(CandidateEntity::create(
package: 'psr-mock/http-factory-implementation',
version: '^1.0',
builder: static fn (string $class = '\PsrMock\Psr17\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'guzzlehttp/psr7',
version: '^2.0',
builder: static fn (string $class = '\GuzzleHttp\Psr7\HttpFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'nyholm/psr7',
version: '^0.2.2',
builder: static fn (string $class = '\Nyholm\Psr7\Factory\MessageFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'nyholm/psr7',
version: '^1.0',
builder: static fn (string $class = '\Nyholm\Psr7\Factory\Psr17Factory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'http-interop/http-factory-guzzle',
version: '^0.2 | ^1.0',
builder: static fn (string $class = '\Http\Factory\Guzzle\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'zendframework/zend-diactoros',
version: '^2.0',
builder: static fn (string $class = '\Zend\Diactoros\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'laminas/laminas-diactoros',
version: '^2.0',
builder: static fn (string $class = '\Laminas\Diactoros\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'slim/psr7',
version: '^1.0',
builder: static fn (string $class = '\Slim\Psr7\Factory\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'typo3/core',
version: '^10.1 | ^11.0 | ^12.0',
builder: static fn (string $class = '\TYPO3\CMS\Core\Http\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'nimbly/capsule',
version: '^2.0',
builder: static fn (string $class = '\Nimbly\Capsule\Factory\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'tuupola/http-factory',
version: '^1.0.2',
builder: static fn (string $class = '\Tuupola\Http\Factory\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'httpsoft/http-message',
version: '^1.0.4',
builder: static fn (string $class = '\HttpSoft\Message\StreamFactory'): object => new $class(),
));
self::$candidates->add(CandidateEntity::create(
package: 'art4/requests-psr18-adapter',
version: '^1.3',
builder: static fn (string $class = '\Art4\Requests\Psr\HttpClient'): object => new $class(),
));
return self::$candidates;
}
/**
* @psalm-suppress MoreSpecificReturnType,LessSpecificReturnStatement
*/
public static function discover(): ?StreamFactoryInterface
{
if (self::$using instanceof StreamFactoryInterface) {
return self::$using;
}
return Discover::httpStreamFactory();
}
public static function discoveries(): array
{
return Discover::httpStreamFactories();
}
public static function prefer(string $package): void
{
self::$candidates ??= CandidatesCollection::create();
parent::prefer($package);
self::use(null);
}
public static function set(CandidatesCollection $candidates): void
{
self::$candidates ??= CandidatesCollection::create();
parent::set($candidates);
self::use(null);
}
public static function singleton(): ?StreamFactoryInterface
{
if (self::$using instanceof StreamFactoryInterface) {
return self::$using;
}
return self::$singleton ??= self::discover();
}
public static function use(?StreamFactoryInterface $instance): void
{
self::$singleton = $instance;
self::$using = $instance;
}
}