While trying to prepare a workaround for #199 I've prepared a patch and set it up as an override of the affected class using files autoloading feature in Composer.
I was really surprised by the fact that the whole site immediately stopped working at all. It took me some time to find a reason, here is it:
This approach is used in WordPress because due to historical reasons, it has lots of possible entry points and some files contain code a not want to be called directly. However, most of this plugin is written using classes, and classes that follow PSR recommendations for autoloading can't be used as an entry point because they're expected to contain no other code in the file besides the class itself.
When I moved the file and added it as a separate entry for Composer autoloader - it, of course, blindly exits at the very early stage, effectively causing patching to be not possible without prior removal of this line.
While this approach does not affect the plugin itself besides such special cases - I would like to propose to remove these lines in class files.
While trying to prepare a workaround for #199 I've prepared a patch and set it up as an override of the affected class using
files
autoloading feature in Composer.I was really surprised by the fact that the whole site immediately stopped working at all. It took me some time to find a reason, here is it:
https://github.com/plausible/wordpress/blob/18bc986f75baffe97fdf7868afce7193b0ef056e/src/Helpers.php#L15
This approach is used in WordPress because due to historical reasons, it has lots of possible entry points and some files contain code a not want to be called directly. However, most of this plugin is written using classes, and classes that follow PSR recommendations for autoloading can't be used as an entry point because they're expected to contain no other code in the file besides the class itself.
When I moved the file and added it as a separate entry for Composer autoloader - it, of course, blindly exits at the very early stage, effectively causing patching to be not possible without prior removal of this line.
While this approach does not affect the plugin itself besides such special cases - I would like to propose to remove these lines in class files.