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. 【LA 3641】 Leonardo's Notebook (置换群)

    [题意] 给出26个大写字母组成 字符串B问是否存在一个置换A使得A^2 = B [分析] 置换前面已经说了,做了这题之后有了更深的了解. 再说说置换群.   首先是群. 置换群的元素是置换,运算时是 ...

  2. JZYZOJ1371 青蛙的约会 扩展欧几里得 GTMD数论

    http://172.20.6.3/Problem_Show.asp?id=1371 题意是两个青蛙朝同一个方向跳 http://www.cnblogs.com/jackge/archive/2013 ...

  3. BZOJ 1106 [POI2007]立方体大作战tet(树状数组)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1106 [题目大意] 给定玩家一个有2n个元素的栈,元素一个叠一个地放置. 这些元素拥有 ...

  4. 【线段树】Gym - 101201J - Shopping

    题意:n个数,m次询问,每次给你一个询问v,l,r,问你v%a[l]%a[l+1]%...%a[r]是多少. a%b,结果要么不变,要么至少缩小到a的一半,于是用线段树,每次询问当前区间最靠左侧的小于 ...

  5. [Luogu2656]采蘑菇

    题目大意: 给你一个有向图,每条边有一个边权w以及恢复系数k, 你从s点出发乱走,经过某条边时会获得相应的收益w,而当第二次经过这条边时相应的收益为w*k下取整. 问你最大能获得的收益为多少? 思路: ...

  6. 5分钟上手TypeScript

    安装TypeScript 安装这个工具有两种方式: 用npm安装npm install -g typescript 安装visual studio的TypeScript插件 编译TypeScript ...

  7. 数组中的forEach和map的区别

    大多数情况下,我们都要对数组进行遍历,然后经常用到的两个方法就是forEach和map方法. 先来说说它们的共同点 相同点 都是循环遍历数组中的每一项 forEach和map方法里每次执行匿名函数都支 ...

  8. Ubantu配置protoc2.5.0

    首先得到 protobuf 相应的包文件 ,在终端上输入如下 wget http://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz 下载完毕后 ...

  9. tcpreplay工具使用

    参考:http://www.cnblogs.com/jiayy/p/3447047.html   速率控制算法的大体思路就是,通过适当的sleep,增加包发送的时间,从而减小算出来的速率,以达到用户设 ...

  10. Android内存优化11 内存泄漏常见情况2 内部类泄漏

    线程持久化 Java中的Thread有一个特点就是她们都是直接被GC Root所引用,也就是说Dalvik虚拟机对所有被激活状态的线程都是持有强引用,导致GC永远都无法回收掉这些线程对象,除非线程被手 ...