Skip to content
This repository was archived by the owner on Jul 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public String getApiWrapperClassName(InterfaceConfig interfaceConfig) {
}

/** The name of the implementation class that implements a particular proto interface. */
public String getApiWrapperClassImplName(Interface apiInterface) {
public String getApiWrapperClassImplName(InterfaceConfig interfaceConfig) {
return getNotImplementedString("SurfaceNamer.getApiWrapperClassImplName");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private StaticLangApiView generateApiClass(GapicInterfaceContext context) {
apiClass.doc(serviceTransformer.generateServiceDoc(context, null));

apiClass.name(namer.getApiWrapperClassName(context.getInterfaceConfig()));
apiClass.implName(namer.getApiWrapperClassImplName(context.getInterface()));
apiClass.implName(namer.getApiWrapperClassImplName(context.getInterfaceConfig()));
apiClass.grpcServiceName(namer.getGrpcContainerTypeName(context.getInterface()));
apiClass.grpcTypeName(namer.getGrpcServiceClassName(context.getInterface()));
apiClass.settingsClassName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.api.codegen.config.FieldConfig;
import com.google.api.codegen.config.GapicInterfaceConfig;
import com.google.api.codegen.config.GapicMethodConfig;
import com.google.api.codegen.config.InterfaceConfig;
import com.google.api.codegen.config.ResourceNameConfig;
import com.google.api.codegen.config.ResourceNameType;
import com.google.api.codegen.config.SingleResourceNameConfig;
Expand Down Expand Up @@ -353,8 +354,8 @@ public String getGrpcServiceClassName(Interface apiInterface) {
}

@Override
public String getApiWrapperClassImplName(Interface apiInterface) {
return publicClassName(Name.upperCamel(apiInterface.getSimpleName(), "ClientImpl"));
public String getApiWrapperClassImplName(InterfaceConfig interfaceConfig) {
return publicClassName(Name.upperCamel(getInterfaceName(interfaceConfig), "ClientImpl"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.api.codegen.transformer.SurfaceNamer;
import com.google.api.codegen.util.php.PhpTypeTable;
import com.google.api.codegen.viewmodel.ApiMethodView;
import com.google.api.codegen.viewmodel.DynamicLangXApiSubclassView;
import com.google.api.codegen.viewmodel.DynamicLangXApiView;
import com.google.api.codegen.viewmodel.GrpcStreamingDetailView;
import com.google.api.codegen.viewmodel.LongRunningOperationDetailView;
Expand All @@ -59,7 +60,8 @@ public class PhpGapicSurfaceTransformer implements ModelToViewTransformer {
private final FileHeaderTransformer fileHeaderTransformer =
new FileHeaderTransformer(new PhpImportSectionTransformer());

private static final String XAPI_TEMPLATE_FILENAME = "php/main.snip";
private static final String API_TEMPLATE_FILENAME = "php/partial_veneer_client.snip";
private static final String API_IMPL_TEMPLATE_FILENAME = "php/client_impl.snip";

public PhpGapicSurfaceTransformer(
GapicProductConfig productConfig, GapicCodePathMapper pathMapper) {
Expand All @@ -74,7 +76,7 @@ public PhpGapicSurfaceTransformer(

@Override
public List<String> getTemplateFileNames() {
return Arrays.asList(XAPI_TEMPLATE_FILENAME);
return Arrays.asList(API_TEMPLATE_FILENAME, API_IMPL_TEMPLATE_FILENAME);
}

@Override
Expand Down Expand Up @@ -108,58 +110,69 @@ public List<ViewModel> transform(GapicInterfaceContext context) {

List<ApiMethodView> methods = generateApiMethods(context);

DynamicLangXApiView.Builder xapiClass = DynamicLangXApiView.newBuilder();
DynamicLangXApiView.Builder apiImplClass = DynamicLangXApiView.newBuilder();

xapiClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0)));
apiImplClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0)));

xapiClass.templateFileName(XAPI_TEMPLATE_FILENAME);
xapiClass.protoFilename(context.getInterface().getFile().getSimpleName());
String name = namer.getApiWrapperClassName(context.getInterfaceConfig());
xapiClass.name(name);
apiImplClass.templateFileName(API_IMPL_TEMPLATE_FILENAME);
apiImplClass.protoFilename(context.getInterface().getFile().getSimpleName());
String implName = namer.getApiWrapperClassImplName(context.getInterfaceConfig());
apiImplClass.name(implName);
ProductServiceConfig productServiceConfig = new ProductServiceConfig();
xapiClass.serviceAddress(
apiImplClass.serviceAddress(
productServiceConfig.getServiceAddress(context.getInterface().getModel()));
xapiClass.servicePort(productServiceConfig.getServicePort());
xapiClass.serviceTitle(productServiceConfig.getTitle(context.getInterface().getModel()));
xapiClass.authScopes(productServiceConfig.getAuthScopes(context.getInterface().getModel()));
apiImplClass.servicePort(productServiceConfig.getServicePort());
apiImplClass.serviceTitle(productServiceConfig.getTitle(context.getInterface().getModel()));
apiImplClass.authScopes(productServiceConfig.getAuthScopes(context.getInterface().getModel()));

xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
xapiClass.formatResourceFunctions(
apiImplClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
apiImplClass.formatResourceFunctions(
pathTemplateTransformer.generateFormatResourceFunctions(context));
xapiClass.parseResourceFunctions(
apiImplClass.parseResourceFunctions(
pathTemplateTransformer.generateParseResourceFunctions(context));
xapiClass.pathTemplateGetterFunctions(
apiImplClass.pathTemplateGetterFunctions(
pathTemplateTransformer.generatePathTemplateGetterFunctions(context));
xapiClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
xapiClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
xapiClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
xapiClass.longRunningDescriptors(createLongRunningDescriptors(context));
xapiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
xapiClass.grpcStreamingDescriptors(createGrpcStreamingDescriptors(context));

xapiClass.methodKeys(generateMethodKeys(context));
xapiClass.clientConfigPath(namer.getClientConfigPath(context.getInterface()));
xapiClass.interfaceKey(context.getInterface().getFullName());
apiImplClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
apiImplClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
apiImplClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
apiImplClass.longRunningDescriptors(createLongRunningDescriptors(context));
apiImplClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
apiImplClass.grpcStreamingDescriptors(createGrpcStreamingDescriptors(context));

apiImplClass.methodKeys(generateMethodKeys(context));
apiImplClass.clientConfigPath(namer.getClientConfigPath(context.getInterface()));
apiImplClass.interfaceKey(context.getInterface().getFullName());
String grpcClientTypeName =
namer.getAndSaveNicknameForGrpcClientTypeName(
context.getModelTypeTable(), context.getInterface());
xapiClass.grpcClientTypeName(grpcClientTypeName);
apiImplClass.grpcClientTypeName(grpcClientTypeName);

xapiClass.apiMethods(methods);
apiImplClass.apiMethods(methods);

xapiClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
apiImplClass.stubs(grpcStubTransformer.generateGrpcStubs(context));

xapiClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
xapiClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
apiImplClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
apiImplClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());

xapiClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion());
apiImplClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion());

// must be done as the last step to catch all imports
xapiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
apiImplClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));

apiImplClass.outputPath(outputPath + "/" + implName + ".php");

xapiClass.outputPath(outputPath + "/" + name + ".php");
surfaceData.add(apiImplClass.build());

String name = namer.getApiWrapperClassName(context.getInterfaceConfig());

surfaceData.add(xapiClass.build());
DynamicLangXApiSubclassView.Builder apiClass = DynamicLangXApiSubclassView.newBuilder();
apiClass.templateFileName(API_TEMPLATE_FILENAME);
apiClass.protoFilename(context.getInterface().getFile().getSimpleName());
apiClass.name(name);
apiClass.parentName(implName);
apiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
apiClass.outputPath(outputPath + "/" + name + ".php");
surfaceData.add(apiClass.build());

return surfaceData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.api.codegen.ServiceMessages;
import com.google.api.codegen.config.GapicInterfaceConfig;
import com.google.api.codegen.config.GapicMethodConfig;
import com.google.api.codegen.config.InterfaceConfig;
import com.google.api.codegen.config.SingleResourceNameConfig;
import com.google.api.codegen.config.VisibilityConfig;
import com.google.api.codegen.transformer.ModelTypeFormatterImpl;
Expand Down Expand Up @@ -123,6 +124,11 @@ public String getFullyQualifiedApiWrapperClassName(GapicInterfaceConfig interfac
return getPackageName() + "\\" + getApiWrapperClassName(interfaceConfig);
}

@Override
public String getApiWrapperClassImplName(InterfaceConfig interfaceConfig) {
return publicClassName(Name.upperCamel(getInterfaceName(interfaceConfig), "GapicClient"));
}

@Override
public String getGrpcClientTypeName(Interface apiInterface) {
return qualifiedName(getGrpcClientTypeName(apiInterface, "GrpcClient"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Copyright 2016 Google Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.api.codegen.viewmodel;

import com.google.api.codegen.SnippetSetRunner;
import com.google.auto.value.AutoValue;

@AutoValue
public abstract class DynamicLangXApiSubclassView implements ViewModel {
public abstract String templateFileName();

public abstract FileHeaderView fileHeader();

public abstract String protoFilename();

public abstract String name();

public abstract String parentName();

public abstract String outputPath();

@Override
public String resourceRoot() {
return SnippetSetRunner.SNIPPET_RESOURCE_ROOT;
}

public static Builder newBuilder() {
return new AutoValue_DynamicLangXApiSubclassView.Builder();
}

@AutoValue.Builder
public abstract static class Builder {
public abstract Builder templateFileName(String val);

public abstract Builder fileHeader(FileHeaderView val);

public abstract Builder protoFilename(String simpleName);

public abstract Builder name(String val);

public abstract Builder parentName(String val);

public abstract Builder outputPath(String val);

public abstract DynamicLangXApiSubclassView build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@extends "php/common.snip"

@snippet generate(xapiClass)
{@renderFileHeader(xapiClass.fileHeader, generatedCodeWarning(xapiClass))}

/**
* {@@inheritdoc}
*/
class {@xapiClass.name} extends {@xapiClass.parentName}
{
// This class is intentionally empty, and is intended to hold manual additions to the generated {@@see {@xapiClass.name}Impl} class.
}
@end

@private generatedCodeWarning(xapiClass)
/*
* GENERATED CODE WARNING
* This file was generated from the file
* https://github.com/google/googleapis/blob/master/{@xapiClass.protoFilename}
* and updates to that file get reflected here through a refresh process.
*
* EXPERIMENTAL: this client library class has not yet been declared beta. This class may change
* more frequently than those which have been declared beta or 1.0, including changes which break
* backwards compatibility.
*
* @@experimental
*/
@end
Loading