Mod Program With Dependencies - I'm Stumped!
Posted: Sun Aug 28, 2011 12:35 am
Ok so here is the situation, I've got someone else's code that I am trying to write a mod program for that works like this:
User calls page -> server calls mod init -> mod init gets the name of the called page then assembles a process queue of mods to run for that page -> original code now runs and assembles the page then calls exit -> using the register_shutdown_function() the mod is again called and the queue is processed, doing something with the assembled page prior to sending it to the browser.
Make sense? Essentially I am trying to add to the page without modifying the original code so that as the original author submits a new update, I don't have to go through and find all of the places I modified the old code and make it work with the new code. With just 1 mod in the queue this works great... However, I need to have other mods that have dependencies, e.g. before running the code for mod 1, run mod 2, and before running mod 3 BOTH mod 1 and mod 2 need to be run without errors, otherwise return the original code unmodified.
The problem I'm having is that I can't find any examples of similar situations and can't think of a simple solution that doesn't have a heavy impact on the server as it tries to figure out the dependency structure. What I ultimately need is a some method whereby I can easily add mods for various pages and have the mod library assemble the process queue taking into consideration dependencies. Also, the mod library needs to be flexible as I will likely add additional mods down the road.
Any ideas? I looked into dependency injection but it is late and it made my head hurt and I am not sure that is what I need.
User calls page -> server calls mod init -> mod init gets the name of the called page then assembles a process queue of mods to run for that page -> original code now runs and assembles the page then calls exit -> using the register_shutdown_function() the mod is again called and the queue is processed, doing something with the assembled page prior to sending it to the browser.
Make sense? Essentially I am trying to add to the page without modifying the original code so that as the original author submits a new update, I don't have to go through and find all of the places I modified the old code and make it work with the new code. With just 1 mod in the queue this works great... However, I need to have other mods that have dependencies, e.g. before running the code for mod 1, run mod 2, and before running mod 3 BOTH mod 1 and mod 2 need to be run without errors, otherwise return the original code unmodified.
The problem I'm having is that I can't find any examples of similar situations and can't think of a simple solution that doesn't have a heavy impact on the server as it tries to figure out the dependency structure. What I ultimately need is a some method whereby I can easily add mods for various pages and have the mod library assemble the process queue taking into consideration dependencies. Also, the mod library needs to be flexible as I will likely add additional mods down the road.
Any ideas? I looked into dependency injection but it is late and it made my head hurt and I am not sure that is what I need.