🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

The Solution

posted in Rarely Spoken
Published May 27, 2005
Advertisement
I've come up with a solution to my problem although I am not terribly satisfied with it. I kept the new field in the module registration table because it made life easier when getting the functions to talk to the modules (and safer since I no longer have to rely on include_once() and require_once() to execute anything) and I split up the administration module.

Splitting the administration module is the part that I dont like. I removed RegisterModule(), UnregisterModule(), and ExtractFunctions() and placed them in a new file, modules.php, which isnt associated with any specific module (like my database and session manager classes). Each module returns the name of the function that will go in the new Function field of the regitration database and I will guarantee that the first time a module is included during its registration is in RegisterModule(). RegisterModule() is the only function that cares about the return value which is why I need to make the guarantee. I dont like that I still rely on the module returning this function no do I like even storing a name of a function that will return the interface functions to the module. Finally, I dont like that RegisterModule(), UnregisterModule(), and ExtractFunctions() are not in the main admin module even though they are the main admin functions.

I wish that PHP had packages or namespaces and that I could use the reflection API to get a list of classes contained within that package. If I had that then my solution would be this:

I would create a module interface, IModule, that all modules would be required to implement. I would then load the package and use reflection to find the class within the module that implements IModule. The end.

I guess the closest thing to that would be to require each module PHP file to contain a single class whose name followed a strict set of rules so that you could use ReflectionClass on that class. That class would contain a subclass that implemented IModule and that subclass would be your interface.

I'm using PHP 4 so I cant do that either. [crying]
Previous Entry Oh No!
0 likes 3 comments

Comments

Rob Loach
You could have a MySQL database manage what "plugins" are loaded into the system and just include those when needed.
May 27, 2005 12:17 PM
Colin Jeanne
How would that be different from the registration database?
May 27, 2005 04:56 PM
jumpjumpjump
Take a look at how mediawiki does namespaces. :) Works on php4 too.
May 27, 2005 08:36 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

4E6 PyGame

1404 views

4E5

1138 views

Happy Yesterday!

1093 views

Another Game

1305 views

Merry Christmas!

1073 views

Hello There

1072 views

Yay!

1088 views
Advertisement