0

I'm developing WordPress plugins. Each plugin in WordPress is a separate piece of software, there's no dependency management in WordPress, so plugins are not aware of other plugins and their dependencies. The problem with PHP is that all dependencies installed with Composer are global.

Let's imagine that my plugin uses a popular PHP library - Symfony, or Guzzle, let's say. More popular library = greater possibility of a conflict.

Is there any way to avoid conflicts? I was searching the web for Composer sandbox solutions or similar, but I didn't find anything - so I'm afraid the solution doesn't exist.

On the other hand, I can imagine a solution that wouldn't involve any rocket science. I can imagine a pre-deployment build script that would scan the /vendor directory and prefix all the dependencies with a custom prefix.

Is there any tool or any technique that would provide a dependences isolations in PHP?

rob006
  • 21,383
  • 5
  • 53
  • 74
wube
  • 923
  • 2
  • 10
  • 22
  • @rob006 True. There's an answer to my question in that topic. The tool I'm looking for is php-scoper. Thanks. – wube Dec 23 '18 at 09:45
  • I have added more PHP prefixing tools to the referenced answer [3rd party dependency conflict in developing Wordpress Plugin](https://stackoverflow.com/questions/50144816/3rd-party-dependency-conflict-in-developing-wordpress-plugin). Namely: humbug/php-scoper, Interfacelab/namespacer, coenjacobs/mozart, and PHP-Prefixer. – Anibal Sanchez Sep 07 '21 at 08:07

2 Answers2

0

Is there any tool or any technique that would provide a dependences isolations in PHP?

I think that it could be an answer on your question: How to get multiple vendor directories with composer?

Maxim
  • 2,233
  • 6
  • 16
  • No. It's not a solution. I'd like to avoid conflict with dependencies loaded by other plugins - authored by other people. I'm not asking for a solution for the site I fully control - In such case I would simply install the whole WordPress ecosystem with Composer - using a tool like Bedrock: https://roots.io/bedrock/ – wube Dec 23 '18 at 09:48
0

Every library comes with its own namespace that is defined by the author. If you happen to use the same library on different plugins, you might need to fork and change the namespace of the library that you want to include in your plugin, or just use class_exists.

  • Thanks. @rob006 has already answered. The tool I'm looking for is php-scoper. class_exist doesn't solve a problem because the class might exist, but the dependency's version might be different from what I need. – wube Dec 23 '18 at 09:50