#4 - Module Loader

Data: 2018-04-14 12:00 - PHP

Simple module loader that includes the index files of all modules.

<?php
class ModuleLoader {
    public static function getModuleDir($module) {
        return __DIR__ . '/modules/' . $module . '/';
    }

    public static function loadModules() {
        $modulesDir = dir(__DIR__ . '/modules/');
        while (($moduleDirName = $modulesDir->read()) !== false) {
            $moduleDir = __DIR__ . '/modules/' . $moduleDirName;
            if ($moduleDirName == '.' || $moduleDirName == '..' || filetype($moduleDir) != 'dir')
                continue;
            include $moduleDir . '/index.php';
        }
        $modulesDir->close();
    }
}

Previous snippet | Next snippet