增加了插件优先级定义的支持,多个插件之间可以自行约定执行顺序,范例

Typecho_Plugin::factory('admin/menu.php')->navBar_1000 = array('HelloWorld_Plugin', 'render');

这个插件的执行优先级就是1000,默认的执行顺序是10,越大的数字越靠后执行
This commit is contained in:
joyqi 2014-01-09 00:56:51 +08:00
parent aa56382207
commit 1859e92e86

View File

@ -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);
}
/**