Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Plugin/Generator/GrpcGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function generateClient(Parser\ServiceDescriptor $service): PhpNamespace
)
->setReturnType('Client\ClientStreamChannel')
->addComment("{$phpdocPrefix}@return Client\\ClientStreamChannel<{$in->fqcn}, {$out->fqcn}>");
} elseif (!$method->clientStreaming && $method->serverStreaming) {
} elseif (!$method->clientStreaming) {
$classMethod
->setBody(
<<<'PHP'
Expand Down Expand Up @@ -281,7 +281,7 @@ public function generateServer(Parser\ServiceDescriptor $service): PhpNamespace
])
->setReturnType($out->fqcn)
->addComment("{$phpdocPrefix}@param Server\\ClientStreamChannel<{$in->fqcn}, {$out->fqcn}> \$stream");
} elseif (!$method->clientStreaming && $method->serverStreaming) {
} elseif (!$method->clientStreaming) {
$interfaceMethod
->setParameters([
new Parameter('request')->setType($in->fqcn),
Expand Down Expand Up @@ -357,7 +357,7 @@ public function generateServerRegistry(Parser\ServiceDescriptor $service): PhpNa
PHP,
$args,
);
} elseif (!$method->clientStreaming && $method->serverStreaming) {
} elseif (!$method->clientStreaming) {
$handlers[] = new Literal(
<<<'PHP'
new Server\Rpc(
Expand Down
16 changes: 8 additions & 8 deletions src/Plugin/Generator/TypeDeclarationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,33 @@ public function create(Parser\FieldDescriptor $field): TypeDeclaration
}),
default: 0,
),
Type::TYPE_INT64,
Type::TYPE_UINT64,
Type::TYPE_FIXED64,
Type::TYPE_SFIXED64,
Type::TYPE_SINT64 => new TypeDeclaration(
Type::TYPE_FIXED64 => new TypeDeclaration(
phpType: '\BcMath\Number',
reflectionType: new Literal(match ($type) {
Type::TYPE_INT64 => 'Reflection\Int64T::T',
Type::TYPE_UINT64 => 'Reflection\Uint64T::T',
Type::TYPE_FIXED64 => 'Reflection\Fixed64T::T',
Type::TYPE_SFIXED64 => 'Reflection\SFixed64T::T',
Type::TYPE_SINT64 => 'Reflection\SInt64T::T',
}),
default: Literal::new('\BcMath\Number', [0]),
),
Type::TYPE_INT32,
Type::TYPE_UINT32,
Type::TYPE_FIXED32,
Type::TYPE_SFIXED32,
Type::TYPE_SINT32 => new TypeDeclaration(
Type::TYPE_SINT32,
Type::TYPE_INT64,
Type::TYPE_SFIXED64,
Type::TYPE_SINT64 => new TypeDeclaration(
phpType: 'int',
reflectionType: new Literal(match ($type) {
Type::TYPE_INT32 => 'Reflection\Int32T::T',
Type::TYPE_FIXED32 => 'Reflection\Fixed32T::T',
Type::TYPE_UINT32 => 'Reflection\Uint32T::T',
Type::TYPE_SFIXED32 => 'Reflection\SFixed32T::T',
Type::TYPE_SINT32 => 'Reflection\SInt32T::T',
Type::TYPE_INT64 => 'Reflection\Int64T::T',
Type::TYPE_SFIXED64 => 'Reflection\SFixed64T::T',
Type::TYPE_SINT64 => 'Reflection\SInt64T::T',
}),
default: 0,
),
Expand Down
26 changes: 26 additions & 0 deletions tests/fixtures/proto3_scalars/proto3_scalars.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";

package proto3.scalars.v1;

// Exercises the PHP type mapping of 64-bit scalar fields under proto3:
// the signed types (int64, sint64, sfixed64) map to native `int`, while the
// unsigned 64-bit types (uint64, fixed64) stay `\BcMath\Number`.
message Scalars {
int64 int64_singular = 1;
sint64 sint64_singular = 2;
sfixed64 sfixed64_singular = 3;
uint64 uint64_singular = 4;
fixed64 fixed64_singular = 5;

optional int64 int64_optional = 11;
optional sint64 sint64_optional = 12;
optional sfixed64 sfixed64_optional = 13;
optional uint64 uint64_optional = 14;
optional fixed64 fixed64_optional = 15;

repeated int64 int64_repeated = 21;
repeated sint64 sint64_repeated = 22;
repeated sfixed64 sfixed64_repeated = 23;
repeated uint64 uint64_repeated = 24;
repeated fixed64 fixed64_repeated = 25;
}
30 changes: 15 additions & 15 deletions tests/snapshots/proto2/Proto/Api/V1/TestRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @param bool $boolRequired another field comment.
* @param list<bool> $boolRepeated
* @param list<int> $int32Repeated
* @param list<\BcMath\Number> $int64Repeated
* @param list<int> $int64Repeated
* @param list<int> $fixed32Repeated
* @param list<\BcMath\Number> $fixed64Repeated
* @param list<int> $uint32Repeated
Expand All @@ -37,22 +37,22 @@
* @param list<string> $stringRepeated
* @param list<string> $bytesRepeated
* @param list<int> $sint32Repeated
* @param list<\BcMath\Number> $sint64Repeated
* @param list<int> $sint64Repeated
* @param list<int> $sfixed32Repeated
* @param list<\BcMath\Number> $sfixed64Repeated
* @param list<int> $sfixed64Repeated
* @param list<bool> $boolRepeatedPacked
* @param list<int> $int32RepeatedPacked
* @param list<\BcMath\Number> $int64RepeatedPacked
* @param list<int> $int64RepeatedPacked
* @param list<int> $fixed32RepeatedPacked
* @param list<\BcMath\Number> $fixed64RepeatedPacked
* @param list<int> $uint32RepeatedPacked
* @param list<\BcMath\Number> $uint64RepeatedPacked
* @param list<float> $floatRepeatedPacked
* @param list<float> $doubleRepeatedPacked
* @param list<int> $sint32RepeatedPacked
* @param list<\BcMath\Number> $sint64RepeatedPacked
* @param list<int> $sint64RepeatedPacked
* @param list<int> $sfixed32RepeatedPacked
* @param list<\BcMath\Number> $sfixed64RepeatedPacked
* @param list<int> $sfixed64RepeatedPacked
* @param Protobuf\Map<string, string> $mapStringString
* @param ?string $lastField Maximum possible tag number.
*/
Expand All @@ -64,7 +64,7 @@ public function __construct(
#[Reflection\Field(11, Reflection\Int32T::T)]
public int $int32Required,
#[Reflection\Field(12, Reflection\Int64T::T)]
public \BcMath\Number $int64Required,
public int $int64Required,
#[Reflection\Field(13, Reflection\Fixed32T::T)]
public int $fixed32Required,
#[Reflection\Field(14, Reflection\Fixed64T::T)]
Expand All @@ -84,17 +84,17 @@ public function __construct(
#[Reflection\Field(102, Reflection\SInt32T::T)]
public int $sint32Required,
#[Reflection\Field(103, Reflection\SInt64T::T)]
public \BcMath\Number $sint64Required,
public int $sint64Required,
#[Reflection\Field(104, Reflection\SFixed32T::T)]
public int $sfixed32Required,
#[Reflection\Field(105, Reflection\SFixed64T::T)]
public \BcMath\Number $sfixed64Required,
public int $sfixed64Required,
#[Reflection\Field(30, Reflection\BoolT::T)]
public ?bool $boolOptional = null,
#[Reflection\Field(31, Reflection\Int32T::T)]
public ?int $int32Optional = null,
#[Reflection\Field(32, Reflection\Int64T::T)]
public ?\BcMath\Number $int64Optional = null,
public ?int $int64Optional = null,
#[Reflection\Field(33, Reflection\Fixed32T::T)]
public ?int $fixed32Optional = null,
#[Reflection\Field(34, Reflection\Fixed64T::T)]
Expand All @@ -114,11 +114,11 @@ public function __construct(
#[Reflection\Field(302, Reflection\SInt32T::T)]
public ?int $sint32Optional = null,
#[Reflection\Field(303, Reflection\SInt64T::T)]
public ?\BcMath\Number $sint64Optional = null,
public ?int $sint64Optional = null,
#[Reflection\Field(304, Reflection\SFixed32T::T)]
public ?int $sfixed32Optional = null,
#[Reflection\Field(305, Reflection\SFixed64T::T)]
public ?\BcMath\Number $sfixed64Optional = null,
public ?int $sfixed64Optional = null,
#[Reflection\Field(20, new Reflection\ListT(Reflection\BoolT::T, false))]
public array $boolRepeated = [],
#[Reflection\Field(21, new Reflection\ListT(Reflection\Int32T::T, false))]
Expand Down Expand Up @@ -180,7 +180,7 @@ public function __construct(
#[Reflection\Field(41, Reflection\Int32T::T)]
public ?int $int32Defaulted = null,
#[Reflection\Field(42, Reflection\Int64T::T)]
public ?\BcMath\Number $int64Defaulted = null,
public ?int $int64Defaulted = null,
#[Reflection\Field(43, Reflection\Fixed32T::T)]
public ?int $fixed32Defaulted = null,
#[Reflection\Field(44, Reflection\Fixed64T::T)]
Expand All @@ -200,11 +200,11 @@ public function __construct(
#[Reflection\Field(402, Reflection\SInt32T::T)]
public ?int $sint32Defaulted = null,
#[Reflection\Field(403, Reflection\SInt64T::T)]
public ?\BcMath\Number $sint64Defaulted = null,
public ?int $sint64Defaulted = null,
#[Reflection\Field(404, Reflection\SFixed32T::T)]
public ?int $sfixed32Defaulted = null,
#[Reflection\Field(405, Reflection\SFixed64T::T)]
public ?\BcMath\Number $sfixed64Defaulted = null,
public ?int $sfixed64Defaulted = null,
#[Reflection\Field(406, new Reflection\MapT(Reflection\StringT::T, Reflection\StringT::T))]
public Protobuf\Map $mapStringString = new Protobuf\Map(),
#[Reflection\Field(407, new Reflection\ObjectT(\Google\Protobuf\Timestamp::class))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: proto3_scalars.proto
*/

declare(strict_types=1);

namespace Proto3\Scalars\V1;

use Override;
use Thesis\Protobuf\Registry;
use Thesis\Protobuf\Registry\File;

/**
* @api
*/
final readonly class Proto3ScalarsDescriptorRegistry implements Registry\Registrar
{
private const string DESCRIPTOR_BUFFER = 'ChRwcm90bzNfc2NhbGFycy5wcm90bxIRcHJvdG8zLnNjYWxhcnMudjEi+wUKB1NjYWxhcnMSJQoOaW50NjRfc2luZ3VsYXIYASABKANSDWludDY0U2luZ3VsYXISJwoPc2ludDY0X3Npbmd1bGFyGAIgASgSUg5zaW50NjRTaW5ndWxhchIrChFzZml4ZWQ2NF9zaW5ndWxhchgDIAEoEFIQc2ZpeGVkNjRTaW5ndWxhchInCg91aW50NjRfc2luZ3VsYXIYBCABKARSDnVpbnQ2NFNpbmd1bGFyEikKEGZpeGVkNjRfc2luZ3VsYXIYBSABKAZSD2ZpeGVkNjRTaW5ndWxhchIqCg5pbnQ2NF9vcHRpb25hbBgLIAEoA0gAUg1pbnQ2NE9wdGlvbmFsiAEBEiwKD3NpbnQ2NF9vcHRpb25hbBgMIAEoEkgBUg5zaW50NjRPcHRpb25hbI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ESAxcUIwoMCgUEAAINAxIDFyYoCgsKBAQAAg4SAxgEKwoMCgUEAAIOBBIDGAQMCgwKBQQAAg4FEgMYDRQKDAoFBAACDgESAxgVJQoMCgUEAAIOAxIDGCgqYgZwcm90bzM=';

#[Override]
public function register(Registry\Pool $pool): void
{
$pool->add(Registry\Descriptor::base64(self::DESCRIPTOR_BUFFER), new File(
name: 'proto3_scalars.proto',
messages: [
new File\MessageDescriptor('proto3.scalars.v1.Scalars', \Proto3\Scalars\V1\Scalars::class),
],
));
}
}
65 changes: 65 additions & 0 deletions tests/snapshots/proto3_scalars/Proto3/Scalars/V1/Scalars.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: proto3_scalars.proto
*/

declare(strict_types=1);

namespace Proto3\Scalars\V1;

use Thesis\Protobuf\Reflection;

/**
* @api
*
* Exercises the PHP type mapping of 64-bit scalar fields under proto3:
* the signed types (int64, sint64, sfixed64) map to native `int`, while the
* unsigned 64-bit types (uint64, fixed64) stay `\BcMath\Number`.
*/
final readonly class Scalars
{
/**
* @param list<int> $int64Repeated
* @param list<int> $sint64Repeated
* @param list<int> $sfixed64Repeated
* @param list<\BcMath\Number> $uint64Repeated
* @param list<\BcMath\Number> $fixed64Repeated
*/
public function __construct(
#[Reflection\Field(1, Reflection\Int64T::T)]
public int $int64Singular = 0,
#[Reflection\Field(2, Reflection\SInt64T::T)]
public int $sint64Singular = 0,
#[Reflection\Field(3, Reflection\SFixed64T::T)]
public int $sfixed64Singular = 0,
#[Reflection\Field(4, Reflection\Uint64T::T)]
public \BcMath\Number $uint64Singular = new \BcMath\Number(0),
#[Reflection\Field(5, Reflection\Fixed64T::T)]
public \BcMath\Number $fixed64Singular = new \BcMath\Number(0),
#[Reflection\Field(11, Reflection\Int64T::T)]
public ?int $int64Optional = null,
#[Reflection\Field(12, Reflection\SInt64T::T)]
public ?int $sint64Optional = null,
#[Reflection\Field(13, Reflection\SFixed64T::T)]
public ?int $sfixed64Optional = null,
#[Reflection\Field(14, Reflection\Uint64T::T)]
public ?\BcMath\Number $uint64Optional = null,
#[Reflection\Field(15, Reflection\Fixed64T::T)]
public ?\BcMath\Number $fixed64Optional = null,
#[Reflection\Field(21, new Reflection\ListT(Reflection\Int64T::T))]
public array $int64Repeated = [],
#[Reflection\Field(22, new Reflection\ListT(Reflection\SInt64T::T))]
public array $sint64Repeated = [],
#[Reflection\Field(23, new Reflection\ListT(Reflection\SFixed64T::T))]
public array $sfixed64Repeated = [],
#[Reflection\Field(24, new Reflection\ListT(Reflection\Uint64T::T))]
public array $uint64Repeated = [],
#[Reflection\Field(25, new Reflection\ListT(Reflection\Fixed64T::T))]
public array $fixed64Repeated = [],
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
*/

declare(strict_types=1);

\Thesis\Protobuf\Registry\Pool::get()->register(
new \Thesis\Protobuf\Registry\OnceRegistrar(new \Proto3\Scalars\V1\Proto3ScalarsDescriptorRegistry()),
);