本文整理汇总了PHP中Host::export方法的典型用法代码示例。如果您正苦于以下问题:PHP Host::export方法的具体用法?PHP Host::export怎么用?PHP Host::export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::export方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildVhost
private static function buildVhost(Host $host, callable $bootLoader) : Vhost
{
try {
$hostExport = $host->export();
$interfaces = $hostExport["interfaces"];
$name = $hostExport["name"];
$actions = $hostExport["actions"];
$middlewares = [];
$applications = [];
foreach ($actions as $key => $action) {
if ($action instanceof Bootable) {
$action = $bootLoader($action);
}
if ($action instanceof Middleware) {
$middlewares[] = [$action, "do"];
} elseif (is_array($action) && $action[0] instanceof Middleware) {
$middlewares[] = [$action[0], "do"];
}
if (is_callable($action)) {
$applications[] = $action;
}
}
if (empty($applications)) {
$application = function (Request $request, Response $response) {
$response->end("<html><body><h1>It works!</h1></body></html>");
};
} elseif (count($applications) === 1) {
$application = current($applications);
} else {
// Observe the Server in our stateful multi-responder so if a shutdown triggers
// while we're iterating over our coroutines we can send a 503 response. This
// obviates the need for applications to pay attention to server state themselves.
$application = $bootLoader(new class($applications) implements Bootable, ServerObserver
{
private $applications;
private $isStopping = false;
public function __construct(array $applications)
{
$this->applications = $applications;
}
public function boot(Server $server, Logger $logger)
{
$server->attach($this);
}
public function update(Server $server) : Promise
{
if ($server->state() === Server::STOPPING) {
$this->isStopping = true;
}
return new Success();
}
public function __invoke(Request $request, Response $response)
{
foreach ($this->applications as $action) {
$out = $action($request, $response);
if ($out instanceof \Generator) {
yield from $out;
}
if ($response->state() & Response::STARTED) {
return;
}
if ($this->isStopping) {
$response->setStatus(HTTP_STATUS["SERVICE_UNAVAILABLE"]);
$response->setReason("Server shutting down");
$response->setHeader("Aerys-Generic-Response", "enable");
$response->end();
return;
}
}
}
public function __debugInfo()
{
return ["applications" => $this->applications];
}
});
}
$vhost = new Vhost($name, $interfaces, $application, $middlewares);
if ($crypto = $hostExport["crypto"]) {
$vhost->setCrypto($crypto);
}
return $vhost;
} catch (\Throwable $previousException) {
throw new \DomainException("Failed building Vhost instance", $code = 0, $previousException);
}
}
示例2: buildVhost
private function buildVhost(Host $host, callable $bootLoader) : Vhost
{
try {
$hostExport = $host->export();
$address = $hostExport["address"];
$port = $hostExport["port"];
$name = $hostExport["name"];
$actions = $hostExport["actions"];
list($application, $middlewares) = $this->bootApplication($actions, $bootLoader);
$vhost = new Vhost($name, $address, $port, $application, $middlewares);
if ($crypto = $hostExport["crypto"]) {
$vhost->setCrypto($crypto);
}
return $vhost;
} catch (\Throwable $previousException) {
throw new \DomainException("Failed building Vhost instance", $code = 0, $previousException);
}
}