1. Go to this page and download the library: Download thesis/protoc-plugin library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thesis / protoc-plugin example snippets
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.2
* protoc — v6.32.1
* Source: protos/request.proto
*/
declare(strict_types=1);
namespace Thesis\Api;
use Thesis\Protobuf\Reflection;
/**
* @api
*/
final readonly class Request
{
public function __construct(
#[Reflection\Field(1, Reflection\StringT::T)]
public string $id = '',
) {}
}
$pool->add(Registry\Descriptor::base64(self::TIMESTAMP_DESCRIPTOR_BUFFER), new File(
name: 'google/protobuf/timestamp.proto',
messages: [
new File\MessageDescriptor('google.protobuf.Timestamp', \Thesis\Google\Protobuf\Timestamp::class),
],
));
final readonly class Request
{
/**
* @param list<int> $ids
*/
public function __construct(
#[Reflection\Field(1, new Reflection\ListT(Reflection\Int32T::T, true))]
public array $ids = [],
) {}
}
use Thesis\Protobuf;
use Thesis\Protobuf\Reflection;
final readonly class Request
{
/**
* @param Protobuf\Map<string, string> $options
*/
public function __construct(
#[Reflection\Field(1, new Reflection\MapT(Reflection\StringT::T, Reflection\StringT::T))]
public Protobuf\Map $options = new Protobuf\Map(),
) {}
}
namespace Thesis\Api\Request;
final readonly class Request
{
public function __construct(
#[Reflection\OneOf([
\Thesis\Api\Request\ContactPhone::class,
\Thesis\Api\Request\ContactEmail::class,
\Thesis\Api\Request\ContactChatId::class,
])]
public ?\Thesis\Api\Request\Contact $contact = null,
) {}
}
namespace Thesis\Api\Request;
/**
* @api
*/
final readonly class ContactChatId implements \Thesis\Api\Request\Contact
{
public function __construct(
#[Reflection\Field(3, Reflection\Int64T::T)]
public \BcMath\Number $chatId = new \BcMath\Number(0),
) {}
}
/**
* @api
*/
final readonly class ContactEmail implements \Thesis\Api\Request\Contact
{
public function __construct(
#[Reflection\Field(2, Reflection\StringT::T)]
public string $email = '',
) {}
}
/**
* @api
*/
final readonly class ContactPhone implements \Thesis\Api\Request\Contact
{
public function __construct(
#[Reflection\Field(1, Reflection\StringT::T)]
public string $phone = '',
) {}
}
namespace Thesis\Api\V1;
use Amp\Cancellation;
use Amp\NullCancellation;
use Thesis\Grpc\Client;
use Thesis\Grpc\Exception\ClientStreamIsClosed;
use Thesis\Grpc\InvokeError;
use Thesis\Grpc\Metadata;
/**
* @api
*/
final readonly class QueueServiceClient
{
public function __construct(
private Client $client,
) {}
public function state(
\Google\Protobuf\Empty_ $request,
Metadata $md = new Metadata(),
Cancellation $cancellation = new NullCancellation(),
): \Thesis\Api\V1\Queue {}
/**
* @return Client\ClientStreamChannel<\Thesis\Api\V1\Message, \Google\Protobuf\Empty_>
*/
public function push(
Metadata $md = new Metadata(),
Cancellation $cancellation = new NullCancellation(),
): Client\ClientStreamChannel {}
/**
* @return Client\ServerStreamChannel<\Google\Protobuf\Empty_, \Thesis\Api\V1\Message>
*/
public function pull(
\Google\Protobuf\Empty_ $request,
Metadata $md = new Metadata(),
Cancellation $cancellation = new NullCancellation(),
): Client\ServerStreamChannel {}
/**
* @return Client\BidirectionalStreamChannel<\Thesis\Api\V1\Heartbeat, \Thesis\Api\V1\Heartbeat>
*/
public function heartbeats(
Metadata $md = new Metadata(),
Cancellation $cancellation = new NullCancellation(),
): Client\BidirectionalStreamChannel {}
}
namespace Thesis\Api\V1;
use Amp\Cancellation;
use Thesis\Grpc\Metadata;
use Thesis\Grpc\Server;
/**
* @api
*/
interface QueueServiceServer
{
public function state(
\Google\Protobuf\Empty_ $request,
Metadata $md,
Cancellation $cancellation,
): \Thesis\Api\V1\Queue;
/**
* @param Server\ClientStreamChannel<\Thesis\Api\V1\Message, \Google\Protobuf\Empty_> $stream
*/
public function push(
Server\ClientStreamChannel $stream,
Metadata $md,
Cancellation $cancellation,
): \Google\Protobuf\Empty_;
/**
* @return iterable<array-key, \Thesis\Api\V1\Message>
*/
public function pull(
\Google\Protobuf\Empty_ $request,
Metadata $md,
Cancellation $cancellation,
): iterable;
/**
* @param Server\BidirectionalStreamChannel<\Thesis\Api\V1\Heartbeat, \Thesis\Api\V1\Heartbeat> $stream
*/
public function heartbeats(
Server\BidirectionalStreamChannel $stream,
Metadata $md,
Cancellation $cancellation,
): void;
}
namespace Thesis\Api\V1;
use Override;
use Thesis\Grpc\Server;
/**
* @api
*/
final readonly class QueueServiceServerRegistry implements Server\ServiceRegistry
{
public function __construct(
private \Thesis\Api\V1\QueueServiceServer $server,
) {}
#[Override]
public function services(): iterable
{
yield new Server\Service('thesis.api.v1.QueueService', [
new Server\Rpc(
new Server\Handle('State', \Google\Protobuf\Empty_::class),
new Server\UnaryHandler($this->server->state(...)),
Server\RpcType::Unary,
),
new Server\Rpc(
new Server\Handle('Push', \Thesis\Api\V1\Message::class),
new Server\ClientStreamHandler($this->server->push(...)),
Server\RpcType::ClientStream,
),
new Server\Rpc(
new Server\Handle('Pull', \Google\Protobuf\Empty_::class),
new Server\ServerStreamHandler($this->server->pull(...)),
Server\RpcType::ServerStream,
),
new Server\Rpc(
new Server\Handle('Heartbeats', \Thesis\Api\V1\Heartbeat::class),
new Server\BidirectionalStreamHandler($this->server->heartbeats(...)),
Server\RpcType::BidirectionalStream,
),
]);
}
}