Skip to content

Commit

Permalink
Breaking change: remove support for PHP generic services
Browse files Browse the repository at this point in the history
Generic services have been deprecated for about 14 years. This is technically a
breaking change, but fortunately the `php_generic_services` option appears to
have little or no usage. I could not find any examples of open source code
using it.

PiperOrigin-RevId: 592677762
  • Loading branch information
acozzette authored and copybara-github committed Dec 20, 2023
1 parent 1ff12ef commit 40ad3fa
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 555 deletions.
127 changes: 0 additions & 127 deletions php/tests/GeneratedServiceTest.php

This file was deleted.

18 changes: 0 additions & 18 deletions php/tests/proto/test_service.proto

This file was deleted.

13 changes: 0 additions & 13 deletions php/tests/proto/test_service_namespace.proto

This file was deleted.

110 changes: 0 additions & 110 deletions src/google/protobuf/compiler/php/php_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ void GenerateEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_,
const Options& options);
void GenerateEnumValueDocComment(io::Printer* printer,
const EnumValueDescriptor* value);
void GenerateServiceDocComment(io::Printer* printer,
const ServiceDescriptor* service);
void GenerateServiceMethodDocComment(io::Printer* printer,
const MethodDescriptor* method);

template <typename DescriptorType>
std::string DescriptorFullName(const DescriptorType* desc, bool is_internal) {
Expand Down Expand Up @@ -345,17 +341,6 @@ std::string LegacyReadOnlyGeneratedClassFileName(std::string php_namespace,
return absl::StrCat(desc->name(), ".php");
}

std::string GeneratedServiceFileName(const ServiceDescriptor* service,
const Options& options) {
std::string result = FullClassName(service, options);
for (int i = 0; i < result.size(); i++) {
if (result[i] == '\\') {
result[i] = '/';
}
}
return absl::StrCat(result, "Interface", ".php");
}

std::string IntToString(int32_t value) {
std::ostringstream os;
os << value;
Expand Down Expand Up @@ -796,16 +781,6 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) {
Outdent(printer);
}

void GenerateServiceMethod(const MethodDescriptor* method,
io::Printer* printer) {
printer->Print(
"public function ^camel_name^(\\^request_name^ $request);\n\n",
"camel_name", UnderscoresToCamelCase(method->name(), false),
"request_name", FullClassName(
method->input_type(), false)
);
}

void GenerateMessageToPool(absl::string_view name_prefix,
const Descriptor* message, io::Printer* printer) {
// Don't generate MapEntry messages -- we use the PHP extension's native
Expand Down Expand Up @@ -1573,53 +1548,6 @@ bool GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
return true;
}

void GenerateServiceFile(
const FileDescriptor* file, const ServiceDescriptor* service,
const Options& options, GeneratorContext* generator_context) {
std::string filename = GeneratedServiceFileName(service, options);
std::unique_ptr<io::ZeroCopyOutputStream> output(
generator_context->Open(filename));
io::Printer printer(output.get(), '^');

GenerateHead(file, &printer);

std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of('\\');

if (!file->options().php_namespace().empty() ||
(!file->options().has_php_namespace() && !file->package().empty()) ||
lastindex != std::string::npos) {
printer.Print(
"namespace ^name^;\n\n",
"name", fullname.substr(0, lastindex));
}

GenerateServiceDocComment(&printer, service);

if (lastindex != std::string::npos) {
printer.Print(
"interface ^name^\n"
"{\n",
"name", fullname.substr(lastindex + 1));
} else {
printer.Print(
"interface ^name^\n"
"{\n",
"name", fullname);
}

Indent(&printer);

for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor* method = service->method(i);
GenerateServiceMethodDocComment(&printer, method);
GenerateServiceMethod(method, &printer);
}

Outdent(&printer);
printer.Print("}\n\n");
}

bool GenerateFile(const FileDescriptor* file, const Options& options,
GeneratorContext* generator_context, std::string* error) {
GenerateMetadataFile(file, options, generator_context);
Expand All @@ -1636,11 +1564,6 @@ bool GenerateFile(const FileDescriptor* file, const Options& options,
return false;
}
}
if (file->options().php_generic_services()) {
for (int i = 0; i < file->service_count(); i++) {
GenerateServiceFile(file, file->service(i), options, generator_context);
}
}

return true;
}
Expand Down Expand Up @@ -1791,19 +1714,6 @@ void GenerateMessageConstructorDocComment(io::Printer* printer,
printer->Print(" */\n");
}

void GenerateServiceDocComment(io::Printer* printer,
const ServiceDescriptor* service) {
printer->Print("/**\n");
if (service->options().deprecated()) {
printer->Print(" * @deprecated\n");
}
GenerateDocCommentBody(printer, service);
printer->Print(
" * Protobuf type <code>^fullname^</code>\n"
" */\n",
"fullname", EscapePhpdoc(service->full_name()));
}

void GenerateFieldDocComment(io::Printer* printer, const FieldDescriptor* field,
const Options& options, int function_type) {
// In theory we should have slightly different comments for setters, getters,
Expand Down Expand Up @@ -1894,26 +1804,6 @@ void GenerateEnumValueDocComment(io::Printer* printer,
"def", EscapePhpdoc(FirstLineOf(value->DebugString())));
}

void GenerateServiceMethodDocComment(io::Printer* printer,
const MethodDescriptor* method) {
printer->Print("/**\n");
GenerateDocCommentBody(printer, method);
if (method->options().deprecated()) {
printer->Print(" * @deprecated\n");
}
printer->Print(
" * Method <code>^method_name^</code>\n"
" *\n",
"method_name", EscapePhpdoc(UnderscoresToCamelCase(method->name(), false)));
printer->Print(
" * @param \\^input_type^ $request\n",
"input_type", EscapePhpdoc(FullClassName(method->input_type(), false)));
printer->Print(
" * @return \\^return_type^\n"
" */\n",
"return_type", EscapePhpdoc(FullClassName(method->output_type(), false)));
}

std::string FilenameCName(const FileDescriptor* file) {
return absl::StrReplaceAll(file->name(), {{".", "_"}, {"/", "_"}});
}
Expand Down
Loading

0 comments on commit 40ad3fa

Please sign in to comment.