|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright 2026 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 | + * IMPORTANT: This file prevents an exception when `PBObject` is used. |
| 20 | + * The `Object` class from `google/cloud/securitycenter/v1/kubernetes.proto` was manually |
| 21 | + * renamed to `PBObject` in PHP to avoid a conflict with a PHP reserved keyword. |
| 22 | + * This file ensures that the `PBObject` class is correctly registered with the |
| 23 | + * Protobuf descriptor pool under its original `Object` descriptor. |
| 24 | + * |
| 25 | + * This file can be removed once the protobuf library introduces a fix for |
| 26 | + * descriptor pool issues when classes are renamed due to reserved keywords. |
| 27 | + * @see https://github.com/protocolbuffers/protobuf/pull/27456 |
| 28 | + */ |
| 29 | +namespace GPBMetadata\Google\Cloud\Securitycenter\V1 { |
| 30 | + |
| 31 | + class KubernetesDescriptorFix |
| 32 | + { |
| 33 | + public static $is_initialized = false; |
| 34 | + |
| 35 | + public static function initOnce() { |
| 36 | + if (static::$is_initialized == true) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + // This is required to load the descriptor for PBObject |
| 41 | + \GPBMetadata\Google\Cloud\Securitycenter\V1\Kubernetes::initOnce(); |
| 42 | + |
| 43 | + $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool(); |
| 44 | + $pool->addMessage( |
| 45 | + 'google.cloud.securitycenter.v1.Kubernetes.Object', |
| 46 | + \Google\Cloud\SecurityCenter\V1\Kubernetes\PBObject::class |
| 47 | + )->finalizeToPool(); |
| 48 | + |
| 49 | + static::$is_initialized = true; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + KubernetesDescriptorFix::initOnce(); |
| 54 | +} |
| 55 | + |
0 commit comments