XMF Framework
2.5.x ✅ 4.0.x ✅
The XOOPS Module Framework (XMF) is a powerful library designed to simplify and standardize XOOPS module development. XMF provides modern PHP practices including namespaces, autoloading, and a comprehensive set of helper classes that reduce boilerplate code and improve maintainability.
What is XMF?
Section titled “What is XMF?”XMF is a collection of classes and utilities that provide:
- Modern PHP Support - Full namespace support with PSR-4 autoloading
- Request Handling - Secure input validation and sanitization
- Module Helpers - Simplified access to module configurations and objects
- Permission System - Easy-to-use permission management
- Database Utilities - Schema migration and table management tools
- JWT Support - JSON Web Token implementation for secure authentication
- Metadata Generation - SEO and content extraction utilities
- Admin Interface - Standardized module administration pages
XMF Component Overview
Section titled “XMF Component Overview”graph TB subgraph XMF["XMF Framework"] direction TB subgraph Core["Core Components"] Request["🔒 Request<br/>Input Handling"] Module["📦 Module Helper<br/>Config & Handlers"] Perm["🔑 Permission<br/>Access Control"] end
subgraph Utils["Utilities"] DB["🗄️ Database<br/>Schema Tools"] JWT["🎫 JWT<br/>Token Auth"] Meta["📊 Metagen<br/>SEO Utils"] end
subgraph Admin["Admin Tools"] AdminUI["🎨 Admin UI<br/>Standardized Pages"] Icons["🖼️ Icons<br/>Font Awesome"] end end
subgraph Module["Your Module"] Controller["Controller"] Handler["Handler"] Template["Template"] end
Controller --> Request Controller --> Module Controller --> Perm Handler --> DB Template --> AdminUI
style XMF fill:#e3f2fd,stroke:#1976d2 style Core fill:#e8f5e9,stroke:#388e3c style Utils fill:#fff3e0,stroke:#f57c00 style Admin fill:#fce4ec,stroke:#c2185bKey Features
Section titled “Key Features”Namespaces and Autoloading
Section titled “Namespaces and Autoloading”All XMF classes reside in the Xmf namespace. Classes are automatically loaded when referenced - no manual includes required.
use Xmf\Request;use Xmf\Module\Helper;
// Classes load automatically when used$input = Request::getString('input', '');$helper = Helper::getHelper('mymodule');Secure Request Handling
Section titled “Secure Request Handling”The Request class provides type-safe access to HTTP request data with built-in sanitization:
flowchart LR subgraph Input["Raw Input"] GET["$_GET"] POST["$_POST"] REQUEST["$_REQUEST"] end
subgraph XMF["Xmf\\Request"] Validate["Type Validation"] Sanitize["Sanitization"] Default["Default Values"] end
subgraph Output["Safe Output"] Int["getInt()"] Str["getString()"] Email["getEmail()"] Bool["getBool()"] end
GET --> XMF POST --> XMF REQUEST --> XMF XMF --> Int XMF --> Str XMF --> Email XMF --> Bool
style Input fill:#ffcdd2,stroke:#c62828 style XMF fill:#fff3e0,stroke:#f57c00 style Output fill:#c8e6c9,stroke:#2e7d32use Xmf\Request;
$id = Request::getInt('id', 0);$name = Request::getString('name', '');$email = Request::getEmail('email', '');Module Helper System
Section titled “Module Helper System”The Module Helper provides convenient access to module-related functionality:
$helper = \Xmf\Module\Helper::getHelper('mymodule');
// Access module configuration$configValue = $helper->getConfig('setting_name', 'default');
// Get module object$module = $helper->getModule();
// Access handlers$handler = $helper->getHandler('items');Permission Management
Section titled “Permission Management”The Permission-Helper simplifies XOOPS permission handling:
$permHelper = new \Xmf\Module\Helper\Permission();
// Check user permissionif ($permHelper->checkPermission('view', $itemId)) { // User has permission}Documentation Structure
Section titled “Documentation Structure”Basics
Section titled “Basics”- Getting-Started-with-XMF - Installation and basic usage
- XMF-Request - Request handling and input validation
- XMF-Module-Helper - Module helper class usage
Recipes
Section titled “Recipes”- Permission-Helper - Working with permissions
- Module-Admin-Pages - Creating standardized admin interfaces
Reference
Section titled “Reference”- JWT - JSON Web Token implementation
- Database - Database utilities and schema management
- Metagen - Metadata and SEO utilities
Requirements
Section titled “Requirements”- XOOPS 2.5.8 or later
- PHP 7.2 or later (PHP 8.x recommended)
Installation
Section titled “Installation”XMF is included with XOOPS 2.5.8 and later versions. For earlier versions or manual installation:
- Download the XMF package from the XOOPS repository
- Extract to your XOOPS
/class/xmf/directory - The autoloader will handle class loading automatically
Quick Start Example
Section titled “Quick Start Example”Here is a complete example showing common XMF usage patterns:
<?phpuse Xmf\Request;use Xmf\Module\Helper;use Xmf\Module\Helper\Permission;
// Get module helper$helper = Helper::getHelper('mymodule');
// Get configuration values$itemsPerPage = $helper->getConfig('items_per_page', 10);
// Handle request input$op = Request::getCmd('op', 'list');$id = Request::getInt('id', 0);
// Check permissions$permHelper = new Permission();if (!$permHelper->checkPermission('view', $id)) { redirect_header('index.php', 3, 'Access denied');}
// Process based on operationswitch ($op) { case 'view': $handler = $helper->getHandler('items'); $item = $handler->get($id); // ... display item break; case 'list': default: // ... list items break;}Resources
Section titled “Resources”#xmf #xoops #framework #php #module-development