示例#1
0
bool f_spl_autoload_register(CVarRef autoload_function /* = null_variant */,
                             bool throws /* = true */,
                             bool prepend /* = false */) {
  if (same(autoload_function, s_spl_autoload_call)) {
    if (throws) {
      throw_spl_exception("Function spl_autoload_call()"
                      "cannot be registered");
    }
    return false;
  }
  CVarRef func = autoload_function.isNull() ?
                 s_spl_autoload : autoload_function;
  bool res = AutoloadHandler::s_instance->addHandler(func, prepend);
  if (!res && throws) {
    throw_spl_exception("Invalid autoload_function specified");
  }
  return res;
}
示例#2
0
static int64 hphp_get_call_info_and_extra(
    CStrRef cls, CStrRef func, int64 &extra) {
  if (func.empty()) {
    throw_spl_exception("Invalid function name given");
  }

  if (cls.empty()) {
    const CallInfo *cit;
    void *extrap;
    get_call_info_or_fail(cit, extrap, func);
    extra = (int64) extrap;
    return (int64) cit;
  } else {
    MethodCallPackage mcp;
    mcp.rootCls = cls.get();
    mcp.name = &func;
    if (!get_call_info_static_method(mcp)) {
      throw_spl_exception("Could not find method %s for class %s",
                          func.c_str(), cls.c_str());
    }
    extra = (int64) mcp.extra;
    return (int64) mcp.ci;
  }
}
示例#3
0
void f_spl_autoload(CStrRef class_name,
                    CStrRef file_extensions /* = null_string */) {
  Array ext = file_extensions.isNull()
              ? s_extension_list->extensions
              : StringUtil::Explode(file_extensions, ",").toArray();
  String lClass = StringUtil::ToLower(class_name);
  bool found = false;
  for (ArrayIter iter(ext); iter; ++iter) {
    String fileName = lClass + iter.second();
    include(fileName, true, "", false);
    if (f_class_exists(class_name, false)) {
      found = true;
      break;
    }
  }

  if (!found && !AutoloadHandler::s_instance->isRunning()) {
    throw_spl_exception("Class %s could not be loaded", class_name.c_str());
  }
}