Skip to content

Commit c34532f

Browse files
committed
add descriptor fix
1 parent ce2185f commit c34532f

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

SecurityCenter/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"psr-4": {
88
"Google\\Cloud\\SecurityCenter\\": "src",
99
"GPBMetadata\\Google\\Cloud\\Securitycenter\\": "metadata"
10-
}
10+
},
11+
"files": [
12+
"metadata/descriptor_fix.php"
13+
]
1114
},
1215
"autoload-dev": {
1316
"psr-4": {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,8 @@
797797
"Grafeas\\": "Grafeas/src"
798798
},
799799
"files": [
800-
"BigQueryStorage/metadata/descriptor_fix.php"
800+
"BigQueryStorage/metadata/descriptor_fix.php",
801+
"SecurityCenter/metadata/descriptor_fix.php"
801802
]
802803
},
803804
"autoload-dev": {

0 commit comments

Comments
 (0)