If anyone knows of a decent module engine, or sample script, please let me know. I'm having a rough time making a reloadable module engine for my latest project (almsot done).
What i need to do is load a module in at runtime (just like including).. and if possible, while the script is running, to have the option to be able to reload that included module, with an updated module.
include_once, and the rest of the functions work now for including the file, but there's no way to overwrite the existing function definitions... I need to literally flush the included module from memory, and reload it with a new copy.
If anyone has any leads, please, let me know.
Thanks in advance.
Module Engine
Moderator: General Moderators
- EvilWalrus
- Site Admin
- Posts: 209
- Joined: Thu Apr 18, 2002 3:21 pm
- Location: Springmont, PA USA
-
compound_eye
- Forum Newbie
- Posts: 15
- Joined: Wed Mar 17, 2004 8:42 pm
perhaps walrus i misunderstand,
but it seem to me that a way to go about this is if you have a class called Module: (bare bones here i don't know what these modules are for...
and
all your modules must inherit from this class:
Then if you have the name of your file and the name of the class of a module you can go:
...
...
this way you know that the basic module functions will at least exist before you call them, as they exist in the base class
this will module will echo the text 'Super' when go is called as you have over written the function go.
You can have as many different classes as you want and change them as many times as you want,
and each time you call $module->go() the behavior depend on which class you have just set $module to.
eventually you would probably want a function which takes a an arguement by reference, something like
buildModule (&$module)
which returns true if the module is succesfully created and false if it isn't, where module is set to the newly created module, then the rest of your code can do whatever you want with the module
is this what you mean?
but it seem to me that a way to go about this is if you have a class called Module: (bare bones here i don't know what these modules are for...
Code: Select all
<?php
class Module
{
function Module()
{
}
function go()
{
}
function stop()
{
}
}
?>all your modules must inherit from this class:
Code: Select all
<?php
class SuperModule extends Module
{
function SuperModule()
{
$this->Module();
}
function go()
{
echo "Super";
}
function stop()
{
echo "Stop Super";
}
}
?>Then if you have the name of your file and the name of the class of a module you can go:
Code: Select all
<?php
$className = 'SuperModule';
$classFile = 'SuperModule.class.php';
?>...
Code: Select all
<?php
if(!empty($className) and !empty($classFile))
{
if(file_exists($classFile))
{
require_once($classFile);
{
if (class_exists($className))
{
$module = new $className(); //could also be done with arguements
if (is_a($module, 'Module'))
{
$module->go();
}
}
}
}
}
?>this will module will echo the text 'Super' when go is called as you have over written the function go.
You can have as many different classes as you want and change them as many times as you want,
and each time you call $module->go() the behavior depend on which class you have just set $module to.
eventually you would probably want a function which takes a an arguement by reference, something like
buildModule (&$module)
which returns true if the module is succesfully created and false if it isn't, where module is set to the newly created module, then the rest of your code can do whatever you want with the module
is this what you mean?