1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Spiral Framework. |
5
|
|
|
* |
6
|
|
|
* @license MIT |
7
|
|
|
* @author Anton Titov (Wolfy-J) |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Spiral\Bootloader\Http; |
13
|
|
|
|
14
|
|
|
use Composer\InstalledVersions; |
15
|
|
|
use Psr\Container\ContainerInterface; |
16
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
17
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
18
|
|
|
use Spiral\Boot\AbstractKernel; |
19
|
|
|
use Spiral\Boot\Bootloader\Bootloader; |
20
|
|
|
use Spiral\Boot\KernelInterface; |
21
|
|
|
use Spiral\Bootloader\ServerBootloader; |
22
|
|
|
use Spiral\Config\ConfiguratorInterface; |
23
|
|
|
use Spiral\Config\Patch\Append; |
24
|
|
|
use Spiral\Core\Container\SingletonInterface; |
25
|
|
|
use Spiral\Core\FactoryInterface; |
26
|
|
|
use Spiral\Http\Config\HttpConfig; |
27
|
|
|
use Spiral\Http\Emitter\SapiEmitter; |
28
|
|
|
use Spiral\Http\EmitterInterface; |
29
|
|
|
use Spiral\Http\Http; |
30
|
|
|
use Spiral\Http\LegacyRrDispatcher; |
31
|
|
|
use Spiral\Http\Pipeline; |
32
|
|
|
use Spiral\Http\RrDispatcher; |
33
|
|
|
use Spiral\Http\SapiDispatcher; |
34
|
|
|
use Spiral\RoadRunner\Http\PSR7Worker; |
|
|
|
|
35
|
|
|
use Spiral\RoadRunner\PSR7Client; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Configures Http dispatcher in SAPI and RoadRunner modes (if available). |
39
|
|
|
*/ |
40
|
|
|
final class HttpBootloader extends Bootloader implements SingletonInterface |
41
|
|
|
{ |
42
|
|
|
protected const DEPENDENCIES = [ |
43
|
|
|
ServerBootloader::class, |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
protected const SINGLETONS = [ |
47
|
|
|
Http::class => [self::class, 'httpCore'], |
48
|
|
|
EmitterInterface::class => [self::class, 'createEmitter'], |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** @var ConfiguratorInterface */ |
52
|
|
|
private $config; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param ConfiguratorInterface $config |
56
|
|
|
*/ |
57
|
200 |
|
public function __construct(ConfiguratorInterface $config) |
58
|
|
|
{ |
59
|
200 |
|
$this->config = $config; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param KernelInterface $kernel |
64
|
|
|
* @param FactoryInterface $factory |
65
|
|
|
*/ |
66
|
198 |
|
public function boot(AbstractKernel $kernel, FactoryInterface $factory): void |
67
|
|
|
{ |
68
|
198 |
|
$this->config->setDefaults( |
69
|
|
|
HttpConfig::CONFIG, |
70
|
|
|
[ |
71
|
198 |
|
'basePath' => '/', |
72
|
|
|
'headers' => [ |
73
|
|
|
'Content-Type' => 'text/html; charset=UTF-8', |
74
|
|
|
], |
75
|
|
|
'middleware' => [], |
76
|
|
|
'chunkSize' => null, |
77
|
|
|
] |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
// Lowest priority |
81
|
198 |
|
$kernel->started(static function (AbstractKernel $kernel) use ($factory): void { |
82
|
198 |
|
$kernel->addDispatcher($factory->make(SapiDispatcher::class)); |
|
|
|
|
83
|
|
|
}); |
84
|
|
|
|
85
|
198 |
|
if (!class_exists('Spiral\RoadRunnerBridge\Http\Dispatcher')) { |
86
|
198 |
|
if (class_exists(PSR7Client::class)) { |
87
|
198 |
|
$kernel->addDispatcher($factory->make(LegacyRrDispatcher::class)); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
198 |
|
if (class_exists(PSR7Worker::class)) { |
91
|
|
|
$kernel->addDispatcher($factory->make(RrDispatcher::class)); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Register new http middleware. |
98
|
|
|
* |
99
|
|
|
* @param mixed $middleware |
100
|
|
|
*/ |
101
|
192 |
|
public function addMiddleware($middleware): void |
102
|
|
|
{ |
103
|
192 |
|
$this->config->modify('http', new Append('middleware', null, $middleware)); |
104
|
|
|
} |
105
|
|
|
|
106
|
2 |
|
public function createEmitter(HttpConfig $config): EmitterInterface |
107
|
|
|
{ |
108
|
2 |
|
$emitter = new SapiEmitter(); |
109
|
|
|
|
110
|
2 |
|
if (($chunkSize = $config->getChunkSize()) !== null) { |
111
|
1 |
|
$emitter->bufferSize = $chunkSize; |
112
|
|
|
} |
113
|
|
|
|
114
|
2 |
|
return $emitter; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param HttpConfig $config |
119
|
|
|
* @param Pipeline $pipeline |
120
|
|
|
* @param RequestHandlerInterface $handler |
121
|
|
|
* @param ResponseFactoryInterface $responseFactory |
122
|
|
|
* @param ContainerInterface $container |
123
|
|
|
* @return Http |
124
|
|
|
*/ |
125
|
74 |
|
protected function httpCore( |
126
|
|
|
HttpConfig $config, |
127
|
|
|
Pipeline $pipeline, |
128
|
|
|
RequestHandlerInterface $handler, |
129
|
|
|
ResponseFactoryInterface $responseFactory, |
130
|
|
|
ContainerInterface $container |
131
|
|
|
): Http { |
132
|
74 |
|
$core = new Http($config, $pipeline, $responseFactory, $container); |
133
|
74 |
|
$core->setHandler($handler); |
134
|
|
|
|
135
|
74 |
|
return $core; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths