Hi!
I'm writing a CMS, but I've got a problem. I have a mysql table called modules. Modules are similar to Wordpress' plug-ins, or Drupal Modules. Some modules require functions of other modules. I'm now writing the part which includes the modules. Here's my code:
//Load modules
$res_modules = mysql_query("SELECT * FROM ".$db_prefix."modules WHERE enabled=1");
echo mysql_error();
while($row_modules = mysql_fetch_array($res_modules))
{
//Check if module exists
if(file_exists("MODULES/".$row_modules["name"]."/module.php"))
{
require_once("MODULES/".$row_modules["name"]."/module.php");//Include module
}
else//Module does not exists...
{
//...so deactivate it
mysql_query("UPDATE ".$db_prefix."modules SET enabled=0 WHERE name='".$row_modules["name"]."'");
}
}
Does someone knows an algorithm that allows some modules (those who require other modules) to be included after other modules? The actual big problem is, that modules can also require each other's functions (module x can use functions of module y and vice versa (which could result in a stack overflow :P)). The modules which require other modules have an array called $req_modules in their module.php file. Example:
$req_modules = array("page", "comments");
Thanks!