bugo/smf-compat
Composer 安装命令:
composer require bugo/smf-compat
包简介
Wrappers for global variables and deprecated functions in SMF
README 文档
README
Description
This package is designed to prepare existing SMF 2.1 modifications for the upcoming migration to SMF 3.0.
The included utility classes eliminate the need for global variables in your modification code.
As a result, your mods will be compatible with both SMF 2.1 and 3.0 with minimal adjustments.
Installation
In your modification's root directory, execute:
composer require bugo/smf-compat
Then, include autoload.php in app.php (or a similar entry point):
require_once __DIR__ . '/vendor/autoload.php';
Usage
Legacy code
<?php class Example { public function method1() { global $txt; var_dump($txt['hello_world']); } public function method2() { global $user_info, $modSettings; var_dump($user_info['name']); var_dump($modSettings); } }
New code
<?php use Bugo\Compat\Lang; use Bugo\Compat\User; use Bugo\Compat\Config; class Example { public function method1() { var_dump(Lang::$txt['hello_world']); } public function method2() { var_dump(User::$me->name); var_dump(Config::$modSettings); } }
After upgrading to SMF 3.0, you only need to replace the class references. For example:
-use Bugo\Compat\Lang; +use SMF\Lang; -use Bugo\Compat\User; +use SMF\User; -use Bugo\Compat\Config; +use SMF\Config; -use Bugo\Compat\Db; +use SMF\Db\DatabaseApi as Db; // etc.
Alternatively, you can leave the code as is. In this case, your modification will maintain compatibility with both SMF versions.
List of suggested replacements
Below is a non-exhaustive list of variable and function mappings.
Global variables
| Legacy code (SMF 2.1.x) | New code (SMF 3.0) |
|---|---|
$board |
Board::$id |
$boards |
Board::$loaded |
board_info |
Board::$info |
$modSettings |
Config::$modSettings |
$mbname |
Config::$mbname |
$scripturl |
Config::$scripturl |
$boardurl |
Config::$boardurl |
$boarddir |
Config::$boarddir |
$sourcedir |
Config::$sourcedir |
$cachedir |
Config::$cachedir |
$db_server |
Config::$db_server |
$db_name |
Config::$db_name |
$db_user |
Config::$db_user |
$db_passwd |
Config::$db_passwd |
$db_type |
Config::$db_type |
$db_prefix |
Config::$db_prefix |
$language |
Config::$language |
$cache_enable |
Config::$cache_enable |
$db_show_debug |
Config::$db_show_debug |
$db_count |
Db::$count |
$db_cache |
Db::$cache |
$txt |
Lang::$txt |
$editortxt |
Lang::$editortxt |
$helptxt |
Lang::$helptxt |
$forum_copyright |
Lang::$forum_copyright |
$settings |
Theme::$current->settings |
$options |
Theme::$current->options |
$topic |
Topic::$id |
$user_info |
User::$me |
$user_profile |
User::$profiles |
$context |
Utils::$context |
$smcFunc |
Utils::$smcFunc |
Functions
| Legacy code (SMF 2.1.x) | New code (SMF 3.0) |
|---|---|
saveDBSettings |
ACP::saveDBSettings |
prepareDBSettingContext |
ACP::prepareDBSettingContext |
createAttachment |
Attachment::create |
removeAttachments |
Attachment::remove |
parse_bbc |
BBCodeParser::load()->parse |
cache_get_data |
CacheApi::get |
cache_put_data |
CacheApi::put |
clean_cache |
CacheApi::clean |
getBirthdayRange |
Calendar::getBirthdayRange |
getEventRange |
Calendar::getEventRange |
getHolidayRange |
Calendar::getHolidayRange |
getTodayInfo |
Calendar::getTodayInfo |
getCalendarList |
Calendar::getCalendarList |
getCalendarGrid |
Calendar::getCalendarGrid |
updateSettings |
Config::updateModSettings |
updateSettingsFile |
Config::updateSettingsFile |
create_control_richedit |
new Editor |
fatal_error |
ErrorHandler::fatal |
fatal_lang_error |
ErrorHandler::fatalLang |
log_error |
ErrorHandler::log |
add_integration_function |
IntegrationHook::add |
call_integration_hook |
IntegrationHook::call |
createList |
new ItemList |
censorText |
Lang::censorText |
getLanguages |
Lang::get |
loadLanguage |
Lang::load |
sentence_list |
Lang::sentenceList |
tokenTxtReplace |
Lang::tokenTxtReplace |
logAction |
Logging::logAction |
loadEmailTemplate |
Mail::loadEmailTemplate |
sendmail |
Mail::send |
getBoardList |
MessageIndex::getBoardList |
getNotifyPrefs |
Notify::getNotifyPrefs |
constructPageIndex |
new PageIndex |
preparsecode |
Parser::sanitize |
un_preparsecode |
Parser::getEditableString |
memoryReturnBytes |
Sapi::memoryReturnBytes |
sm_temp_dir |
Sapi::getTempDir |
set_time_limit |
Sapi::setTimeLimit |
checkSubmitOnce |
Security::checkSubmitOnce |
addJavaScriptVar |
Theme::addJavaScriptVar |
addInlineCss |
Theme::addInlineCss |
addInlineJavaScript |
Theme::addInlineJavaScript |
loadCSSFile |
Theme::loadCSSFile |
loadJavaScriptFile |
Theme::loadJavaScriptFile |
loadEssentialThemeData |
Theme::loadEssential |
loadTemplate |
Theme::loadTemplate |
allowedTo |
User::$me->allowedTo |
checkSession |
User::$me->checkSession |
isAllowedTo |
User::$me->isAllowedTo |
membersAllowedTo |
User::getAllowedTo |
updateMemberData |
User::updateMemberData |
JavaScriptEscape |
Utils::escapeJavaScript |
obExit |
Utils::obExit |
redirectexit |
Utils::redirectexit |
send_http_status |
Utils::sendHttpStatus |
shorten_subject |
Utils::shorten |
smf_chmod |
Utils::makeWritable |
smf_json_decode |
Utils::jsonDecode |
get_mime_type |
Utils::getMimeType |
un_htmlspecialchars |
Utils::htmlspecialcharsDecode |
fetch_web_data |
WebFetchApi::fetch |
timeformat |
Time::stringFromUnix |
SSI functions
All functions in SSI.php that were called via ssi_function_name prior to SMF 3.0 are now accessed as ServerSideIncludes::function_name.
Working with the database
In compatibility mode, you can still use Utils::$smcFunc['db_query'], etc. However, we have also introduced a new DatabaseApi class, which features a static property $db representing the current database engine.
The methods of this class correspond to the functions in Utils::$smcFunc, but without the db_ prefix.
Here are examples of three commonly used functions:
| Legacy code (SMF 2.1.x) | New code (SMF 3.0) |
|---|---|
global $smcFunc; |
use Bugo\Compat\Db\DatabaseApi as Db; |
$result = $smcFunc['db_query']('', /* Your SQL */, []) |
$result = Db::$db->query('', /* Your SQL */, []) |
$rows = $smcFunc['db_fetch_assoc']($result) |
$rows = Db::$db->fetch_assoc($result) |
$smcFunc['db_free_result']($result) |
Db::$db->free_result($result) |
Examples of Integration
bugo/smf-compat 适用场景与选型建议
bugo/smf-compat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 314 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「smf helpers」 「smf compatibility」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bugo/smf-compat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bugo/smf-compat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bugo/smf-compat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Polyfill for the New Relic PHP extension
Compatibility layer for emulating enumerations in PHP < 8.1 and native enumerations in PHP >= 8.1
HTML and form generation
Adds various plugin compatibility fixes into SnapWP
Falsy helps you manage half-truths with PHP
Helper class for SMF mods
统计信息
- 总下载量: 314
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-03