Sign in to follow this  
  • entries
    43
  • comments
    51
  • views
    31883

The Solution

Sign in to follow this  

212 views

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]
Sign in to follow this  


3 Comments


Recommended Comments

You could have a MySQL database manage what "plugins" are loaded into the system and just include those when needed.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now