New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefix all our vendor libs #16905
Comments
This could be a lot of work and cause a lot of breaking changes. It will save a lot of time in the long run as Matomo for WordPress will be more stable and have less compatibility issues. The effort it takes to do this one, might not be worth it though. Depends though how much work it really is? |
Will check the level of work needed before confirming we will do it in 5.0.0 |
Using the proposed logic, is it possible to only prefix some vendor libraries to reduce the effort / amount of work on this issue so that we get a good ration on effort vs value? Or would above solution only be able to prefix all vendor libraries? The libraries that cause the most issues are typically
The biggest library that's causing issues is likely Twig. The goal would be to keep breaking changes small so we need to change less code and reduce the amount of possible regressions etc. How much effort would it be to implement this feature? And if it is a lot of effort, is there a way to reduce the effort significantly while still getting a lot of the value? |
@tsteur I looked into this issue and I couldn't think of another way to accomplish it than using php-scoper (specifically I couldn't find a simple, dynamic solution). Since a dynamic, runtime solution isn't possible, I think the best alternative is automation, specifically:
And for BC:
What do you think? Are these deliverables sound? If so I can start working on this. |
👍
Sounds good. Although not sure how many usages are used and if it could be done manually. If this worked automatically that be awesome.
If we include this in Matomo 5, maybe we could skip the BC part? Although maybe this is needed during the update process when someone updates from an older Matomo On-Premise version when some files are already loaded and try to use the old naming and then can't find the file. I'm mostly worried about this that plugins then work with On-Premise but not with Matomo for WordPress because in a plugin it was missed to update a use statement and it's hard to find these errors. Most developers etc wouldn't notice the problem but WordPress users then run into the problem. Not sure it's clear what I mean? |
I really doubt that a script to automatically prefix any vendor class namespace is a solution we should go with. That will always have the risk that updating a vendor lib could break everything. There are a lot cases that might never be detectable using a script. Like dynamic instances of classes built from string variables or when class names are compared in the code and similar stuff. I'm really not sure if the benefits of doing that are higher than the pain we might have one day after doing that. |
This was mostly just for third party plugin developers that may not update their code. I suppose if it's not important those plugins just automatically work. (Though from @sgiehl's comment it seems this sort of autoloader could have another potential use, see below.)
How often are composer libraries updated? Would tests fail if updating a vendor lib caused a problem?
This could certainly be an issue. From the php-scoper docs it says it has "limited support" for changing such code. In this case the BC autoloader would be useful for making sure things still work in that case (it would be disabled in tests).
I don't know how php-scoper exactly works, but couldn't it potentially change |
Patch and in some cases minor releases are updated automatically when they are released. We have a action to run a
That could work for Matomo itself. But it might produce the same issues we are trying to solve for Matomo for Wordpress, as it might load the libs from another plugin if the un-prefixed names are used.
That depends if |
Note that I believe we'd get the biggest benefit by looking at the libs in #16905 (comment) and we don't need to replace all of them if that makes things easier. It wouldn't need to work for the less lib from my perspective as this library is used more rarely by other plugins. Even only changing the namespace for twig and/or Monolog could be a win. Most incompatibilities seem to come from Twig and monolog see https://matomo.org/faq/wordpress/which-plugins-is-matomo-for-wordpress-known-to-be-not-compatible-with/ but we also have quite a few cases around PHP-DI. PHP-Scoper should for example prefix a I assume if we prefix for example php-di and other dependencies want to use PHP-DI without a prefix, then it could maybe cause an issue for example. So maybe it would only work for twig and monolog. If it doesn't replace all the namespaces correctly then of course this be a problem and it creates more problems than it solves. And it could be also a problem in the future if there's a change in a library that php-scoper can't replace automatically. |
@tsteur So is it worth trying now with twig/monolog? If so I'll get started. |
be great to try it from my perspective 👍 |
If we limit this to only a couple of libs and don't prefix all our libs (as the title says) it might be feasible. |
FYI just now we got a report that WP-Rocket started using Monolog 2 and we're now incompatible with it see https://wordpress.org/support/topic/archive-error-with-wp-rocket/ . WP-Rocket is the 7th most popular WordPress plugin and we're using it as well (https://en.wikipedia.org/wiki/WP_Rocket#Usage) and runs on millions of sites (source) Updating our monolog to version 2 wouldn't help much either as we then become incompatible with many other popular plugins. |
@tsteur Can't we make Matomo compatible with both monolog versions? I guess there are some changes we would need to apply to make Matomo compatible, but we could maybe try to detect the monolog version being used and use different code in Matomo then. |
I don't know if we can and what that would mean. I guess that would then also involve scanning all WordPress plugins to see what monolog version which plugin uses? |
I haven't had a look at the required changes to update Monolog to version 2 in our codebase, but my idea was, to simply check the monolog version using |
@tsteur I do not want to complicate this thread any more than it is already, but in case it's worth knowing, I should have a proof of concep of a prefixing workflow (with twig) for evaluation by end of week at the latest. |
@diosmosis we discussed it would be great to also prefix PHP-DI if any possible. Because namespaced functioned can't be aliased (like class_alias), we'll then need a wrapper like We'll then test the composer install that things still work nicely when Matomo is installed via composer. |
Ping @diosmosis |
@tsteur this has been done for a while now |
Has the conflict between Matomo and WP Rocket been resolved with version 5.0? |
It looks like it might be compatible now, @schwarzpunkt, but not because of Matomo 5. Best to check/keep an eye on the Matomo for Wordpress issue #1010. |
Closing this issue here, as we won't prefix the vendor libs in Matomo. |
see matomo-org/matomo-for-wordpress#233
Need to do this in a major release. Should investigate if we can make this work. We'd only prefix vendor libraries. Could use
Matomo
orMatomoLib
or something as prefix. egDi\object
then becomesMatomo\Di\object
. To have it actually useful in development too we would put this into the composer json similar to google/site-kit-wp#612 see eg https://github.com/google/site-kit-wp/pull/730/filesMore details in #233
The text was updated successfully, but these errors were encountered: