Google-api-php-client: Google_Client namespacing

Created on 31 Oct 2017  路  6Comments  路  Source: googleapis/google-api-php-client

I'm working in the context of WordPress plugins. In WordPress, you have no way to control what other plugins are doing. This means that if another plugin is using a library (via copy/paste or composer), developers run the risk of conflicting packages.

I'm using a utility https://github.com/TypistTech/imposter that modifies namesspaces allowing me to scope all the vendor libaries for my project without creating conflicts.

\Google_Client is registered in the global namespace, and I haven't been able to figure how using composer or the utility above to change that (without editing the vendor files manually). This is producing a conflict with a 3rd party plugin that is using an old version of google/apiclient.

While this isn't an issue for single composer projects, it's a massive problem for WordPress plugin development.

question

Most helpful comment

I think you should follow the PSR-Standards for namesspaces (PSR-0 and PSR-4) and add a proper vendor name + get rid of underscores in the lib name.

What was your consideration which lead you to the decision to not fix this issue?

All 6 comments

Ran into a similar issue, at the end I had to commit Google's API files into my plugin to ensure that it's reading the right files... Added a few class exists checks, method checks and exception catches to fix this

Don't take this the wrong way... but
at the end of the day, this is not Google's problem... its yours

@Johnhhorton As far as I see in the composer.json the namespace is Google_, not very common to do it that way, but it is not in the global \ namespace.

Hello!

I stumble upon the exact same problem while writing a plugin. Duplicator Pro use an old version of Google_Client(). Would you be kind enough to share you code modification in order to make it work?

Thanks in advance!

Thank you for your bug report. This client library is currently in maintenance mode. We are fixing necessary bugs and adding essential features to ensure this library continues to meet your needs for accessing Google APIs. After careful consideration, we have decided not to fix this bug since there is an acceptable work-around. If you disagree, please feel free explain why you believe fixing it is essential for users of this client library.

I think you should follow the PSR-Standards for namesspaces (PSR-0 and PSR-4) and add a proper vendor name + get rid of underscores in the lib name.

What was your consideration which lead you to the decision to not fix this issue?

@Johnhhorton
Did you find a workaround for this problem? If so, could you share?

thank you

I'm working in the context of WordPress plugins. In WordPress, you have no way to control what other plugins are doing. This means that if another plugin is using a library (via copy/paste or composer), developers run the risk of conflicting packages.

I'm using a utility https://github.com/TypistTech/imposter that modifies namesspaces allowing me to scope all the vendor libaries for my project without creating conflicts.

\Google_Client is registered in the global namespace, and I haven't been able to figure how using composer or the utility above to change that (without editing the vendor files manually). This is producing a conflict with a 3rd party plugin that is using an old version of google/apiclient.

While this isn't an issue for single composer projects, it's a massive problem for WordPress plugin development.

I'm working in the context of WordPress plugins. In WordPress, you have no way to control what other plugins are doing. This means that if another plugin is using a library (via copy/paste or composer), developers run the risk of conflicting packages.

I'm using a utility https://github.com/TypistTech/imposter that modifies namesspaces allowing me to scope all the vendor libaries for my project without creating conflicts.

\Google_Client is registered in the global namespace, and I haven't been able to figure how using composer or the utility above to change that (without editing the vendor files manually). This is producing a conflict with a 3rd party plugin that is using an old version of google/apiclient.

While this isn't an issue for single composer projects, it's a massive problem for WordPress plugin development.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

unixkapl picture unixkapl  路  3Comments

armetiz picture armetiz  路  4Comments

bencromwell picture bencromwell  路  3Comments

Fredyy90 picture Fredyy90  路  3Comments

slaFFik picture slaFFik  路  5Comments