mirror of
https://github.com/typecho/typecho.git
synced 2025-03-18 17:09:41 +01:00
fix #152
增加了插件优先级定义的支持,多个插件之间可以自行约定执行顺序,范例 Typecho_Plugin::factory('admin/menu.php')->navBar_1000 = array('HelloWorld_Plugin', 'render'); 这个插件的执行优先级就是1000,默认的执行顺序是10,越大的数字越靠后执行
This commit is contained in:
parent
aa56382207
commit
1859e92e86
@ -421,9 +421,38 @@ class Typecho_Plugin
|
||||
*/
|
||||
public function __set($component, $value)
|
||||
{
|
||||
$weight = 0;
|
||||
|
||||
if (strpos($component, '_') > 0) {
|
||||
$parts = explode('_', $component, 2);
|
||||
list($component, $weight) = $parts;
|
||||
$weight = intval($weight) - 10;
|
||||
}
|
||||
|
||||
$component = $this->_handle . ':' . $component;
|
||||
self::$_plugins['handles'][$component][] = $value;
|
||||
|
||||
if (!isset(self::$_plugins['handles'][$component])) {
|
||||
self::$_plugins['handles'][$component] = array();
|
||||
}
|
||||
|
||||
if (!isset(self::$_tmp['handles'][$component])) {
|
||||
self::$_tmp['handles'][$component] = array();
|
||||
}
|
||||
|
||||
foreach (self::$_plugins['handles'][$component] as $key => $val) {
|
||||
$key = floatval($key);
|
||||
|
||||
if ($weight > $key) {
|
||||
break;
|
||||
} else if ($weight == $key) {
|
||||
$weight += 0.001;
|
||||
}
|
||||
}
|
||||
|
||||
self::$_plugins['handles'][$component][strval($weight)] = $value;
|
||||
self::$_tmp['handles'][$component][] = $value;
|
||||
|
||||
ksort(self::$_plugins['handles'][$component], SORT_NUMERIC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user