Drupal所能够理解的资源
Drupal能够识别哪些资源类型?
profile,不知道怎么翻译,应该是指安装类型,固定地存放于profiles目录下。
module,模块,可以存在于多个目录下:modules、profiles/{profile}/modules、sites/all/modules、sites/{$site}/modules。
theme,主题,可以存在于多个目录下:themes、profiles/{profile}/themes、sites/all/themes、sites/{$site}/themes。
theme_engine,主题引擎,可以存在于多个目录下:themes/engines、profiles/{profile}/themes/engines、sites/all/themes/engines、sites/{$site}/themes/engines。
Drupal识别的这些资源都可以注册到系统表system里面,用资源主文件作为key,用type字段表示资源类型。
Drupal如何找到指定的资源?
Drupal使用drupal_get_filename()和drupal_system_listing()两个函数配合来寻找指定的资源。
最先进入的是drupal_get_filename()函数,该函数以资源类型和资源名称作为传入参数:
function drupal_get_filename($type, $name, $filename = NULL) { ... ... }
profile资源固定地存放在profiles目录下,这是在代码里面固定写死了的:
if ($type == 'profile') {
$profile_filename = "profiles/$name/$name.profile";
$files[$type][$name] = file_exists($profile_filename) ? $profile_filename : FALSE;
}
然后在系统表system中搜索对应的资源类型和名称是否有存在。若存在,代表该资源已经安装过,直接返回其key就是资源主文件。
if (function_exists('db_query')) {
$file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField();
if (file_exists(DRUPAL_ROOT . '/' . $file)) {
$files[$type][$name] = $file;
}
}
在system表找不到对应的资源,Drupal就直接去检查对应的目录是否存在。Drupal规定了每种资源的目录和主文件命名规则:
$dir = $type . 's';
if ($type == 'theme_engine') {
$dir = 'themes/engines';
$extension = 'engine';
}
elseif ($type == 'theme') {
$extension = 'info';
}
else {
$extension = $type;
}
资源目录命名规则是以资源类型加上s后缀,theme_engine例外,theme_engine目录是themes/engines。
资源主文件命名规则是资源名称加上资源类型后缀。theme和theme_engine的后缀例外,theme后缀是info,theme_engine后缀是engine。
每种资源都有多个目录可以存放,Drupal使用drupal_system_listing()函数定义其搜索顺序。
function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
$config = conf_path();
$searchdir = array($directory);
$files = array();
// The 'profiles' directory contains pristine collections of modules and
// themes as organized by a distribution. It is pristine in the same way
// that /modules is pristine for core; users should avoid changing anything
// there in favor of sites/all or sites/<domain> directories.
$profiles = array();
$profile = drupal_get_profile();
// In case both profile directories contain the same extension, the actual
// profile always has precedence.
$profiles[] = $profile;
foreach ($profiles as $profile) {
if (file_exists("profiles/$profile/$directory")) {
$searchdir[] = "profiles/$profile/$directory";
}
}
// Always search sites/all/* as well as the global directories.
$searchdir[] = 'sites/all/' . $directory;
if (file_exists("$config/$directory")) {
$searchdir[] = "$config/$directory";
}
// Get current list of items.
if (!function_exists('file_scan_directory')) {
require_once DRUPAL_ROOT . '/includes/file.inc';
}
foreach ($searchdir as $dir) {
$files_to_add = file_scan_directory($dir, $mask, array('key' => $key, 'min_depth' => $min_depth));
// Duplicate files found in later search directories take precedence over
// earlier ones, so we want them to overwrite keys in our resulting
// $files array.
// The exception to this is if the later file is from a module or theme not
// compatible with Drupal core. This may occur during upgrades of Drupal
// core when new modules exist in core while older contrib modules with the
// same name exist in a directory such as sites/all/modules/.
foreach (array_intersect_key($files_to_add, $files) as $file_key => $file) {
// If it has no info file, then we just behave liberally and accept the
// new resource on the list for merging.
if (file_exists($info_file = dirname($file->uri) . '/' . $file->name . '.info')) {
// Get the .info file for the module or theme this file belongs to.
$info = drupal_parse_info_file($info_file);
// If the module or theme is incompatible with Drupal core, remove it
// from the array for the current search directory, so it is not
// overwritten when merged with the $files array.
if (isset($info['core']) && $info['core'] != DRUPAL_CORE_COMPATIBILITY) {
unset($files_to_add[$file_key]);
}
}
}
$files = array_merge($files, $files_to_add);
}
return $files;
}
这里举一个搜索hello模块的例子来说明搜索的过程。根据上面的资源命名规则可以知道,模块目录的命名规则是资源类型加s后缀,也就是modules。然后模块主文件的命名规则是资源名称加上资源类型后缀,也就是hello.module。好了,现在我们要找的就是modules/hello/hello.module文件。那到哪里去找这个文件呢?drupal_system_listing()会依次搜索以下四个位置:
- modules/hello/hello.module
- profiles/drupal_get_profile()/modules/hello/hello.module
- sites/all/modules/hello/hello.module
- sites/conf_path()/modules/hello/hello.module
找到了就OK,找不到就说明hello模块不存在。
Drupal如何载入指定资源?
Drupal用drupal_load()函数载入资源。首先用drupal_get_filename()得到资源主文件,然后简单的include_once就完了。
function drupal_load($type, $name) {
static $files = array();
if (isset($files[$type][$name])) {
return TRUE;
}
$filename = drupal_get_filename($type, $name);
if ($filename) {
include_once DRUPAL_ROOT . '/' . $filename;
$files[$type][$name] = TRUE;
return TRUE;
}
return FALSE;
}
Drupal所能够理解的资源的更多相关文章
- drupal node机制理解
[1]根据结构的功能结构的不同,drupal划分为,node,user,comment等不同的结构,他们的结构是不同的.他们可以作为四个不同的抽象类,根据这个抽象类,分别有一套hook函数去控制实现的 ...
- 深入理解 Kubernetes 资源限制:CPU
原文地址:https://www.yangcs.net/posts/understanding-resource-limits-in-kubernetes-cpu-time/ 在关于 Kubernet ...
- 深入理解Kubernetes资源限制:内存
写在前面 当我开始大范围使用Kubernetes的时候,我开始考虑一个我做实验时没有遇到的问题:当集群里的节点没有足够资源的时候,Pod会卡在Pending状态.你是没有办法给节点增加CPU或者内存的 ...
- 深入理解Kubernetes资源限制:CPU
写在前面 在上一篇关于Kubernetes资源限制的文章我们讨论了如何通过ResourceRequirements设置Pod中容器内存限制,以及容器运行时是如何利用Linux Cgroups实现这些限 ...
- 理解k8s资源限制系列(二):cpu time
本文介绍几种在K8S中限制资源使用的几种方法. 资源类型 在K8S中可以对两类资源进行限制:cpu和内存. CPU的单位有: 正实数,代表分配几颗CPU,可以是小数点,比如0.5代表0.5颗CPU,意 ...
- Drupal中的模块载入
什么是模块载入?首先说载入,这里的载入是指require_once.模块载入就是指require_once模块目录中的某个PHP文件. 每个Drupal模块都应该有自己的主文件.模块主文件以模块名开始 ...
- 对drupal的理解【转】
写本文是想跟刚用drupal的朋友,分享一下心得,国内用drupal的太少了,希望大家能好好交流. 希望几分钟看完后你能马上上手drupal,至少能理解hook,api,theme,module,cc ...
- 服务器资源监控插件(jmeter)
零.引言 我们对被测应用进行性能测试时,除了关注吞吐量.响应时间等应用自身的表现外,对应用运行所涉及的服务器资源的使用情况,也是非常重要的方面,通过 实时监控,可以准确的把握不同测试场景下服务器资源消 ...
- Spring Security之动态配置资源权限
在Spring Security中实现通过数据库动态配置url资源权限,需要通过配置验证过滤器来实现资源权限的加载.验证.系统启动时,到数据库加载系统资源权限列表,当有请求访问时,通过对比系统资源权限 ...
随机推荐
- javascript中的对象创建与继承
js是一门基于原型的面向对象语言,与传统的面向对象如Java,C#相比,它在对象创建及继承上有自己独特的实现方式,本文主要描述js中对象创建及继承的一些实践. 1.对象创建 方式一:工厂模式创建对象 ...
- Python - 字符和字符值之间的转换
字符和字符值之间的转换 Python中, 字符和字符值, 直接的转换, 包含ASCII码和字母之间的转换,Unicode码和数字之间的转换; 也可以使用map, 进行批量转换, 输出为集合, 使用jo ...
- [SRM686]CyclesNumber
题意:求$n$个数的所有排列形成的轮换个数的$m$次方之和 我以前只知道这是GDKOI的题,今天在ckw博客上发现它是TC题...原题真是哪里都有... 就是求$\sum\limits_{i=1}^n ...
- 【成端更新线段树模板】POJ3468-A Simple Problem with Integers
http://poj.org/problem?id=3468 _(:зゝ∠)_我又活着回来啦,前段时间太忙了写的题没时间扔上来,以后再说. [问题描述] 成段加某一个值,然后询问区间和. [思路] 讲 ...
- CentOS 6.9下KVM虚拟机网络Bridge(网桥)方式与NAT方式详解(转)
摘要:KVM虚拟机网络配置的两种方式:NAT方式和Bridge方式.Bridge方式的配置原理和步骤.Bridge方式适用于服务器主机的虚拟化.NAT方式适用于桌面主机的虚拟化. NAT的网络结构图: ...
- Oracle下的ArcSDE创建的空间数据库的备份与恢复
对Oracle下ArcSDE创建的空间数据库, 整体备份.恢复或迁移. 一.imp和exp命令方式 1.1 数据库完整备份 检查数据库字符集是否一致 SQL>select userenv(‘la ...
- http请求及缓存框架 GalHttprequest
GalHttprequest 是一个android平台上一个轻量级的http网络请求及缓存框架.当前GalHttpRequest支持以下功能: 同步请求Stirng.InputStream.Bitma ...
- 【mybatis】mybatis自定义动态字段查询,mybatis实现动态字段查询,如果某个条件为null,则不查询某个字段,否则就查询某个字段
mybatis实现动态字段查询,如果某个条件为null,则不查询某个字段,否则就查询某个字段 先看一下 怎么实现动态的自定义字段查询: 例如: 而field 就是数据表中的某一个字段 String f ...
- GitHub 上100个最受欢迎的Java基础类库
作为一名整天与既成熟且不断发展的Java语言打交道的开发者,面对的困境之一就是在我们编写代码的时候,是使用一些人人谈论的人们新技术呢,还是坚持使用一些虽旧但成熟的类库? 由于Java应用中大部分是商业 ...
- 利用PMKID破解PSK的实际测试与影响评估
在2018年8月4日,一位研究员在hashcat论坛中发布了一篇帖子,表示他研究WPA3协议密码破解方法的过程中,发现了一个针对WPA/WPA2协议密码破解的新方法,使用PMKID(the Pairw ...