bool AutoloadHandler::autoloadType(const String& name) { return !m_map.isNull() && loadFromMap(name, s_type, true, [] (const String& name) { return Unit::GetNamedEntity(name.get())-> getCachedTypeAlias() != nullptr; } ) != Failure; }
/** * Load settings from config file. * @return true if success, false otherwise */ bool SettingsManager::load() { if (!QFile::exists(_configPath)) return false; QFile f(_configPath); if (!f.open(QIODevice::ReadOnly)) return false; bool ok; QJson::Parser parser; QVariantMap map = parser.parse(f.readAll(), &ok).toMap(); if (!ok) return false; loadFromMap(map); return true; }
/** * invokeHandler returns true if any autoload handlers were executed, * false otherwise. When this function returns true, it is the caller's * responsibility to check if the given class or interface exists. */ bool AutoloadHandler::invokeHandler(const String& className, bool forceSplStack /* = false */) { if (className.empty()) { return false; } if (!m_map.isNull()) { ClassExistsChecker ce; Result res = loadFromMap(className, s_class, true, ce); if (res == ContinueAutoloading) { if (ce(className)) return true; } else { if (res != Failure) return res == Success; } } // If we end up in a recursive autoload loop where we try to load the // same class twice, just fail the load to mimic PHP as many frameworks // rely on it unless we are forcing a restart (due to spl_autoload_call) // in which case autoload is allowed to be reentrant. if (!forceSplStack) { if (m_loading.exists(className)) { return false; } m_loading.add(className, className); } else { // We can still overflow the stack if there is a loop when using // spl_autoload_call directly, but this behavior matches the reference // implementation. m_loading.append(className); } // Make sure state is cleaned up from this load; autoloading of arbitrary // code below can throw SCOPE_EXIT { String l_className = m_loading.pop(); assert(l_className == className); }; Array params = PackedArrayInit(1).append(className).toArray(); if (!m_spl_stack_inited && !forceSplStack) { if (function_exists(s___autoload)) { invoke(s___autoload, params, -1, true, false); return true; } return false; } if (!m_spl_stack_inited || m_handlers.empty()) { return false; } Object autoloadException; for (const HandlerBundle& hb : m_handlers) { try { vm_call_user_func_cufiter(*hb.m_cufIter, params); } catch (Object& ex) { assert(ex.instanceof(SystemLib::s_ExceptionClass)); if (autoloadException.isNull()) { autoloadException = ex; } else { Object cur = ex; Variant next = cur->o_get(s_previous, false, s_exception); while (next.isObject()) { cur = next.toObject(); next = cur->o_get(s_previous, false, s_exception); } cur->o_set(s_previous, autoloadException, s_exception); autoloadException = ex; } } if (Unit::lookupClass(className.get()) != nullptr) { break; } } if (!autoloadException.isNull()) { throw autoloadException; } return true; }
bool AutoloadHandler::autoloadConstant(StringData* name) { return !m_map.isNull() && loadFromMap(name, s_constant, false, ConstantExistsChecker()) != Failure; }
bool AutoloadHandler::autoloadFunc(StringData* name) { return !m_map.isNull() && loadFromMap(name, s_function, true, function_exists) != Failure; }