Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
update php paged map fields with map field snippet (#3325)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Jan 7, 2021
1 parent 7c508c8 commit d284392
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public PageStreamingDescriptorView generateDescriptor(
context.getNamer().getFieldGetFunctionName(pageStreaming.getResourcesField()));
descriptor.methodName(context.getNamer().getMethodKey(method));
descriptor.transportMethodName(context.getNamer().getGrpcMethodName(method));
descriptor.resourcesFieldIsMap(pageStreaming.getResourcesField().isMap());
return descriptor.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public abstract class PageStreamingDescriptorView {

public abstract String resourcesGetMethodName();

public abstract Boolean resourcesFieldIsMap();

public abstract String methodName();

public abstract String transportMethodName();
Expand Down Expand Up @@ -75,6 +77,8 @@ public abstract static class Builder {

public abstract Builder resourcesGetMethodName(String val);

public abstract Builder resourcesFieldIsMap(Boolean val);

public abstract Builder methodName(String val);

public abstract Builder transportMethodName(String val);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@
// Iterate over pages of elements
$pagedResponse = {@methodCallSampleCode(apiMethod)};
foreach ($pagedResponse->iteratePages() as $page) {
@if apiMethod.pageStreamingView.resourcesFieldIsMap
foreach ($page as $key => $element) {
@else
foreach ($page as $element) {
@end
// doSomethingWith($element);
}
}
Expand All @@ -163,7 +167,11 @@
@private pagedAllSampleCode(apiMethod)
// Iterate through all elements
$pagedResponse = {@methodCallSampleCode(apiMethod)};
@if apiMethod.pageStreamingView.resourcesFieldIsMap
foreach ($pagedResponse->iterateAllElements() as $key => $element) {
@else
foreach ($pagedResponse->iterateAllElements() as $element) {
@end
// doSomethingWith($element);
}
@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ class LibraryServiceGapicClient
* // Iterate over pages of elements
* $pagedResponse = $libraryServiceClient->listAggregatedShelves();
* foreach ($pagedResponse->iteratePages() as $page) {
* foreach ($page as $element) {
* foreach ($page as $key => $element) {
* // doSomethingWith($element);
* }
* }
Expand All @@ -1029,7 +1029,7 @@ class LibraryServiceGapicClient
*
* // Iterate through all elements
* $pagedResponse = $libraryServiceClient->listAggregatedShelves();
* foreach ($pagedResponse->iterateAllElements() as $element) {
* foreach ($pagedResponse->iterateAllElements() as $key => $element) {
* // doSomethingWith($element);
* }
* } finally {
Expand Down

0 comments on commit d284392

Please sign in to comment.