PHP Modular Programming

Good afternoon!

Not so long ago I decided to create a small engine for quickly developing sites for myself, so that I didn’t have to finish it: everything was ready, just connect modules and plugins…

And here’s the problem, I just can’t think of a better way. There are folders

-admin
-ModAndPlugin

There is a file in the -adminfolder that scans the -ModAndPluginfolder and gets an array of its subfolders

array([0]=>"./ModAndPlugin/user/" , [1]=>"./ModAndPlugin/maillent/")

How to connect modules?

Give links to topics where this has already been discussed, or a finished piece of code.


Answer 1, authority 100%

function __autoload($className){
  $filename = "-ModAndPlugin/".$className.".class.php";
  if(!file_exists($filename)){
    die("lack of required module");
  }else{
    include $filename;
  }
}

And you don’t have to worry too much.
When accessing the constructor of a non-existent class, its file will try to be loaded.


Answer 2, authority 50%

Why don’t you store modules and plugins in a folder, and describe them in the database, and connect them with links?
Example :

/system/exts/mod/modulename/index.php
/system/exts/pls/pluginname/index.php

link : ?module=modulename

and as an option to connect it with protection against arbitrary launch of functions:

//$allow_func -    ,   
$allow_func['show_page']        =   'ok';
$allow_func['users']        =   'ok';
#
if (!function_exists($module)) {
    if (@file_exists("./system/extensions/modules/$module/$module".'.php')) {
        include "./system/extensions/modules/$module/$module".'.php';
        $allow_func[$module]    =   'ok';//  ,          
    } else {
        return '<strong>  123</strong><br />';
    }
}
if ($allow_func[$module] == 'ok') {
    $module();
}