optionsmodule.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 979 行 · 第 1/2 页
JAVA
979 行
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Scott Ferguson */package com.caucho.quercus.lib;import com.caucho.quercus.Quercus;import com.caucho.quercus.QuercusModuleException;import com.caucho.quercus.annotation.Optional;import com.caucho.quercus.annotation.UsesSymbolTable;import com.caucho.quercus.annotation.Name;import com.caucho.quercus.env.*;import com.caucho.quercus.lib.file.FileModule;import com.caucho.quercus.module.AbstractQuercusModule;import com.caucho.quercus.module.IniDefinition;import com.caucho.quercus.module.IniDefinitions;import com.caucho.quercus.program.QuercusProgram;import com.caucho.util.L10N;import com.caucho.vfs.Path;import java.io.IOException;import java.util.ArrayList;import java.util.Map;import java.util.TreeSet;/** * PHP options */public class OptionsModule extends AbstractQuercusModule { private static final L10N L = new L10N(OptionsModule.class); // php/1a0q (phpMyAdmin) public static final String PHP_OS = System.getProperty("os.name").toUpperCase(); public static final int ASSERT_ACTIVE = 1; public static final int ASSERT_CALLBACK = 2; public static final int ASSERT_BAIL = 3; public static final int ASSERT_WARNING = 4; public static final int ASSERT_QUIET_EVAL = 5; public static final int CREDITS_GROUP = 1; public static final int CREDITS_GENERAL = 2; public static final int CREDITS_SAPI = 4; public static final int CREDITS_MODULES = 8; public static final int CREDITS_DOCS = 16; public static final int CREDITS_FULLPAGE = 32; public static final int CREDITS_QA = 64; public static final int CREDITS_ALL = -1; public static final int INFO_GENERAL = 1; public static final int INFO_CREDITS = 2; public static final int INFO_CONFIGURATION = 4; public static final int INFO_MODULES = 8; public static final int INFO_ENVIRONMENT = 16; public static final int INFO_VARIABLES = 32; public static final int INFO_LICENSE = 64; public static final int INFO_ALL = -1; private static final IniDefinitions _iniDefinitions = new IniDefinitions(); /** * Returns the default php.ini values. */ public IniDefinitions getIniDefinitions() { return _iniDefinitions; } /** * Checks the assertion */ @UsesSymbolTable(replace=false) @Name("assert") public static Value q_assert(Env env, String code) { try { Quercus quercus = env.getQuercus(); QuercusProgram program = quercus.parseCode(code); program = program.createExprReturn(); Value value = program.execute(env); if (value == null || ! value.toBoolean()) { env.warning(L.l("Assertion \"{0}\" failed", code)); return NullValue.NULL; } return BooleanValue.TRUE; } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Checks the assertion */ public static Value assert_options(Env env, int code, @Optional("null") Value value) { Value result; switch (code) { case ASSERT_ACTIVE: result = INI_ASSERT_ACTIVE.getAsLongValue(env); if (!value.isNull()) INI_ASSERT_ACTIVE.set(env, value); break; case ASSERT_WARNING: result = INI_ASSERT_WARNING.getAsLongValue(env); if (!value.isNull()) INI_ASSERT_WARNING.set(env, value); break; case ASSERT_BAIL: result = INI_ASSERT_BAIL.getAsLongValue(env); if (!value.isNull()) INI_ASSERT_BAIL.set(env, value); break; case ASSERT_QUIET_EVAL: result = INI_ASSERT_QUIET_EVAL.getAsLongValue(env); if (!value.isNull()) INI_ASSERT_QUIET_EVAL.set(env, value); break; case ASSERT_CALLBACK: result = INI_ASSERT_CALLBACK.getValue(env); if (!value.isNull()) INI_ASSERT_CALLBACK.set(env, value); break; default: env.warning(L.l("unknown value {0}", code)); result = BooleanValue.FALSE; } return result; } /** * Stubs the dl. */ public static boolean dl(Env env, String dl) { env.stub("dl is stubbed for dl(" + dl + ")"); return false; } /** * Returns true if the given extension is loaded */ public static boolean extension_loaded(Env env, String ext) { return env.isExtensionLoaded(ext); } /** * Returns the configuration value of a configuration. */ public static Value get_cfg_var(Env env, String name) { Value value = env.getConfigVar(name); if (!value.isNull()) return value; else return BooleanValue.FALSE; } /** * Returns the owner of the current script. */ public static String get_current_user(Env env) { env.stub("get_current_user"); return String.valueOf(env.getSelfPath().getOwner()); } /** * Returns the constants as an array */ public static Value get_defined_constants(Env env) { return env.getDefinedConstants(); } /** * Returns extension function with a given name. */ public static Value get_extension_funcs(Env env, String name) { return env.getExtensionFuncs(name); } /** * Returns the include path */ public static Value get_include_path(Env env) { return Quercus.INI_INCLUDE_PATH.getAsStringValue(env); } /** * Returns an array of all the included path. */ public static ArrayValue get_included_files(Env env) { return env.getIncludedFiles(); } /** * Returns true if the given extension is loaded */ public static Value get_loaded_extensions(Env env) { ArrayValue value = new ArrayValueImpl(); for (String ext : env.getLoadedExtensions()) { value.put(ext); } return value; } /** * Gets the magic quotes value. */ public static Value get_magic_quotes_gpc(Env env) { return (env.getIniBoolean("magic_quotes_gpc") ? BooleanValue.TRUE : BooleanValue.FALSE); } /** * Gets the magic quotes runtime value. */ public static Value get_magic_quotes_runtime(Env env) { return BooleanValue.FALSE; // PHP 6 removes, so we don't support } /** * Returns an array of all the included path. */ public static ArrayValue get_required_files(Env env) { return get_included_files(env); } /** * Gets an environment value. */ public static Value getenv(Env env, StringValue key) { Value val = env.getQuercus().getServerEnv(key); if (val == null) { ArrayValue serverVars = env.getGlobalVar("_SERVER").toArrayValue(env); val = serverVars.get(key); } if (val == null || ! val.isset()) return BooleanValue.FALSE; return val; } /** * Returns the gid for the script path. */ public static Value getlastmod(Env env) { return FileModule.filemtime(env, env.getSelfPath()); } /** * Returns the gid for the script path. */ public static Value getmygid(Env env) { return FileModule.filegroup(env, env.getSelfPath()); } /** * Returns the inode for the script path. */ public static Value getmyinode(Env env) { return FileModule.fileinode(env, env.getSelfPath()); } /** * Returns the uid for the script path. */ public static Value getmyuid(Env env) { return FileModule.fileowner(env, env.getSelfPath()); } /** * Returns the thread for the script. */ public static long getmypid(Env env) { return Thread.currentThread().getId(); } // XXX: getopt /** * Stub value for getrusage. */ public static Value getrusage(Env env, @Optional int who) { ArrayValue value = new ArrayValueImpl(); value.put(env.createString("ru_inblock"), LongValue.create(0)); value.put(env.createString("ru_outblock"), LongValue.create(0)); value.put(env.createString("ru_msgsnd"), LongValue.create(0)); value.put(env.createString("ru_msgrcv"), LongValue.create(0)); value.put(env.createString("ru_maxrss"), LongValue.create(0)); value.put(env.createString("ru_ixrss"), LongValue.create(0)); value.put(env.createString("ru_idrss"), LongValue.create(0)); value.put(env.createString("ru_minflt"), LongValue.create(0)); value.put(env.createString("ru_majflt"), LongValue.create(0)); value.put(env.createString("ru_nsignals"), LongValue.create(0)); value.put(env.createString("ru_nvcsw"), LongValue.create(0)); value.put(env.createString("ru_nswap"), LongValue.create(0)); value.put(env.createString("ru_utime.tv_sec"), LongValue.create(0)); value.put(env.createString("ru_utime.tv_usec"), LongValue.create(0)); value.put(env.createString("ru_stime.tv_sec"), LongValue.create(0)); value.put(env.createString("ru_stime.tv_usec"), LongValue.create(0)); return value; } /** * Sets an initialization value. */ public static Value ini_alter(Env env, String varName, String value) { return ini_set(env, varName, value); } /** * Returns an initialization value. */ public static String ini_get(Env env, String varName) { StringValue v = env.getIni(varName); if (v != null) return v.toString(); else return ""; } /** * Returns all initialization values. * XXX: access levels dependent on PHP_INI, PHP_INI_PERDIR, PHP_INI_SYSTEM. * * @param extension assumes ini values are prefixed by extension names. */ public static Value ini_get_all(Env env, @Optional() String extension) { if (extension.length() > 0) { if (! env.isExtensionLoaded(extension)) { env.warning(L.l("extension '" + extension + "' not loaded.")); return BooleanValue.FALSE; } extension += "."; } return getAllDirectives(env, extension); } private static Value getAllDirectives(Env env, String prefix) { ArrayValue directives = new ArrayValueImpl(); Value global = env.createString("global_value"); Value local = env.createString("local_value"); Value access = env.createString("access"); IniDefinitions iniDefinitions = env.getQuercus().getIniDefinitions(); TreeSet<String> names = new TreeSet<String>(); names.addAll(iniDefinitions.getNames()); for (String name : names) { if (name.startsWith(prefix)) { IniDefinition iniDefinition = iniDefinitions.get(name); // php/1a0n - do not add unless defined if (!iniDefinition.isRuntimeDefinition()) { ArrayValue inner = new ArrayValueImpl(); inner.put(global, iniDefinition.getAsStringValue(env.getQuercus())); inner.put(local, iniDefinition.getAsStringValue(env)); inner.put(access, LongValue.create(iniDefinition.getScope())); directives.put(env.createString(name), inner); } } } return directives; } /** * Restore the initial configuration value */ public static Value ini_restore(Env env, String name) { Value value = env.getConfigVar(name); if (value != null) env.setIni(name, value.toString()); return NullValue.NULL; } /** * Sets an initialization value. */ public static StringValue ini_set(Env env, String varName, String value) { StringValue oldValue = env.setIni(varName, value); if (oldValue != null) return oldValue; else return StringValue.EMPTY; } /** * Gets the magic quotes value. */ public static Value magic_quotes_runtime(Env env) { return BooleanValue.FALSE; // PHP 6 removes, so we don't support } /** * Stub value for memory get usage. */ public static Value memory_get_peak_usage(Env env, @Optional boolean real) { if (com.caucho.util.Alarm.isTest()) return LongValue.create(0); else
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?