📄 quercus.java
字号:
/** * Returns true if an extension is loaded. */ public Value getExtensionFuncs(String name) { ArrayValue value = null; for (ModuleInfo moduleInfo : _modules.values()) { Set<String> extensionSet = moduleInfo.getLoadedExtensions(); if (extensionSet.contains(name)) { for (String functionName : moduleInfo.getFunctions().keySet()) { if (value == null) value = new ArrayValueImpl(); value.put(functionName); } } } if (value != null) return value; else return BooleanValue.FALSE; } public Collection<ModuleInfo> getModules() { return _modules.values(); } public HashMap<String, Value> getConstMap() { return _constMap; } /** * Interns a string. */ public StringValue intern(String name) { synchronized (_internMap) { StringValue value = _internMap.get(name); if (value == null) { name = name.intern(); value = new StringBuilderValue(name); _internMap.put(name, value); } return value; } } /** * Returns a named constant. */ public Value getConstant(String name) { return _constMap.get(name); } public String createStaticName() { return ("s" + _staticId++).intern(); } /** * Loads the session from the backing. */ public SessionArrayValue loadSession(Env env, String sessionId) { long now = Alarm.getCurrentTime(); SessionArrayValue session = _sessionManager.getSession(env, sessionId, now); if (session == null) session = _sessionManager.createSession(env, sessionId, now); return session; } /** * Saves the session to the backing. */ public void saveSession(Env env, SessionArrayValue session) { _sessionManager.saveSession(env, session); } /** * Removes the session from the backing. */ public void destroySession(String sessionId) { _sessionManager.removeSession(sessionId); } /** * Loads a special value */ public Object getSpecial(String key) { synchronized (_specialMap) { return _specialMap.get(key); } } /** * Saves a special value */ public void setSpecial(String key, Object value) { synchronized (_specialMap) { _specialMap.put(key, value); } } /** * Scans the classpath for META-INF/services/com.caucho.quercus.QuercusModule */ private void initStaticFunctions() { Thread thread = Thread.currentThread(); ClassLoader loader = thread.getContextClassLoader(); try { String quercusModule = "META-INF/services/com.caucho.quercus.QuercusModule"; Enumeration<URL> urls = loader.getResources(quercusModule); HashSet<URL> urlSet = new HashSet<URL>(); // gets rid of duplicate entries found by different classloaders while (urls.hasMoreElements()) { URL url = urls.nextElement(); urlSet.add(url); } for (URL url : urlSet) { InputStream is = null; ReadStream rs = null; try { is = url.openStream(); rs = new ReadStream(new VfsStream(is, null)); parseServicesModule(rs); } catch (Throwable e) { log.log(Level.WARNING, e.toString(), e); } finally { if (rs != null) rs.close(); if (is != null) is.close(); } } } catch (Exception e) { log.log(Level.WARNING, e.toString(), e); } } /** * Parses the services file, looking for PHP services. */ private void parseServicesModule(ReadStream in) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); String line; while ((line = in.readLine()) != null) { int p = line.indexOf('#'); if (p >= 0) line = line.substring(0, p); line = line.trim(); if (line.length() > 0) { String className = line; try { Class cl; try { cl = Class.forName(className, false, loader); } catch (ClassNotFoundException e) { throw new ClassNotFoundException(L.l("'{0}' not valid {1}", className, e.toString())); } introspectPhpModuleClass(cl); } catch (Throwable e) { log.info("Failed loading " + className + "\n" + e.toString()); log.log(Level.FINE, e.toString(), e); } } } } /** * Introspects the module class for functions. * * @param cl the class to introspect. */ private void introspectPhpModuleClass(Class cl) throws IllegalAccessException, InstantiationException, ConfigException { synchronized (_modules) { if (_modules.get(cl.getName()) != null) return; log.finest("Quercus loading module " + cl.getName()); QuercusModule module = (QuercusModule) cl.newInstance(); ModuleContext context = getLocalContext(); ModuleInfo info = context.addModule(cl.getName(), module); _modules.put(cl.getName(), info); if (info.getModule() instanceof ModuleStartupListener) _moduleStartupListeners.add((ModuleStartupListener)info.getModule()); for (String ext : info.getLoadedExtensions()) _extensionSet.add(ext); Map<String, Value> map = info.getConstMap(); if (map != null) _constMap.putAll(map); _iniDefinitions.addAll(info.getIniDefinitions()); synchronized (_functionNameMap) { for (Map.Entry<String, AbstractFunction> entry : info.getFunctions().entrySet()) { String funName = entry.getKey(); AbstractFunction fun = entry.getValue(); _funMap.put(funName, fun); _lowerFunMap.put(funName.toLowerCase(), fun); int id = getFunctionId(funName); _functionMap[id] = fun; } } } } public static Value objectToValue(Object obj) { if (obj == null) return NullValue.NULL; else if (Byte.class.equals(obj.getClass()) || Short.class.equals(obj.getClass()) || Integer.class.equals(obj.getClass()) || Long.class.equals(obj.getClass())) { return LongValue.create(((Number) obj).longValue()); } else if (Float.class.equals(obj.getClass()) || Double.class.equals(obj.getClass())) { return DoubleValue.create(((Number) obj).doubleValue()); } else if (String.class.equals(obj.getClass())) { // XXX: i18n return new StringBuilderValue((String) obj); } else { // XXX: unknown types, e.g. Character? return null; } } /** * Scans the classpath for META-INF/services/com.caucho.quercus.QuercusClass */ private void initStaticClassServices() { Thread thread = Thread.currentThread(); ClassLoader loader = thread.getContextClassLoader(); try { String quercusModule = "META-INF/services/com.caucho.quercus.QuercusClass"; Enumeration<URL> urls = loader.getResources(quercusModule); HashSet<URL> urlSet = new HashSet<URL>(); // gets rid of duplicate entries found by different classloaders while (urls.hasMoreElements()) { URL url = urls.nextElement(); urlSet.add(url); } for (URL url : urlSet) { InputStream is = null; ReadStream rs = null; try { is = url.openStream(); rs = new ReadStream(new VfsStream(is, null)); parseClassServicesModule(rs); } catch (Throwable e) { log.log(Level.WARNING, e.toString(), e); } finally { if (rs != null) rs.close(); if (is != null) is.close(); } } } catch (Exception e) { log.log(Level.WARNING, e.toString(), e); } } /** * Parses the services file, looking for PHP services. */ private void parseClassServicesModule(ReadStream in) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, ConfigException, NoSuchMethodException, InvocationTargetException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); String line; while ((line = in.readLine()) != null) { int p = line.indexOf('#'); if (p >= 0) line = line.substring(0, p); line = line.trim(); if (line.length() == 0) continue; String[] args = line.split(" "); String className = args[0]; Class cl; try { cl = Class.forName(className, false, loader); String phpClassName = null; String extension = null; String definedBy = null; for (int i = 1; i < args.length; i++) { if ("as".equals(args[i])) { i++; if (i >= args.length) throw new IOException(L.l("expecting Quercus class name after '{0}' in definition for class {1}", "as", className)); phpClassName = args[i]; } else if ("provides".equals(args[i])) { i++; if (i >= args.length) throw new IOException(L.l("expecting name of extension after '{0}' in definition for class {1}", "extension", className)); extension = args[i]; } else if ("definedBy".equals(args[i])) { i++; if (i >= args.length) throw new IOException(L.l("expecting name of class implementing JavaClassDef after '{0}' in definition for class {1}", "definedBy", className)); definedBy = args[i]; } else { throw new IOException(L.l("unknown token '{0}' in definition for class {1} ", args[i], className)); } } if (phpClassName == null) phpClassName = className.substring(className.lastIndexOf('.') + 1); Class javaClassDefClass; if (definedBy != null) { javaClassDefClass = Class.forName(definedBy, false, loader); } else javaClassDefClass = null; introspectJavaClass(phpClassName, cl, extension, javaClassDefClass); } catch (Exception e) { log.info("Failed loading " + className + "\n" + e.toString()); log.log(Level.FINE, e.toString(), e); } } } /** * Introspects the module class for functions. * * @param name the php class name * @param type the class to introspect. * @param extension the extension provided by the class, or null * @param javaClassDefClass */ private void introspectJavaClass(String name, Class type, String extension, Class javaClassDefClass) throws IllegalAccessException, InstantiationException, ConfigException, NoSuchMethodException, InvocationTargetException { ModuleContext context = getLocalContext(); /* if (type.isAnnotationPresent(ClassImplementation.class)) { if (javaClassDefClass != null) throw new UnimplementedException(); ClassDef def = context.addClassImpl(name, type, extension); } else { */ JavaClassDef def = context.addClass(name, type, extension, javaClassDefClass); synchronized (_javaClassWrappers) { _javaClassWrappers.put(name, def); _lowerJavaClassWrappers.put(name.toLowerCase(), def); } /* _staticClasses.put(name, def); _lowerStaticClasses.put(name.toLowerCase(), def); */ // } if (extension != null) _extensionSet.add(extension); } /** * Introspects the module class for functions. * * @param name the php class name * @param type the class to introspect. * @param extension the extension provided by the class, or null */ private void introspectJavaImplClass(String name, Class type, String extension) throws IllegalAccessException, InstantiationException, ConfigException { if (log.isLoggable(Level.FINEST)) { if (extension == null) log.finest(L.l("Quercus loading class {0} with type {1}", name, type.getName())); else log.finest(L.l("Quercus loading class {0} with type {1} providing extension {2}", name, type.getName(), extension)); } ModuleContext context = getLocalContext(); // JavaImplClassDef def = context.addClassImpl(name, type, extension); try { JavaClassDef def = context.addClass(name, type, extension, null); /* _staticClasses.put(name, def); _lowerStaticClasses.put(name.toLowerCase(), def); */ } catch (RuntimeException e) { throw e; } catch (Exception e) { throw ConfigException.create(e); } } /** * Scans the classpath for META-INF/services/com.caucho.quercus.QuercusClass */ private void initStaticClasses() { /* _stdClassDef = new InterpretedClassDef("stdClass", null, new String[0]); _stdClass = new QuercusClass(_stdClassDef, null); _staticClasses.put(_stdClass.getName(), _stdClassDef); _lowerStaticClasses.put(_stdClass.getName().toLowerCase(), _stdClassDef); InterpretedClassDef exn = new InterpretedClassDef("Exception", null, new String[0]); try { exn.setConstructor(new StaticFunction(_moduleContext, null, Quercus.class.getMethod("exnConstructor", new Class[] { Env.class, Value.class, String.class }))); } catch (Exception e) { throw new QuercusException(e); } // QuercusClass exnCl = new QuercusClass(exn, null); _staticClasses.put(exn.getName(), exn); _lowerStaticClasses.put(exn.getName().toLowerCase(), exn); */ } public void start() { } public void close() { _sessionManager.close(); _pageManager.close(); } public static Value exnConstructor(Env env, Value obj, String msg) { if (obj != null) { obj.putField(env, "message", new UnicodeValueImpl(msg)); } return NullValue.NULL; } static class IncludeKey { private final String _include; private final String _includePath; private final Path _pwd; private final Path _scriptPwd; IncludeKey(String include, String includePath, Path pwd, Path scriptPwd) { _include = include; _includePath = includePath; _pwd = pwd; _scriptPwd = scriptPwd; } public int hashCode() { int hash = 37; hash = 65537 * hash + _include.hashCode(); hash = 65537 * hash + _includePath.hashCode(); hash = 65537 * hash + _pwd.hashCode(); hash = 65537 * hash + _scriptPwd.hashCode(); return hash; } public boolean equals(Object o) { if (! (o instanceof IncludeKey)) return false; IncludeKey key = (IncludeKey) o; return (_include.equals(key._include) && _includePath.equals(key._includePath) && _pwd.equals(key._pwd) && _scriptPwd.equals(key._scriptPwd)); } } static { _superGlobals.add("GLOBALS"); _superGlobals.add("_COOKIE"); _superGlobals.add("_ENV"); _superGlobals.add("_FILES"); _superGlobals.add("_GET"); _superGlobals.add("_POST"); _superGlobals.add("_SERVER"); _superGlobals.add("_SESSION"); _superGlobals.add("_REQUEST"); } public static final IniDefinition INI_INCLUDE_PATH = _ini.add("include_path", ".", IniDefinition.PHP_INI_ALL); public static final IniDefinition INI_REGISTER_LONG_ARRAYS = _ini.add("register_long_arrays", true, IniDefinition.PHP_INI_PERDIR); public static final IniDefinition INI_ALWAYS_POPULATE_RAW_POST_DATA = _ini.add("always_populate_raw_post_data", false, IniDefinition.PHP_INI_PERDIR); // unicode ini public static final IniDefinition INI_UNICODE_SEMANTICS = _ini.add("unicode.semantics", false, IniDefinition.PHP_INI_SYSTEM); public static final IniDefinition INI_UNICODE_FALLBACK_ENCODING = _ini.add("unicode.fallback_encoding", "utf-8", IniDefinition.PHP_INI_ALL); public static final IniDefinition INI_UNICODE_FROM_ERROR_MODE = _ini.add("unicode.from_error_mode", "2", IniDefinition.PHP_INI_ALL); public static final IniDefinition INI_UNICODE_FROM_ERROR_SUBST_CHAR = _ini.add("unicode.from_error_subst_char", "3f", IniDefinition.PHP_INI_ALL); public static final IniDefinition INI_UNICODE_HTTP_INPUT_ENCODING = _ini.add("unicode.http_input_encoding", null, IniDefinition.PHP_INI_ALL); public static final IniDefinition INI_UNICODE_OUTPUT_ENCODING = _ini.add("unicode.output_encoding", null, IniDefinition.PHP_INI_ALL); public static final IniDefinition INI_UNICODE_RUNTIME_ENCODING = _ini.add("unicode.runtime_encoding", null, IniDefinition.PHP_INI_ALL); public static final IniDefinition INI_UNICODE_SCRIPT_ENCODING = _ini.add("unicode.script_encoding", null, IniDefinition.PHP_INI_ALL);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -