Repository navigation
Expand file tree
/
Copy pathOption.php
More file actions
90 lines (74 loc) · 2.27 KB
/
Copy pathOption.php
File metadata and controls
90 lines (74 loc) · 2.27 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
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Server;
use Hyperf\HttpServer\PriorityMiddleware;
use function Hyperf\Tappable\tap;
class Option
{
/**
* Send Channel Capacity, Only support multiplex server mode.
*/
protected int $sendChannelCapacity = 0;
/**
* Whether to enable request lifecycle event.
*/
protected bool $enableRequestLifecycle = false;
/**
* Whether to sort middlewares by priority.
*/
protected bool $mustSortMiddlewares = false;
public static function make(array|Option $options): Option
{
if ($options instanceof Option) {
return $options;
}
return tap(new self(), function (Option $option) use ($options) {
$option->setSendChannelCapacity($options['send_channel_capacity'] ?? 0);
$option->setEnableRequestLifecycle($options['enable_request_lifecycle'] ?? false);
});
}
public function getSendChannelCapacity(): int
{
return $this->sendChannelCapacity;
}
public function setSendChannelCapacity(int $sendChannelCapacity): static
{
$this->sendChannelCapacity = $sendChannelCapacity;
return $this;
}
public function isEnableRequestLifecycle(): bool
{
return $this->enableRequestLifecycle;
}
public function setEnableRequestLifecycle(bool $enableRequestLifecycle): static
{
$this->enableRequestLifecycle = $enableRequestLifecycle;
return $this;
}
public function isMustSortMiddlewares(): bool
{
return $this->mustSortMiddlewares;
}
public function setMustSortMiddlewares(bool $mustSortMiddlewares): static
{
$this->mustSortMiddlewares = $mustSortMiddlewares;
return $this;
}
public function setMustSortMiddlewaresByMiddlewares(array $middlewares): static
{
foreach ($middlewares as $middleware) {
if (is_int($middleware) || $middleware instanceof PriorityMiddleware) {
return $this->setMustSortMiddlewares(true);
}
}
return $this;
}
}