Editing Vendor Methods without Overwriting them in the Future on composer updates

If I have a added a Feature/Plugin via composer to my Kirby 3 Website and I want to edit a Method which is beeing used in a Class of said installed composer package. How would I do that with Kirby 3?

Editing the file directly wouldn’t be the best, because If I was to update all composer packages my rewritten Method would also be changed.

In other CMS/Frameworks i’ve worked with in the past I was able to create a Class somewhere with the same name of the Vendor Class and overwrite the Method that way. Whats the correct way to do this in Kirby?

when using composer with the optimized option you get a classmap file. tricking that might be difficult. a solution might be monkey-patching. read more about it at stackoverflow. you can do that with php 7 and runkit7 which must be installed as a php extension.


may i ask what feature/plugin you are trying to change? maybe there is another way.

I manage my Kirby dependencies via git submodules. Then you can create a separate branch in the plugin’s submodule to track your changes. When you pull in changes from the origin to update the plugin, you can merge your branch with the updated version and you’re good to go.

I like how this works.

I was able to do this without overriding the Methods as I’ve planned before by fixing up some plugin settings. Therefor i dont need to do this anymore.