interface IPlugin{
static function getname();
static function init();
static function getMenu();
}
<?php
Class Welcome implements IPlugin{
static function getname(){
return 'Welcome (Plugin)';
}
static function getMenu(){
return array(
'text'=>'插件1′,
'href'=>'http://www.google.com'
);
}
static function init(){
echo self::getname() . " 载入中…<br />";
}
}
?>
<?php
Class ShowAD implements IPlugin{
static function getname(){
return 'Show AD (Plugin)';
}
static function getMenu(){
return array(
'text'=>'插件2′,
'href'=>'http://www.live.com'
);
}
static function init(){
echo self::getname() . " 载入中…<br />";
}
}
?>
$menu[] = array( 'text'=>'首页', 'href'=>'/test.php' );
$pluginPath = $_SERVER['DOCUMENT_ROOT'] . '/plugin';
$dirHd = opendir($pluginPath);
while ($file = readdir($dirHd)){
$pluginFilePath = $pluginPath . '/' . $file;
if($file!='.' && $file!='..' && is_file($pluginFilePath)){
include "$pluginFilePath";
}
}
// 反射执行方法(注入菜单)
foreach (get_declared_classes() as $class){
$refClass = new ReflectionClass($class);
if($refClass->implementsInterface('IPlugin')){
//插件初始化
$refClass->getMethod('init')->invoke(null);
//获取注入菜单
$menuItem = $refClass->getMethod('getMenu')->invoke(null);
//合并菜单项
$menu = array_merge($menu, array($menuItem));
}
}
foreach ($menu as $m){
echo "<a href='{$m['href']}'>{$m['text']}</a> ";
}
$refClass = new ReflectionClass($class);
$menuItem = $refClass->getMethod('getMenu')->invoke(null);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有