googleapis / google-api-php-client

A PHP client library for accessing Google APIs
Apache License 2.0
9.2k stars 3.52k forks source link

Custom Namespace issue on google analytics-admin and analytics-data php api. #2586

Closed bilal-ahmed-wpb closed 3 weeks ago

bilal-ahmed-wpb commented 2 months ago

A question raised in my mind. The files in which there is the following comment:

Generated by the protocol buffer compiler. DO NOT EDIT! In google/analytics-admin and google/analytics-data can I add my custom plugin namespace on them and will they work then?

And to make them work as I am using php-scoper to contain them under my own custom namespace in order to avoid plugin conflicts on Wordpress. Any guidance on this please.

ajupazhamayil commented 2 months ago

To give you a context on the comment, the code is fully generated by a generator and, in normal scenarios, if we change that code and merge it to the repository, the generator will generate the code again and overwrite it in the repository (local machines are safe on this overwrite as long as you don't pull the latest, but local machine will be stuck with the old code). Thats why we have that warning.

Hope this information helps.

bilal-ahmed-wpb commented 2 months ago

But as I use the php-scoper or strauss (namespace tool) and then reuse the plugin I get following error:

WARNING MyPlugin\Google\Analytics\Admin\V1alpha\DataStream is not found in descriptor pool. Only generated classes may derive from Message

WARNING MyPlugin\Google\Analytics\Admin\V1alpha\ListDataStreamsRequest is not found in descriptor pool

Hectorhammett commented 3 weeks ago

Hello @bilal-ahmed-wpb !

@ajupazhamayil is correct, this code is automatically generated from protobuffs from each API team, that way they can make any necessary changes and the code gets generated for the library :).

So editing the code inside the library is not advised. I recommend you to check the documentation for the php-scoper library.

Closing this as this is a question related to php-scoper and wordpress. If you have any specific questions about the usage of the library, please feel free to comment back!