Drupal的system_list()函数解析
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()函数解析的更多相关文章
- [转]javascript eval函数解析json数据时为什加上圆括号eval("("+data+")")
javascript eval函数解析json数据时为什么 加上圆括号?为什么要 eval这里要添加 “("("+data+")");//”呢? 原因在于: ...
- PHP json_decode 函数解析 json 结果为 NULL 的解决方法
在做网站 CMS 模块时,对于模块内容 content 字段,保存的是 json 格式的字符串,所以在后台进行模块内容的编辑操作 ( 取出保存的数据 ) 时,需要用到 json_decode() 函数 ...
- Matlab中bsxfun和unique函数解析
一.问题来源 来自于一份LSH代码,记录下来. 二.函数解析 2.1 bsxfun bsxfun是一个matlab自版本R2007a来就提供的一个函数,作用是”applies an element-b ...
- socket使用TCP协议时,send、recv函数解析以及TCP连接关闭的问题
Tcp协议本身是可靠的,并不等于应用程序用tcp发送数据就一定是可靠的.不管是否阻塞,send发送的大小,并不代表对端recv到多少的数据. 在阻塞模式下, send函数的过程是将应用程序请求发送的数 ...
- sigaction函数解析
http://blog.chinaunix.net/uid-1877180-id-3011232.html sigaction函数解析 sigaction函数的功能是检查或修改与指定信号相关联的处理 ...
- driver_register()函数解析
driver_register()函数解析 /** * driver_register - register driver with bus * @drv: driver to register * ...
- async函数解析
转载请注明出处:async函数解析 async函数是基于Generator函数实现的,也就是说是Generator函数的语法糖.在之前的文章有介绍过Generator函数语法和异步应用,如果对其不了解 ...
- tf.train.shuffle_batch函数解析
tf.train.shuffle_batch (tensor_list, batch_size, capacity, min_after_dequeue, num_threads=1, seed=No ...
- oracle中next_day()、last_day()函数解析
oracle中next_day()函数解析 Sql代码 当前系统时间的下一星期一的时间select next_day(sysdate,1) from dual NEXT_DAY(date,char ...
随机推荐
- 对Webservice的理解
eb Service使用的是 SOAP (Simple Object Access Protocol)协议 soap协议只是用来封装消息用的.封装后的消息你可以通过各种已有的协 ...
- BM算法--串匹配
BM(Boyer-Moore)算法,后缀匹配,是指模式串的比较从右到左,模式串的移动也是从左到右的匹配过程,一般情况比KMP算法要快.时间复杂度O(m/n) C++描述(教师版) int BM(cha ...
- [bzoj2433][Noi2011]智能车比赛
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2433 http://221.192.240.123:8586/JudgeOnline/ ...
- luogu P1339 [USACO09OCT]热浪Heat Wave
题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for g ...
- [Codeforces #210] Tutorial
Link: Codeforces #210 传送门 A: 贪心,对每个值都取最大值,不会有其他解使答案变优 #include <bits/stdc++.h> using namespace ...
- 【Splay】【启发式合并】hdu6133 Army Formations
题意:给你一颗树,每个结点的儿子数不超过2.每个结点有一个权值,一个结点的代价被定义为将其子树中所有结点的权值放入数组排序后,每个权值乘以其下标的和.让你计算所有结点的代价. 二叉树的条件没有用到. ...
- 【CCpp程序设计2017】推箱子游戏
我的还……支持撤销!用链表实现! 题目:推箱子小游戏(基于console) 功能要求: 将p09迷宫游戏改造为“推箱子”游戏: 在地图中增加箱子.箱子目标位置等图形: 当玩家将所有箱子归位,则显示玩家 ...
- 【深度搜索+剪枝】POJ1011-Sticks
深搜部分和之前的POJ2362差不多,只是有几处需要额外的剪枝. [思路]排序后从最短木棒开始搜索至木棒长总和,如果木棒长总和sum能整除当前棒长,则进入深搜. [剪枝]先前POJ2362的剪枝部分不 ...
- List the Books
描述 Jim is fond of reading books, and he has so many books that sometimes it's hard for him to manage ...
- python的高阶函数
函数式编程的一个特点就是,允许把函数本身作为参数传入另一个函数,还允许返回一个函数. 高阶函数 定义:一个函数就可以接收另一函数作为参数,这种函数就称之为高阶函数. map/reduce Python ...