Skip to content

Commit

Permalink
Fix service NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Taylor committed May 12, 2024
1 parent 47dba0c commit 7b4aa55
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
11 changes: 10 additions & 1 deletion protoc_plugins/protoc-gen-php-grpc/php/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use Spiral\RoadRunner\GRPC;
interface {{ .Service.Name | interface }} extends GRPC\ServiceInterface
{
// GRPC specific service name.
public const NAME = "{{ .File.Package }}.{{ .Service.Name }}";{{ "\n" }}
public const NAME = "{{ resolve_name_const .File.Package .Service.Name }}";{{ "\n" }}
{{- range $m := .Service.Method}}
{{- $inName := name $ns $m.InputType }}
{{- $outName := name $ns $m.OutputType }}
Expand Down Expand Up @@ -94,6 +94,15 @@ func body(req *plugin.CodeGeneratorRequest, file *desc.FileDescriptorProto, serv
"strip_slashes": func(name string) string {
return strings.ReplaceAll(name, "\\\\", "\\")
},
"resolve_name_const": func(packagePath, serviceName *string) string {

if packagePath == nil || *packagePath == "" {
return *serviceName
}

return *packagePath + "." + *serviceName

},
}).Parse(phpBody))

err := tpl.Execute(out, data)
Expand Down
18 changes: 12 additions & 6 deletions protoc_plugins/protoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func protoc(t *testing.T, args []string) {
}

func Test_Simple(t *testing.T) {
workdir, _ := os.Getwd()
workdir, err := os.Getwd()
require.NoError(t, err)
tmpdir, err := os.MkdirTemp("", "proto-test")
require.NoError(t, err)

Expand All @@ -61,7 +62,8 @@ func Test_Simple(t *testing.T) {
}

func Test_PhpNamespaceOption(t *testing.T) {
workdir, _ := os.Getwd()
workdir, err := os.Getwd()
require.NoError(t, err)
tmpdir, err := os.MkdirTemp("", "proto-test")
require.NoError(t, err)

Expand All @@ -87,7 +89,8 @@ func Test_PhpNamespaceOption(t *testing.T) {
}

func Test_UseImportedMessage(t *testing.T) {
workdir, _ := os.Getwd()
workdir, err := os.Getwd()
require.NoError(t, err)
tmpdir, err := os.MkdirTemp("", "proto-test")
require.NoError(t, err)

Expand All @@ -113,7 +116,8 @@ func Test_UseImportedMessage(t *testing.T) {
}

func Test_PhpNamespaceOptionInUse(t *testing.T) {
workdir, _ := os.Getwd()
workdir, err := os.Getwd()
require.NoError(t, err)
tmpdir, err := os.MkdirTemp("", "proto-test")
require.NoError(t, err)

Expand All @@ -139,7 +143,8 @@ func Test_PhpNamespaceOptionInUse(t *testing.T) {
}

func Test_UseOfGoogleEmptyMessage(t *testing.T) {
workdir, _ := os.Getwd()
workdir, err := os.Getwd()
require.NoError(t, err)
tmpdir, err := os.MkdirTemp("", "proto-test")
require.NoError(t, err)

Expand All @@ -166,7 +171,8 @@ func Test_UseOfGoogleEmptyMessage(t *testing.T) {
}

func Test_NoPackage(t *testing.T) {
workdir, _ := os.Getwd()
workdir, err := os.Getwd()
require.NoError(t, err)
tmpdir, err := os.MkdirTemp("", "proto-test")
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
interface ServiceInterface extends GRPC\ServiceInterface
{
// GRPC specific service name.
public const NAME = "<nil>.Service";
public const NAME = "Service";

/**
* @param GRPC\ContextInterface $ctx
Expand Down

0 comments on commit 7b4aa55

Please sign in to comment.