Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions protoc_plugins/protoc-gen-php-grpc/php/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ interface {{ .Service.Name | interface }} extends GRPC\ServiceInterface
// GRPC specific service name.
public const NAME = "{{ .File.Package }}.{{ .Service.Name }}";{{ "\n" }}
{{- range $m := .Service.Method}}
{{- $inName := name $ns $m.InputType }}
{{- $outName := name $ns $m.OutputType }}
/**
* @param GRPC\ContextInterface $ctx
* @param {{ name $ns $m.InputType }} $in
* @return {{ name $ns $m.OutputType }}
* @param {{ strip_slashes $inName }} $in
* @return {{ strip_slashes $outName }}
*
* @throws GRPC\Exception\InvokeException
*/
public function {{ $m.Name }}(GRPC\ContextInterface $ctx, {{ name $ns $m.InputType }} $in): {{ name $ns $m.OutputType }};
public function {{ $m.Name }}(GRPC\ContextInterface $ctx, {{ strip_slashes $inName }} $in): {{ strip_slashes $outName }};
{{end -}}
}
`
Expand Down Expand Up @@ -89,6 +91,9 @@ func body(req *plugin.CodeGeneratorRequest, file *desc.FileDescriptorProto, serv
"name": func(ns *ns, name *string) string {
return ns.resolve(name)
},
"strip_slashes": func(name string) string {
return strings.ReplaceAll(name, "\\\\", "\\")
},
}).Parse(phpBody))

err := tpl.Execute(out, data)
Expand Down
6 changes: 6 additions & 0 deletions protoc_plugins/protoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func Test_UseOfGoogleEmptyMessage(t *testing.T) {
}

func Test_NoPackage(t *testing.T) {
workdir, _ := os.Getwd()
Comment thread
satdeveloping marked this conversation as resolved.
Outdated
tmpdir, err := os.MkdirTemp("", "proto-test")
require.NoError(t, err)

Expand All @@ -182,6 +183,11 @@ func Test_NoPackage(t *testing.T) {
}
protoc(t, args)

assertEqualFiles(
t,
workdir+"/testdata/NoPackage/Test/CustomImport/ServiceInterface.php",
tmpdir+"/Test/CustomImport/ServiceInterface.php",
)
assert.NoError(t, os.RemoveAll("plugin"))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
# Generated by the protocol buffer compiler (roadrunner-server/grpc). DO NOT EDIT!
# source: NoPackage/nopackage.proto

namespace Test\CustomImport;

use Spiral\RoadRunner\GRPC;

interface ServiceInterface extends GRPC\ServiceInterface
{
// GRPC specific service name.
public const NAME = "<nil>.Service";
Comment thread
satdeveloping marked this conversation as resolved.
Outdated

/**
* @param GRPC\ContextInterface $ctx
* @param \Message $in
* @return \Message
*
* @throws GRPC\Exception\InvokeException
*/
public function SimpleMethod(GRPC\ContextInterface $ctx, \Message $in): \Message;
}