|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +/* |
| 19 | + * GENERATED CODE WARNING |
| 20 | + * This file was automatically generated - do not edit! |
| 21 | + */ |
| 22 | + |
| 23 | +require_once __DIR__ . '/../../../vendor/autoload.php'; |
| 24 | + |
| 25 | +// [START discoveryengine_v1_generated_ServingConfigService_UpdateServingConfig_sync] |
| 26 | +use Google\ApiCore\ApiException; |
| 27 | +use Google\Cloud\DiscoveryEngine\V1\Client\ServingConfigServiceClient; |
| 28 | +use Google\Cloud\DiscoveryEngine\V1\ServingConfig; |
| 29 | +use Google\Cloud\DiscoveryEngine\V1\SolutionType; |
| 30 | +use Google\Cloud\DiscoveryEngine\V1\UpdateServingConfigRequest; |
| 31 | + |
| 32 | +/** |
| 33 | + * Updates a ServingConfig. |
| 34 | + * |
| 35 | + * Returns a NOT_FOUND error if the ServingConfig does not exist. |
| 36 | + * |
| 37 | + * @param string $servingConfigDisplayName The human readable serving config display name. Used in Discovery |
| 38 | + * UI. |
| 39 | + * |
| 40 | + * This field must be a UTF-8 encoded string with a length limit of 128 |
| 41 | + * characters. Otherwise, an INVALID_ARGUMENT error is returned. |
| 42 | + * @param int $servingConfigSolutionType Immutable. Specifies the solution type that a serving config can |
| 43 | + * be associated with. |
| 44 | + */ |
| 45 | +function update_serving_config_sample( |
| 46 | + string $servingConfigDisplayName, |
| 47 | + int $servingConfigSolutionType |
| 48 | +): void { |
| 49 | + // Create a client. |
| 50 | + $servingConfigServiceClient = new ServingConfigServiceClient(); |
| 51 | + |
| 52 | + // Prepare the request message. |
| 53 | + $servingConfig = (new ServingConfig()) |
| 54 | + ->setDisplayName($servingConfigDisplayName) |
| 55 | + ->setSolutionType($servingConfigSolutionType); |
| 56 | + $request = (new UpdateServingConfigRequest()) |
| 57 | + ->setServingConfig($servingConfig); |
| 58 | + |
| 59 | + // Call the API and handle any network failures. |
| 60 | + try { |
| 61 | + /** @var ServingConfig $response */ |
| 62 | + $response = $servingConfigServiceClient->updateServingConfig($request); |
| 63 | + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); |
| 64 | + } catch (ApiException $ex) { |
| 65 | + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +/** |
| 70 | + * Helper to execute the sample. |
| 71 | + * |
| 72 | + * This sample has been automatically generated and should be regarded as a code |
| 73 | + * template only. It will require modifications to work: |
| 74 | + * - It may require correct/in-range values for request initialization. |
| 75 | + * - It may require specifying regional endpoints when creating the service client, |
| 76 | + * please see the apiEndpoint client configuration option for more details. |
| 77 | + */ |
| 78 | +function callSample(): void |
| 79 | +{ |
| 80 | + $servingConfigDisplayName = '[DISPLAY_NAME]'; |
| 81 | + $servingConfigSolutionType = SolutionType::SOLUTION_TYPE_UNSPECIFIED; |
| 82 | + |
| 83 | + update_serving_config_sample($servingConfigDisplayName, $servingConfigSolutionType); |
| 84 | +} |
| 85 | +// [END discoveryengine_v1_generated_ServingConfigService_UpdateServingConfig_sync] |
0 commit comments