모듈 구조
잘 구성된 모듈 구조는 유지 관리 가능한 XOOPS 개발의 기본입니다. 이 가이드에서는 레거시 및 최신(PSR-4) 모듈 레이아웃을 모두 다룹니다.
표준 모듈 레이아웃
섹션 제목: “표준 모듈 레이아웃”레거시 구조
섹션 제목: “레거시 구조”modules/mymodule/├── admin/ # Admin panel files│ ├── index.php # Admin dashboard│ ├── menu.php # Admin menu definition│ ├── permissions.php # Permission management│ └── templates/ # Admin templates├── assets/ # Frontend resources│ ├── css/│ ├── js/│ └── images/├── class/ # PHP classes│ ├── Common/ # Shared utilities│ │ ├── Breadcrumb.php│ │ └── Configurator.php│ ├── Form/ # Custom form elements│ └── Handler/ # Object handlers├── include/ # Include files│ ├── common.php # Common initialization│ ├── functions.php # Utility functions│ ├── oninstall.php # Installation hooks│ ├── onupdate.php # Update hooks│ └── onuninstall.php # Uninstallation hooks├── language/ # Translations│ ├── english/│ │ ├── admin.php # Admin strings│ │ ├── main.php # Frontend strings│ │ ├── modinfo.php # Module info strings│ │ └── help/ # Help files│ └── other_language/├── sql/ # Database schemas│ └── mysql.sql # MySQL schema├── templates/ # Smarty templates│ ├── admin/│ └── blocks/├── blocks/ # Block functions├── preloads/ # Preload classes├── xoops_version.php # Module manifest├── header.php # Module header├── footer.php # Module footer└── index.php # Main entry point최신 PSR-4 구조
섹션 제목: “최신 PSR-4 구조”modules/mymodule/├── src/ # PSR-4 autoloaded source│ ├── Controller/ # Request handlers│ │ ├── ArticleController.php│ │ └── CategoryController.php│ ├── Service/ # Business logic│ │ ├── ArticleService.php│ │ └── CategoryService.php│ ├── Repository/ # Data access│ │ ├── ArticleRepository.php│ │ └── ArticleRepositoryInterface.php│ ├── Entity/ # Domain objects│ │ ├── Article.php│ │ └── Category.php│ ├── DTO/ # Data transfer objects│ │ ├── CreateArticleDTO.php│ │ └── UpdateArticleDTO.php│ ├── Event/ # Domain events│ │ └── ArticleCreatedEvent.php│ ├── Exception/ # Custom exceptions│ │ └── ArticleNotFoundException.php│ ├── ValueObject/ # Value types│ │ └── ArticleId.php│ └── Middleware/ # HTTP middleware│ └── AuthenticationMiddleware.php├── config/ # Configuration│ ├── routes.php # Route definitions│ ├── services.php # DI container config│ └── events.php # Event listeners├── migrations/ # Database migrations│ ├── 001_create_articles.php│ └── 002_add_indexes.php├── tests/ # Test files│ ├── Unit/│ └── Integration/├── templates/ # Smarty templates├── language/ # Translations (JSON)│ ├── en/│ │ └── main.json│ └── de/├── assets/ # Frontend resources├── module.json # Module manifest (XOOPS 4.0)└── composer.json # Composer config주요 파일 설명
섹션 제목: “주요 파일 설명”xoops_version.php (레거시 매니페스트)
섹션 제목: “xoops_version.php (레거시 매니페스트)”<?php$modversion = [ 'name' => 'My Module', 'version' => '1.0.0', 'description' => 'Module description', 'author' => 'Your Name', 'credits' => 'Contributors', 'license' => 'GPL 2.0', 'dirname' => basename(__DIR__), 'modicons16' => 'assets/images/icons/16', 'modicons32' => 'assets/images/icons/32', 'image' => 'assets/images/logo.png',
// System 'system_menu' => 1, 'hasAdmin' => 1, 'adminindex' => 'admin/index.php', 'adminmenu' => 'admin/menu.php', 'hasMain' => 1,
// Database 'sqlfile' => ['mysql' => 'sql/mysql.sql'], 'tables' => ['mymodule_items', 'mymodule_categories'],
// Templates 'templates' => [ ['file' => 'mymodule_index.tpl', 'description' => 'Index page'], ['file' => 'mymodule_item.tpl', 'description' => 'Item detail'], ],
// Blocks 'blocks' => [ [ 'file' => 'blocks/recent.php', 'name' => '_MI_MYMOD_BLOCK_RECENT', 'description' => '_MI_MYMOD_BLOCK_RECENT_DESC', 'show_func' => 'mymodule_recent_show', 'edit_func' => 'mymodule_recent_edit', 'template' => 'mymodule_block_recent.tpl', 'options' => '5|0', ], ],
// Config 'config' => [ [ 'name' => 'items_per_page', 'title' => '_MI_MYMOD_ITEMS_PER_PAGE', 'description' => '_MI_MYMOD_ITEMS_PER_PAGE_DESC', 'formtype' => 'textbox', 'valuetype' => 'int', 'default' => 10, ], ],];module.json(XOOPS 4.0 매니페스트)
섹션 제목: “module.json(XOOPS 4.0 매니페스트)”{ "name": "My Module", "slug": "mymodule", "version": "1.0.0", "description": "Module description", "author": "Your Name", "license": "GPL-2.0-or-later", "php": ">=8.2",
"namespace": "XoopsModules\\MyModule", "autoload": "src/",
"admin": { "menu": "config/admin-menu.php" },
"routes": "config/routes.php", "services": "config/services.php", "events": "config/events.php",
"templates": [ {"file": "index.tpl", "description": "Index page"} ],
"config": { "items_per_page": { "type": "int", "default": 10, "title": "@mymodule.config.items_per_page" } }}디렉토리 목적
섹션 제목: “디렉토리 목적”| 디렉토리 | 목적 |
|---|---|
admin/ | 관리 인터페이스 |
assets/ | CSS, JavaScript, 이미지 |
blocks/ | 블록 렌더링 기능 |
class/ | PHP 클래스(레거시) |
config/ | 구성 파일(최신) |
include/ | 공유된 포함 파일 |
language/ | 번역 파일 |
migrations/ | 데이터베이스 마이그레이션 |
sql/ | 초기 데이터베이스 스키마 |
src/ | PSR-4 소스 코드 |
templates/ | Smarty 템플릿 |
tests/ | 테스트 파일 |
모범 사례
섹션 제목: “모범 사례”- 별도의 우려사항 - 템플릿에서 비즈니스 로직을 제외하세요.
- 네임스페이스 사용 - 적절한 네임스페이스로 코드 구성
- PSR-4를 따르세요 - 표준 자동 로딩 규칙을 사용하세요.
- 구성 외부화 - 구성을 코드와 별도로 유지
- 문서 구조 - 구성을 설명하는 README 포함
관련 문서
섹션 제목: “관련 문서”- 모듈 개발 - 전체 개발 가이드
- 모범 사례/코드 구성 - 코드 구성 패턴
- 모듈 매니페스트 - 매니페스트 구성
- 데이터베이스/데이터베이스-스키마 - 데이터베이스 설계