system_list()函数的目的是根据传入的资源类型,返回一个数组列表:

function system_list($type) { ... ... }

参数$type支持下面三种类型:

  • bootstrap:返回启动模块列表
  • module_enabled :返回模块列表
  • theme:返回主题列表

三种类型里面bootstrap处理方式有点不同,module_enabled和theme是相同的。

先看看bootstrap是如此处理的。这里的bootstrap指的是系统表system里面标识为bootstrap的模块,是系统的启动模块,在Drupal启动过程中需要先被载入。首先检查是否有缓存:

if ($cached = cache_get('bootstrap_modules', 'cache_bootstrap')) {
$bootstrap_list = $cached->data;
}

若没有缓存,则直接从系统表system中查询:

$bootstrap_list = db_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC")->fetchAllAssoc('name');
cache_set('bootstrap_modules', $bootstrap_list, 'cache_bootstrap');

然后透过drupal_get_filename()更新模块主文件路径,目的是用system表的filename字段更新drupal_get_filename()函数中的静态变量:

foreach ($bootstrap_list as $module) {
drupal_get_filename('module', $module->name, $module->filename);
}

最后,更新system_list()的静态变量$lists,返回列表:

$lists['bootstrap'] = array_keys($bootstrap_list);
... ...
return $list[$type];

注意这里boostrap类型返回的只是启动模块的名称数组,没有其它额外的信息。

下面看看module_enabled和theme是如何处理的。首先还是查看缓存:

if ($cached = cache_get('system_list', 'cache_bootstrap')) {
$lists = $cached->data;
}

若缓存不存在,则直接读取系统表system:

$lists = array(
'module_enabled' => array(),
'theme' => array(),
'filepaths' => array(),
); $result = db_query("SELECT * FROM {system} WHERE type = 'theme' OR (type = 'module' AND status = 1) ORDER BY weight ASC, name ASC");
foreach ($result as $record) {
$record->info = unserialize($record->info); // info字段就是资源的info文件 // Build a list of all enabled modules.
if ($record->type == 'module') {
$lists['module_enabled'][$record->name] = $record;
} // Build a list of themes.
if ($record->type == 'theme') {
$lists['theme'][$record->name] = $record;
} // Build a list of filenames so drupal_get_filename can use it.
if ($record->status) {
$lists['filepaths'][] = array('type' => $record->type, 'name' => $record->name, 'filepath' => $record->filename);
}
}

接下来处理主题的继承关系。关于主题的继承关系可以参看《Drupal如何解析主题继承关系?》。

foreach ($lists['theme'] as $key => $theme) {
if (!empty($theme->info['base theme'])) {
// Make a list of the theme's base themes.
require_once DRUPAL_ROOT . '/includes/theme.inc';
$lists['theme'][$key]->base_themes = drupal_find_base_themes($lists['theme'], $key);
// Don't proceed if there was a problem with the root base theme.
if (!current($lists['theme'][$key]->base_themes)) {
continue;
} // Determine the root base theme.
$base_key = key($lists['theme'][$key]->base_themes);
// Add to the list of sub-themes for each of the theme's base themes.
foreach (array_keys($lists['theme'][$key]->base_themes) as $base_theme) {
$lists['theme'][$base_theme]->sub_themes[$key] = $lists['theme'][$key]->info['name'];
} // Add the base theme's theme engine info.
$lists['theme'][$key]->info['engine'] = isset($lists['theme'][$base_key]->info['engine']) ? $lists['theme'][$base_key]->info['engine'] : 'theme';
}
else {
// A plain theme is its own engine.
$base_key = $key;
if (!isset($lists['theme'][$key]->info['engine'])) {
$lists['theme'][$key]->info['engine'] = 'theme';
}
}
// Set the theme engine prefix.
$lists['theme'][$key]->prefix = ($lists['theme'][$key]->info['engine'] == 'theme') ? $base_key : $lists['theme'][$key]->info['engine'];
}

最后更新drupal_get_filename()的资源主文件路径,返回列表:

foreach ($lists['filepaths'] as $item) {
drupal_get_filename($item['type'], $item['name'], $item['filepath']);
} return $lists[$type];

从代码来看,system_list()也是可以调用filepaths类型的,结果也是数组:

array(
array('type' => '...', 'name' => '...', 'filepath' => '...'),
array('type' => '...', 'name' => '...', 'filepath' => '...'),
)

Drupal的system_list()函数解析的更多相关文章

  1. [转]javascript eval函数解析json数据时为什加上圆括号eval("("+data+")")

    javascript eval函数解析json数据时为什么 加上圆括号?为什么要 eval这里要添加 “("("+data+")");//”呢?   原因在于: ...

  2. PHP json_decode 函数解析 json 结果为 NULL 的解决方法

    在做网站 CMS 模块时,对于模块内容 content 字段,保存的是 json 格式的字符串,所以在后台进行模块内容的编辑操作 ( 取出保存的数据 ) 时,需要用到 json_decode() 函数 ...

  3. Matlab中bsxfun和unique函数解析

    一.问题来源 来自于一份LSH代码,记录下来. 二.函数解析 2.1 bsxfun bsxfun是一个matlab自版本R2007a来就提供的一个函数,作用是”applies an element-b ...

  4. socket使用TCP协议时,send、recv函数解析以及TCP连接关闭的问题

    Tcp协议本身是可靠的,并不等于应用程序用tcp发送数据就一定是可靠的.不管是否阻塞,send发送的大小,并不代表对端recv到多少的数据. 在阻塞模式下, send函数的过程是将应用程序请求发送的数 ...

  5. sigaction函数解析

    http://blog.chinaunix.net/uid-1877180-id-3011232.html sigaction函数解析  sigaction函数的功能是检查或修改与指定信号相关联的处理 ...

  6. driver_register()函数解析

    driver_register()函数解析 /** * driver_register - register driver with bus * @drv: driver to register *  ...

  7. async函数解析

    转载请注明出处:async函数解析 async函数是基于Generator函数实现的,也就是说是Generator函数的语法糖.在之前的文章有介绍过Generator函数语法和异步应用,如果对其不了解 ...

  8. tf.train.shuffle_batch函数解析

    tf.train.shuffle_batch (tensor_list, batch_size, capacity, min_after_dequeue, num_threads=1, seed=No ...

  9. oracle中next_day()、last_day()函数解析

    oracle中next_day()函数解析 Sql代码 当前系统时间的下一星期一的时间select   next_day(sysdate,1) from dual NEXT_DAY(date,char ...

随机推荐

  1. Visual Studio警告IDE0006的解决办法

     Visual Studio警告IDE0006的解决办法 Visual Studio警告IDE0006虽然给出明确的操作过程,但是在实施的过程中,还是有很多地方需要注意.下面以官方的信息,介绍一下注意 ...

  2. poj 2262 筛法求素数(巧妙利用数组下标!)

    Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41582   Accepted: ...

  3. SNOI2017(BZOJ5015~5018)泛做

    T1:礼物 想错方向了,实际上很简单. 我想的是:显然题目求的是$\sum_{i=1}^{n} i^{k}2^{i}$,然后或许可以通过化式子变成与n无关的复杂度? 然后就不停往斯特林数反演和下降幂的 ...

  4. NOIP2014 解题报告·水渣记

    Day 1: 第一次参加noip.小激动,小紧张,这些正常的情绪就不用说了.唯一值得一提的是 我早上步行去郑大工学院的时候迷路了,直接转进了隔壁的河南农大,绕了半天找不到机房,还给几个同学打了电话可就 ...

  5. XCode6 ,iOS之PCH文件配置

    1: 创建PCH文件 NewFile-->Other中的PCH File-->Next-->Create 2:配置PCH文件 项目中的TARGETS-->Build Setti ...

  6. linux安装配置redis

    redis是支持linux的,所以linux安装redis非常简单,按照官网的提示操作即可. 下载 $ wget http://download.redis.io/releases/redis-3.2 ...

  7. TSQLTableJSON解析JSON

    TSQLTableJSON解析JSON uses mormot rocedure TTestTableContent.SynopseTableVariant;var json: RawUTF8; pe ...

  8. Flash&Flex大全

    官方在线帮助(没标英文的都是中文) 用于 Adobe Flash Platform 的 ActionScript 3.0 参考 更多参考使这样的链接下载离线版:http://help.adobe.co ...

  9. sso 自动化运维平台

    单点登录SSO(Single Sign-On)是身份管理中的一部分.本文中作者开发了一个自动化运维平台中的统一认证接口,单点登录平台通过提供统一的认证平台,实现单点登录.因此,应用系统并不需要开发用户 ...

  10. (转)RedHat/CentOS安装和配置kerberos

    RedHat/CentOS安装和配置kerberos 需要在kerberos server和客户端都先安装ntp (Internet时间协议,保证服务器和客户机时间同步 ) 1  kerberos 服 ...