php-tokio/examples/reqwest/lib/Client.php

36 lines
730 B
PHP
Raw Normal View History

2023-08-27 19:32:52 +02:00
<?php
namespace Reqwest;
2023-08-27 20:25:28 +02:00
use Revolt\EventLoop;
2023-08-29 15:13:04 +02:00
final class Client
{
2023-08-27 19:32:52 +02:00
private static ?string $id = null;
2023-08-29 15:13:04 +02:00
public static function init(): void
{
2023-08-27 19:32:52 +02:00
if (self::$id !== null) {
return;
}
2023-08-29 15:13:04 +02:00
$f = fopen("php://fd/" . \Client::init(), "r+");
2023-08-27 19:32:52 +02:00
stream_set_blocking($f, false);
2023-08-29 15:13:04 +02:00
self::$id = EventLoop::onReadable($f, fn() => \Client::wakeup());
2023-08-27 19:32:52 +02:00
}
2023-08-29 15:13:04 +02:00
public static function reference(): void
{
2023-08-27 19:32:52 +02:00
EventLoop::reference(self::$id);
}
2023-08-29 15:13:04 +02:00
public static function unreference(): void
{
2023-08-27 19:32:52 +02:00
EventLoop::unreference(self::$id);
}
2023-08-29 15:13:04 +02:00
public static function __callStatic(string $name, array $args): mixed
{
2023-08-27 20:25:28 +02:00
return \Client::$name(...$args);
2023-08-27 19:32:52 +02:00
}
}