Page 1 of 1

Mod Program With Dependencies - I'm Stumped!

Posted: Sun Aug 28, 2011 12:35 am
by KCAstroTech
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.

Re: Mod Program With Dependencies - I'm Stumped!

Posted: Mon Aug 29, 2011 1:12 am
by getmizanur
i do not know how you expect us here to resolve your problem if you have not submitted any code or error messages.

my guess is, if other mods have dependencies that the original coder did not account for then you have to add it.

> 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
stop being lazy. your alternative is either it is not working or write something from scratch for your needs.

Re: Mod Program With Dependencies - I'm Stumped!

Posted: Mon Aug 29, 2011 11:21 pm
by KCAstroTech
My apologies, it was late when I wrote that and I guess I didn't make it clear. I'm not trying to be lazy and I'm not looking for exact code or anything I'm looking for ideas to solve a problem (I presume I'm in the right area for this).

The program in question is PHP RCON by Ashus (http://ashus.ashus.net/viewtopic.php?f=4&t=27). PHP RCON is a great web based RCON management program for Call Of Duty and other gaming servers. What I've done is expand on his program, adding new features and integrating it with my gaming clan's forum. Unfortunately, the way he wrote the code didn't make it very easy to add to it, so I ended up inserting my code in at various places in his scripts to achieve my desired outcome. Ashus has since come out with several updates to his code that make it harder still to properly go through and insert all my updated changes and code. I therefore came up with my own solution to simply insert one line in his init.php file that initializes my currently simple mod.php script which in turn looks at the page being requested, then puts a register_shutdown_function() that will call the appropriate mod(s) for that page. Once PHP_RCON is done and ready to post the page, I take what it is trying to submit, modify it by adding additional content (lots of it), then passing the updated content to the browser. This way, if he comes out with another update it should have no effect on my scripts and all I have to do is put one line back in his init file.

The problem I've run into is that I broke my code up into several smaller mods that each have a specific function, but I've got one mod in particular that needs to run after two other mods have run. I know I can hard code this in, but I would like to make this easily expandable so that others can add their own mods or expand on mine. To do that I know there has to be some formula, framework, or script out there, that can take a group of xml, php, or some sort of configuration files, then if a dependency is specified in any of the config files, it should know to run them in order of dependencies so that they execute properly.

Does that make sense? I have spent hours looking for something that might put me down the right path. I am by no means afraid of work nor research, but in this topic I just can't seem to find what I am looking for and was hoping someone here has come across a similar situation and might be able to provide some guidance. The closest thing I've found to a dependency structure / maping script that looks like it might work is PHP Crafty (http://phpcrafty.sourceforge.net/documentation.php) though their download link is broken and I have no way of examining and testing it.

If I cannot find a solution I will simply end up hard coding everything into my mod.php file, though I'd rather learn and find a way to do what I know should be able to be done. Any and all advice is welcome.

Thanks!