k911/swoole-bundle

View on GitHub
src/Server/Api/ApiServerClient.php

Summary

Maintainability
A
0 mins
Test Coverage
B
80%
<?php

declare(strict_types=1);

namespace K911\Swoole\Server\Api;

use K911\Swoole\Client\Http;
use K911\Swoole\Client\HttpClient;

final class ApiServerClient implements ApiServerInterface
{
    private $client;

    public function __construct(HttpClient $client)
    {
        $this->client = $client;
    }

    /**
     * Get Swoole HTTP Server status.
     */
    public function status(): array
    {
        return $this->client->send('/api/server')['response']['body'];
    }

    /**
     * Shutdown Swoole HTTP Server.
     */
    public function shutdown(): void
    {
        $this->client->send('/api/server', Http::METHOD_DELETE);
    }

    /**
     * Reload Swoole HTTP Server workers.
     */
    public function reload(): void
    {
        $this->client->send('/api/server', Http::METHOD_PATCH);
    }

    /**
     * Get Swoole HTTP Server metrics.
     */
    public function metrics(): array
    {
        return $this->client->send('/api/server/metrics')['response']['body'];
    }
}