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

31 lines
716 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-27 19:32:52 +02:00
final class Client {
private static ?string $id = null;
2023-08-27 20:25:28 +02:00
public static function init(): void {
2023-08-27 19:32:52 +02:00
if (self::$id !== null) {
return;
}
2023-08-27 20:25:28 +02:00
$f = fopen("php://fd/".\Client::init(), 'r+');
2023-08-27 19:32:52 +02:00
stream_set_blocking($f, false);
2023-08-27 20:25:28 +02:00
self::$id = EventLoop::onReadable($f, fn () => \Client::wakeup());
2023-08-27 19:32:52 +02:00
}
public static function reference(): void{
EventLoop::reference(self::$id);
}
public static function unreference(): void {
EventLoop::unreference(self::$id);
}
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
}
}