本文共 1751 字,大约阅读时间需要 5 分钟。
插件系统分为:
插件管理平台
插件探测
插件注册
插件调用
插件注销
path = $this->directory.'/'; } public function autoload(){ $interfaces = scandir($this->directory); unset($interfaces[0]); unset($interfaces[1]); foreach($interfaces as $interface) { //load all of the plugins $file = $this->path . $interface; if (@file_exists($file)) { include_once($file); $class = basename($interface, ".php"); if (class_exists($class)) { $this->$class = new $class($this); $vars = get_class_vars($class); $entity['name'] = $vars['name']; $entity['description'] = $vars['description']; $entity['author'] = $vars['author']; $entity['class'] = $class; $entity['methods'] = get_class_methods($class); $this->plugins[$class] = $entity; } } } } public function load($plugin){ $file = $this->path . $plugin . '.php'; if (@file_exists($file)) { include_once($file); $class = $plugin; if (class_exists($class)) { $this->$class = new $class($this); $vars = get_class_vars($class); $entity['name'] = $vars['name']; $entity['description'] = $vars['description']; $entity['author'] = $vars['author']; $entity['class'] = $class; $entity['methods'] = get_class_methods($class); $this->plugins[$class] = $entity; } } } public function show(){ print_r($this->plugins); }}
'; public static $name = 'Demo'; public static $description = 'Demo Simple'; public function __construct(){ } public function test(){ echo 'Hello world!!!'; }}
load('demo');$plugin->demo->test();echo '=============================';$plugin->autoload();$plugin->show();
原文出处:Netkiller 系列 手札
本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。