Skip to content

Commit 40ad3fa

Browse files
Adam Cozzettecopybara-github
authored andcommitted
Breaking change: remove support for PHP generic services
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
1 parent 1ff12ef commit 40ad3fa

9 files changed

Lines changed: 203 additions & 555 deletions

File tree

php/tests/GeneratedServiceTest.php

Lines changed: 0 additions & 127 deletions
This file was deleted.

php/tests/proto/test_service.proto

Lines changed: 0 additions & 18 deletions
This file was deleted.

php/tests/proto/test_service_namespace.proto

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/google/protobuf/compiler/php/php_generator.cc

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ void GenerateEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_,
8787
const Options& options);
8888
void GenerateEnumValueDocComment(io::Printer* printer,
8989
const EnumValueDescriptor* value);
90-
void GenerateServiceDocComment(io::Printer* printer,
91-
const ServiceDescriptor* service);
92-
void GenerateServiceMethodDocComment(io::Printer* printer,
93-
const MethodDescriptor* method);
9490

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

348-
std::string GeneratedServiceFileName(const ServiceDescriptor* service,
349-
const Options& options) {
350-
std::string result = FullClassName(service, options);
351-
for (int i = 0; i < result.size(); i++) {
352-
if (result[i] == '\\') {
353-
result[i] = '/';
354-
}
355-
}
356-
return absl::StrCat(result, "Interface", ".php");
357-
}
358-
359344
std::string IntToString(int32_t value) {
360345
std::ostringstream os;
361346
os << value;
@@ -796,16 +781,6 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) {
796781
Outdent(printer);
797782
}
798783

799-
void GenerateServiceMethod(const MethodDescriptor* method,
800-
io::Printer* printer) {
801-
printer->Print(
802-
"public function ^camel_name^(\\^request_name^ $request);\n\n",
803-
"camel_name", UnderscoresToCamelCase(method->name(), false),
804-
"request_name", FullClassName(
805-
method->input_type(), false)
806-
);
807-
}
808-
809784
void GenerateMessageToPool(absl::string_view name_prefix,
810785
const Descriptor* message, io::Printer* printer) {
811786
// Don't generate MapEntry messages -- we use the PHP extension's native
@@ -1573,53 +1548,6 @@ bool GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
15731548
return true;
15741549
}
15751550

1576-
void GenerateServiceFile(
1577-
const FileDescriptor* file, const ServiceDescriptor* service,
1578-
const Options& options, GeneratorContext* generator_context) {
1579-
std::string filename = GeneratedServiceFileName(service, options);
1580-
std::unique_ptr<io::ZeroCopyOutputStream> output(
1581-
generator_context->Open(filename));
1582-
io::Printer printer(output.get(), '^');
1583-
1584-
GenerateHead(file, &printer);
1585-
1586-
std::string fullname = FilenameToClassname(filename);
1587-
int lastindex = fullname.find_last_of('\\');
1588-
1589-
if (!file->options().php_namespace().empty() ||
1590-
(!file->options().has_php_namespace() && !file->package().empty()) ||
1591-
lastindex != std::string::npos) {
1592-
printer.Print(
1593-
"namespace ^name^;\n\n",
1594-
"name", fullname.substr(0, lastindex));
1595-
}
1596-
1597-
GenerateServiceDocComment(&printer, service);
1598-
1599-
if (lastindex != std::string::npos) {
1600-
printer.Print(
1601-
"interface ^name^\n"
1602-
"{\n",
1603-
"name", fullname.substr(lastindex + 1));
1604-
} else {
1605-
printer.Print(
1606-
"interface ^name^\n"
1607-
"{\n",
1608-
"name", fullname);
1609-
}
1610-
1611-
Indent(&printer);
1612-
1613-
for (int i = 0; i < service->method_count(); i++) {
1614-
const MethodDescriptor* method = service->method(i);
1615-
GenerateServiceMethodDocComment(&printer, method);
1616-
GenerateServiceMethod(method, &printer);
1617-
}
1618-
1619-
Outdent(&printer);
1620-
printer.Print("}\n\n");
1621-
}
1622-
16231551
bool GenerateFile(const FileDescriptor* file, const Options& options,
16241552
GeneratorContext* generator_context, std::string* error) {
16251553
GenerateMetadataFile(file, options, generator_context);
@@ -1636,11 +1564,6 @@ bool GenerateFile(const FileDescriptor* file, const Options& options,
16361564
return false;
16371565
}
16381566
}
1639-
if (file->options().php_generic_services()) {
1640-
for (int i = 0; i < file->service_count(); i++) {
1641-
GenerateServiceFile(file, file->service(i), options, generator_context);
1642-
}
1643-
}
16441567

16451568
return true;
16461569
}
@@ -1791,19 +1714,6 @@ void GenerateMessageConstructorDocComment(io::Printer* printer,
17911714
printer->Print(" */\n");
17921715
}
17931716

1794-
void GenerateServiceDocComment(io::Printer* printer,
1795-
const ServiceDescriptor* service) {
1796-
printer->Print("/**\n");
1797-
if (service->options().deprecated()) {
1798-
printer->Print(" * @deprecated\n");
1799-
}
1800-
GenerateDocCommentBody(printer, service);
1801-
printer->Print(
1802-
" * Protobuf type <code>^fullname^</code>\n"
1803-
" */\n",
1804-
"fullname", EscapePhpdoc(service->full_name()));
1805-
}
1806-
18071717
void GenerateFieldDocComment(io::Printer* printer, const FieldDescriptor* field,
18081718
const Options& options, int function_type) {
18091719
// In theory we should have slightly different comments for setters, getters,
@@ -1894,26 +1804,6 @@ void GenerateEnumValueDocComment(io::Printer* printer,
18941804
"def", EscapePhpdoc(FirstLineOf(value->DebugString())));
18951805
}
18961806

1897-
void GenerateServiceMethodDocComment(io::Printer* printer,
1898-
const MethodDescriptor* method) {
1899-
printer->Print("/**\n");
1900-
GenerateDocCommentBody(printer, method);
1901-
if (method->options().deprecated()) {
1902-
printer->Print(" * @deprecated\n");
1903-
}
1904-
printer->Print(
1905-
" * Method <code>^method_name^</code>\n"
1906-
" *\n",
1907-
"method_name", EscapePhpdoc(UnderscoresToCamelCase(method->name(), false)));
1908-
printer->Print(
1909-
" * @param \\^input_type^ $request\n",
1910-
"input_type", EscapePhpdoc(FullClassName(method->input_type(), false)));
1911-
printer->Print(
1912-
" * @return \\^return_type^\n"
1913-
" */\n",
1914-
"return_type", EscapePhpdoc(FullClassName(method->output_type(), false)));
1915-
}
1916-
19171807
std::string FilenameCName(const FileDescriptor* file) {
19181808
return absl::StrReplaceAll(file->name(), {{".", "_"}, {"/", "_"}});
19191809
}

0 commit comments

Comments
 (0)