zoukankan      html  css  js  c++  java
  • Drupal如何处理系统变量?

    Drupal的系统变量都保存在数据库variable表中:

    然后,开发人员可以通过下面的API函数操作这些系统变量:

    function variable_get($name, $default = NULL) {
      global $conf;
      return isset($conf[$name]) ? $conf[$name] : $default;
    }
    
    function variable_set($name, $value) {
      global $conf;
      db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();
      cache_clear_all('variables', 'cache_bootstrap');
      $conf[$name] = $value;
    }
    
    function variable_del($name) {
      global $conf;
      db_delete('variable')
        ->condition('name', $name)
        ->execute();
      cache_clear_all('variables', 'cache_bootstrap');
      unset($conf[$name]);
    }

    从这些API函数可以知道,系统变量从variable表读取出来后,都放在了全局变量$conf里面。那全局变量$conf是如何初始化的呢?这实际上是通过在Bootstrap过程中调用variable_initialize()函数完成的:

    function variable_initialize($conf = array()) {
      if ($cached = cache_get('variables', 'cache_bootstrap')) {
        $variables = $cached->data;
      }
      else {
        // Cache miss. Avoid a stampede.
        $name = 'variable_init';
        if (!lock_acquire($name, 1)) {
          // Another request is building the variable cache.
          // Wait, then re-run this function.
          lock_wait($name);
          return variable_initialize($conf);
        }
        else {
          // Proceed with variable rebuild.
          $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
          cache_set('variables', $variables, 'cache_bootstrap');
          lock_release($name);
        }
      }
    
      foreach ($conf as $name => $value) {
        $variables[$name] = $value;
      }
    
      return $variables;
    }
  • 相关阅读:
    webstorm之js,css文件压缩
    Dojo的UI框架bootstrap for dojo和Dojo-Bootstrap简介
    android 之 java环境部署
    利用requestjs优化响应式移动端js加载
    前端自动化部署之gulp
    ubuntu配置LAMP
    html5的116个标签
    前端环境安装(node.js+npm+grunt+bower)
    git在webstorm中的使用
    JDK下载安装与环境变量path配置
  • 原文地址:https://www.cnblogs.com/eastson/p/3355580.html
Copyright © 2011-2022 走看看