예제 #1
0
// No `ini` binding yet. Hdf still takes precedence but will be removed
// once we have made all options ini-aware. All new settings should
// use the ini path of this method (i.e., pass a bogus Hdf or keep it null)
void Config::Iterate(std::function<void (const IniSettingMap&,
                                         const Hdf&,
                                         const std::string&)> cb,
                     const IniSettingMap &ini, const Hdf& config,
                     const std::string &name,
                     const bool prepend_hhvm /* = true */) {
  // We shouldn't be passing a leaf here. That's why name is not
  // optional.
  assert(!name.empty());
  Hdf hdf = config[name];
  if (hdf.exists() && !hdf.isEmpty()) {
    for (Hdf c = hdf.firstChild(); c.exists(); c = c.next()) {
      cb(IniSetting::Map::object, c, "");
    }
  } else {
    Hdf empty;
    auto ini_name = IniName(name, prepend_hhvm);
    auto* ini_value = ini_iterate(ini, ini_name);
    if (ini_value && ini_value->isObject()) {
      for (auto& pair : ini_value->items()) {
        cb(pair.second, empty, pair.first.data());
      }
    }
  }
}
예제 #2
0
const char* Config::Get(const IniSetting::Map &ini, const Hdf& config,
                         const char *defValue /* = nullptr */) {
  auto* value = ini.get_ptr(IniName(config));
  if (value && value->isString()) {
    return value->data();
  }
  return config.configGet(defValue);
}
예제 #3
0
파일: config.cpp 프로젝트: atdt/hhvm
// Hdf takes precedence, as usual. No `ini` binding yet.
void Config::Iterate(const IniSettingMap &ini, const Hdf &hdf,
                     std::function<void (const IniSettingMap&,
                                         const Hdf&)> cb) {
    if (hdf.exists()) {
      for (Hdf c = hdf.firstChild(); c.exists(); c = c.next()) {
        cb(ini, c);
      }
    } else {
      auto ini_name = IniName(hdf);
      auto* ini_value = ini.get_ptr(ini_name);
      if (ini_value && ini_value->isObject()) {
        for (auto& val : ini_value->values()) {
          cb(val, hdf);
        }
      }
    }
  }
예제 #4
0
const char* Config::Get(const IniSetting::Map &ini, const Hdf& config,
                        const std::string& name /* = "" */,
                        const char *defValue /* = nullptr */,
                        const bool prepend_hhvm /* = true */) {
  auto ini_name = IniName(name, prepend_hhvm);
  Hdf hdf = name != "" ? config[name] : config;
  auto* value = ini_iterate(ini, ini_name);
  if (value && value->isString()) {
    // See generic Get##METHOD below for why we are doing this
    const char* ini_ret = value->data();
    const char* hdf_ret = hdf.configGet(value->data());
    if (hdf_ret != ini_ret) {
      ini_ret = hdf_ret;
      IniSetting::Set(ini_name, ini_ret);
    }
    return ini_ret;
  }
  return hdf.configGet(defValue);
}
예제 #5
0
void Config::Bind(std::vector<std::string>& loc, const IniSettingMap& ini,
                  const Hdf& config) {
  std::vector<std::string> ret;
  auto ini_name = IniName(config);
  auto* value = ini.get_ptr(ini_name);
  if (value && value->isObject()) {
    ini_on_update(*value, ret);
    loc = ret;
  }
  // If there is an HDF setting for the config, then it still wins for
  // the RuntimeOption value until we obliterate HDFs
  ret.clear();
  config.configGet(ret);
  if (ret.size() > 0) {
    loc = ret;
  }
  IniSetting::Bind(IniSetting::CORE, IniSetting::PHP_INI_SYSTEM, ini_name,
                   &loc);
}
예제 #6
0
파일: config.cpp 프로젝트: fredemmott/hhvm
// This method must return a char* which is owned by the IniSettingMap
// to avoid issues with the lifetime of the char*
const char* Config::Get(const IniSettingMap &ini, const Hdf& config,
                        const std::string& name /* = "" */,
                        const char *defValue /* = nullptr */,
                        const bool prepend_hhvm /* = true */) {
  auto ini_name = IniName(name, prepend_hhvm);
  Hdf hdf = name != "" ? config[name] : config;
  auto value = ini_iterate(ini, ini_name);
  if (value.isString()) {
    // See generic Get##METHOD below for why we are doing this
    // Note that value is a string, so value.toString() is not
    // a temporary.
    const char* ini_ret = value.toString().data();
    const char* hdf_ret = hdf.configGet(ini_ret);
    if (hdf_ret != ini_ret) {
      ini_ret = hdf_ret;
      IniSetting::SetSystem(ini_name, ini_ret);
    }
    return ini_ret;
  }
  return hdf.configGet(defValue);
}
예제 #7
0
파일: config.cpp 프로젝트: fredemmott/hhvm
// No `ini` binding yet. Hdf still takes precedence but will be removed
// once we have made all options ini-aware. All new settings should
// use the ini path of this method (i.e., pass a bogus Hdf or keep it null)
void Config::Iterate(std::function<void (const IniSettingMap&,
                                         const Hdf&,
                                         const std::string&)> cb,
                     const IniSettingMap &ini, const Hdf& config,
                     const std::string &name,
                     const bool prepend_hhvm /* = true */) {
  Hdf hdf = name.empty() ? config : config[name];
  if (hdf.exists() && !hdf.isEmpty()) {
    for (Hdf c = hdf.firstChild(); c.exists(); c = c.next()) {
      cb(IniSetting::Map::object, c, "");
    }
  } else {
    Hdf empty;
    auto ini_value = name.empty() ? ini :
      ini_iterate(ini, IniName(name, prepend_hhvm));
    if (ini_value.isArray()) {
      for (ArrayIter iter(ini_value.toArray()); iter; ++iter) {
        cb(iter.second(), empty, iter.first().toString().toCppString());
      }
    }
  }
}