Example #1
0
static Variant HHVM_METHOD(Yaf_Controller_Abstract, render, const String& tpl, 
        const Variant& parameters)
{
    //raise_warning("start render in controller!");
    auto _viewTmp = this_->o_realProp("_view", 
            ObjectData::RealPropUnchecked, "Yaf_Controller_Abstract");
    if (_viewTmp->isNull()) {
        return false;
    }

    auto _view = _viewTmp->toObject();
    std::string self_name = this_->o_realProp("_name", 
            ObjectData::RealPropUnchecked, "Yaf_Controller_Abstract")->toString().toCppString();

    std::string view_ext = g_yaf_local_data.get()->view_ext;
    transform(self_name.begin(), self_name.end(), self_name.begin(), tolower);

    for (unsigned int i = 0; i < self_name.length(); i++) {
        if (self_name[i] == '_') {
            self_name[i] = DEFAULT_SLASH_CHAR;
        }
    }

    std::string action_name = tpl.toCppString();

    for (unsigned int i = 0; i < action_name.length(); i++) {
        if (action_name[i] == '_') {
            action_name[i] = DEFAULT_SLASH_CHAR;
        }
    }

    std::string path = self_name  + DEFAULT_SLASH_STR + action_name + 
                        "." + view_ext;

    Array func = Array::Create();
    func.append(_view);
    func.append(String("render"));

    Array params = Array::Create();
    params.append(String(path.c_str()));

    if (!parameters.isNull()) {
        params.append(parameters);
    }

    Variant ret = vm_call_user_func(func, params);
    if (ret.isNull()) {
        return false;
    }

    if (ret.isBoolean() && !ret.toBoolean()) {
        return false;
    }

    return ret;
}
Example #2
0
Variant IniSetting::FromString(const String& ini, const String& filename,
                               bool process_sections, int scanner_mode) {
    Lock lock(s_mutex); // ini parser is not thread-safe
    auto ini_cpp = ini.toCppString();
    auto filename_cpp = filename.toCppString();
    if (process_sections) {
        CallbackData data;
        SectionParserCallback cb;
        data.arr = Array::Create();
        if (zend_parse_ini_string(ini_cpp, filename_cpp, scanner_mode, cb, &data)) {
            return data.arr;
        }
    } else {
        ParserCallback cb;
        Variant ret = Array::Create();
        if (zend_parse_ini_string(ini_cpp, filename_cpp, scanner_mode, cb, &ret)) {
            return ret;
        }
    }

    return false;
}
Example #3
0
static void mysql_set_conn_attr(MYSQL* mysql, const String& key,
                                const String& value) {
  if (key.empty()) {
    raise_warning("MySQL: Invalid connection attribute - empty key");
  }
  else if (value.empty()) {
    raise_warning(
        std::string("MySQL: Invalid connection attribute - empty value for ") +
        key.toCppString());
  }
  else {
    mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, key.c_str(),
                   value.c_str());
  }
}
Example #4
0
Array IniSetting::GetAll(const String& ext_name, bool details) {
    Array r = Array::Create();

    const Extension* ext = nullptr;
    if (!ext_name.empty()) {
        if (ext_name == s_core) {
            ext = IniSetting::CORE;
        } else {
            ext = Extension::GetExtension(ext_name);
            if (!ext) {
                raise_warning("Unable to find extension '%s'",
                              ext_name.toCppString().c_str());
                return r;
            }
        }
    }

    for (auto& iter: boost::join(s_system_ini_callbacks, *s_user_callbacks)) {
        if (ext && ext != iter.second.extension) {
            continue;
        }

        auto value = dynamic_to_variant(iter.second.getCallback());
        // Cast all non-arrays to strings since that is what everything used ot be
        if (!value.isArray()) {
            value = value.toString();
        }
        if (details) {
            Array item = Array::Create();
            item.add(s_global_value, value);
            item.add(s_local_value, value);
            if (iter.second.mode == PHP_INI_ALL) {
                item.add(
                    s_access,
                    Variant(PHP_INI_USER | PHP_INI_SYSTEM | PHP_INI_PERDIR)
                );
            } else if (iter.second.mode == PHP_INI_ONLY) {
                item.add(s_access, Variant(PHP_INI_SYSTEM));
            } else {
                item.add(s_access, Variant(iter.second.mode));
            }
            r.add(String(iter.first), item);
        } else {
            r.add(String(iter.first), value);
        }
    }
    return r;
}
Example #5
0
void CmdVariable::recvImpl(DebuggerThriftBuffer &thrift) {
  DebuggerCommand::recvImpl(thrift);
  thrift.read(m_frame);
  {
    String sdata;
    thrift.read(sdata);
    auto error = DebuggerWireHelpers::WireUnserialize(sdata, m_variables);
    if (error != DebuggerWireHelpers::NoError) {
      m_variables.reset();
      if (error != DebuggerWireHelpers::HitLimit || m_version == 0) {
        // Unexpected error. Log it.
        m_wireError = sdata.toCppString();
      }
    }
  }
  thrift.read(m_global);
  if (m_version == 2) {
    thrift.read(m_formatMaxLen);
    thrift.read(m_varName);
    thrift.read(m_filter);
  }
}
Example #6
0
bool IniSetting::SetUser(const String& name, const Variant& value) {
    return SetUser(name.toCppString(), variant_to_dynamic(value), FollyDynamic());
}
Example #7
0
bool IniSetting::Get(const String& name, Variant& value) {
    folly::dynamic b = nullptr;
    auto ret = Get(name.toCppString(), b);
    value = dynamic_to_variant(b);
    return ret;
}