2828class Component
2929{
3030 const VERSION_REGEX = '/^V([0-9])?(p[0-9])?(beta|alpha)?[0-9]?$/ ' ;
31+ private const PROTOBUF = 'google/protobuf ' ;
3132 public const ROOT_DIR = __DIR__ . '/../../ ' ;
3233 private string $ path ;
3334 private string $ releaseLevel ;
@@ -188,7 +189,10 @@ private function validateComponentFiles(): void
188189 $ this ->description = $ composerJson ['description ' ];
189190 $ this ->composerVersion = $ composerJson ['version ' ] ?? null ;
190191
191- if (!$ repoName = $ composerJson ['extra ' ]['component ' ]['target ' ] ?? null ) {
192+ if ($ this ->packageName === Component::PROTOBUF ) {
193+ // special handling for protobuf "virtual" package
194+ $ repoName = 'protocolbuffers/protobuf ' ;
195+ } elseif (!$ repoName = $ composerJson ['extra ' ]['component ' ]['target ' ] ?? null ) {
192196 if (!str_starts_with ($ composerJson ['homepage ' ], 'https://github.com/ ' )) {
193197 throw new RuntimeException (
194198 'composer does not contain extra.component.target, and homepage is not a github URL '
@@ -204,6 +208,13 @@ private function validateComponentFiles(): void
204208 $ repoMetadataJson = $ repoMetadataFullJson [$ this ->name ];
205209 } elseif (file_exists ($ repoMetadataPath = $ this ->path . '/.repo-metadata.json ' )) {
206210 $ repoMetadataJson = json_decode (file_get_contents ($ repoMetadataPath ), true );
211+ } elseif ($ this ->packageName === Component::PROTOBUF ) {
212+ // special handling for protobuf "virtual" package
213+ $ repoMetadataJson = [
214+ 'release_level ' => 'stable ' ,
215+ 'client_documentation ' => 'https://cloud.google.com/php/docs/reference/auth/latest ' ,
216+ 'library_type ' => 'CORE ' ,
217+ ];
207218 } else {
208219 throw new RuntimeException (sprintf (
209220 'repo metadata not found for component "%s" and no .repo-metadata.json file found in %s ' ,
@@ -218,16 +229,22 @@ private function validateComponentFiles(): void
218229 $ this ->name
219230 ));
220231 }
221- if (empty ($ repoMetadataJson ['release_level ' ])) {
232+ if (empty ($ repoMetadataJson ['client_documentation ' ])) {
222233 throw new RuntimeException (sprintf (
223234 'repo metadata does not contain "client_documentation" for component "%s" ' ,
224235 $ this ->name
225236 ));
226237 }
238+ if (empty ($ repoMetadataJson ['library_type ' ])) {
239+ throw new RuntimeException (sprintf (
240+ 'repo metadata does not contain "library_type" for component "%s" ' ,
241+ $ this ->name
242+ ));
243+ }
227244 $ this ->releaseLevel = $ repoMetadataJson ['release_level ' ];
228245 $ this ->clientDocumentation = $ repoMetadataJson ['client_documentation ' ];
229- $ this ->productDocumentation = $ repoMetadataJson ['product_documentation ' ] ?? '' ;
230246 $ this ->libraryType = $ repoMetadataJson ['library_type ' ];
247+ $ this ->productDocumentation = $ repoMetadataJson ['product_documentation ' ] ?? '' ;
231248
232249 $ namespaces = [];
233250 foreach ($ composerJson ['autoload ' ]['psr-4 ' ] as $ namespace => $ dir ) {
@@ -261,13 +278,20 @@ private function validateComponentFiles(): void
261278 $ this ->componentDependencies [] = new Component ('CommonProtos ' );
262279 }
263280 }
281+ // add protobuf if it's required
282+ if (isset ($ composerJson ['require ' ]['google/protobuf ' ])) {
283+ $ this ->componentDependencies [] = new Component ('protobuf ' , self ::ROOT_DIR . '/dev/vendor/google/protobuf ' );
284+ }
264285 }
265286
266287 /**
267288 * Get the contents of VERSION in the component directory
268289 */
269290 public function getPackageVersion (): string
270291 {
292+ if (!file_exists (sprintf ('%s/VERSION ' , $ this ->path ))) {
293+ return '' ;
294+ }
271295 return trim (file_get_contents (sprintf ('%s/VERSION ' , $ this ->path )));
272296 }
273297
0 commit comments