Skip to content

Commit

Permalink
Strip extra slashes when there is no package
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Taylor <[email protected]>
  • Loading branch information
Stuart Taylor committed May 12, 2024
1 parent 1cabc0e commit 47dba0c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
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()
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";

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

0 comments on commit 47dba0c

Please sign in to comment.