errormodule.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 584 行 · 第 1/2 页
JAVA
584 行
/* * 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.annotation.Optional;import com.caucho.quercus.env.*;import com.caucho.quercus.expr.Expr;import com.caucho.quercus.expr.FunctionExpr;import com.caucho.quercus.expr.IncludeExpr;import com.caucho.quercus.expr.IncludeOnceExpr;import com.caucho.quercus.expr.MethodCallExpr;import com.caucho.quercus.module.AbstractQuercusModule;import com.caucho.quercus.module.IniDefinitions;import com.caucho.quercus.module.IniDefinition;import com.caucho.quercus.lib.file.FileModule;import com.caucho.util.L10N;import java.util.logging.Logger;/** * PHP error handling. */public class ErrorModule extends AbstractQuercusModule { private static final L10N L = new L10N(ErrorModule.class); private static final Logger log = Logger.getLogger(ErrorModule.class.getName()); private static final IniDefinitions _iniDefinitions = new IniDefinitions(); public static final int E_ERROR = Env.E_ERROR; public static final int E_WARNING = Env.E_WARNING; public static final int E_PARSE = Env.E_PARSE; public static final int E_NOTICE = Env.E_NOTICE; public static final int E_CORE_ERROR = Env.E_CORE_ERROR; public static final int E_CORE_WARNING = Env.E_CORE_WARNING; public static final int E_COMPILE_ERROR = Env.E_COMPILE_ERROR; public static final int E_COMPILE_WARNING = Env.E_COMPILE_WARNING; public static final int E_USER_ERROR = Env.E_USER_ERROR; public static final int E_USER_WARNING = Env.E_USER_WARNING; public static final int E_USER_NOTICE = Env.E_USER_NOTICE; public static final int E_ALL = Env.E_ALL; public static final int E_STRICT = Env.E_STRICT; public static final int E_RECOVERABLE_ERROR = Env.E_RECOVERABLE_ERROR; private long _errorReporting = Env.E_DEFAULT; /** * Returns the default php.ini values. */ public IniDefinitions getIniDefinitions() { return _iniDefinitions; } /** * Exits */ public Value die(Env env, @Optional String msg) { if (msg != null) return env.die(msg); else return env.die(); } /** * Produces a backtrace */ public static Value debug_backtrace(Env env) { ArrayValue result = new ArrayValueImpl(); Exception e = new Exception(); e.fillInStackTrace(); StackTraceElement []stack = e.getStackTrace(); int depth = 0; for (int i = 1; i < stack.length; i++) { StackTraceElement elt = stack[i]; String name = elt.getMethodName(); String className = elt.getClassName(); // System.out.println("NAME: " + name + " " + elt.getClassName()); if (name.equals("executeTop")) { return result; } else if (className.startsWith("_quercus._") && name.equals("call")) { String path = unmangleFile(className); String fileName = env.getPwd().lookup("./" + path).getNativePath(); ArrayValue call = new ArrayValueImpl(); result.put(call); call.put("file", fileName); call.put("line", env.getSourceLine(className, elt.getLineNumber())); call.put("function", unmangleFunction(className)); call.put(env.createString("args"), new ArrayValueImpl()); } else if (className.startsWith("_quercus._") && name.equals("callMethod")) { String path = unmangleFile(className); String fileName = env.getPwd().lookup("./" + path).getNativePath(); ArrayValue call = new ArrayValueImpl(); result.put(call); call.put("file", fileName); call.put("line", env.getSourceLine(className, elt.getLineNumber())); call.put("function", unmangleFunction(className)); call.put("class", unmangleClass(className)); call.put("type", "->"); call.put(env.createString("args"), new ArrayValueImpl()); } else if (className.startsWith("_quercus._") && name.equals("execute")) { String methodName = stack[i - 1].getMethodName(); if (stack[i - 1].getClassName().equals("com.caucho.quercus.env.Env") && (methodName.equals("include") || methodName.equals("includeOnce"))) { String path = unmangleFile(className); String fileName = env.getPwd().lookup("./" + path).getNativePath(); ArrayValue call = new ArrayValueImpl(); result.put(call); call.put("file", fileName); call.put("line", env.getSourceLine(className, elt.getLineNumber())); if (methodName.equals("includeOnce")) call.put("function", "include_once"); else call.put("function", "include"); } } else if (className.equals("com.caucho.quercus.expr.FunctionExpr") && name.equals("evalImpl")) { if (stack[i - 1].getMethodName().equals("evalArguments")) { } else if (result.getSize() == 0 && depth == 0) depth++; else addInterpreted(env, result, depth++); } else if (className.equals("com.caucho.quercus.expr.MethodCallExpr") && name.equals("eval")) { if (stack[i - 1].getMethodName().equals("evalArguments")) { } else if (result.getSize() == 0 && depth == 0) depth++; else addInterpreted(env, result, depth++); } else if (className.equals("com.caucho.quercus.expr.IncludeExpr") && name.equals("eval")) { addInterpreted(env, result, depth++); } else if (className.equals("com.caucho.quercus.expr.IncludeOnceExpr") && name.equals("eval")) { addInterpreted(env, result, depth++); } else if (className.startsWith("com.caucho.quercus")) { } else if (name.equals("invoke") || name.equals("invoke0")) { } else { ArrayValue call = new ArrayValueImpl(); result.put(call); call.put("file", elt.getFileName()); call.put("line", elt.getLineNumber()); call.put("function", elt.getMethodName()); call.put("class", elt.getClassName()); call.put(env.createString("args"), new ArrayValueImpl()); } } return result; } private static void addInterpreted(Env env, ArrayValue result, int i) { Expr expr = env.peekCall(i); if (expr instanceof FunctionExpr) { FunctionExpr callExpr = (FunctionExpr) expr; ArrayValue call = new ArrayValueImpl(); result.put(call); if (callExpr.getFileName() != null) { call.put(env.createString("file"), env.createString(callExpr.getFileName())); call.put(env.createString("line"), new LongValue(callExpr.getLine())); } call.put(env.createString("function"), env.createString(callExpr.getName())); // Create "args" argument value array // evaluating args a second time is problematic, affecting mediawiki // php/180q //ArrayValueImpl args = evalArgsArray(env, callExpr); ArrayValueImpl args = new ArrayValueImpl(); call.put(env.createString("args"), args); } else if (expr instanceof MethodCallExpr) { MethodCallExpr callExpr = (MethodCallExpr) expr; ArrayValue call = new ArrayValueImpl(); result.put(call); if (callExpr.getFileName() != null) { call.put(env.createString("file"), env.createString(callExpr.getFileName())); call.put(env.createString("line"), new LongValue(callExpr.getLine())); } call.put(env.createString("function"), env.createString(callExpr.getName())); call.put(env.createString("class"), env.createString(env.peekCallThis(i).getClassName())); call.put(env.createString("type"), env.createString("->")); call.put(env.createString("args"), new ArrayValueImpl()); } else if (expr instanceof IncludeExpr) { ArrayValue call = new ArrayValueImpl(); result.put(call); if (expr.getFileName() != null) { call.put(env.createString("file"), env.createString(expr.getFileName())); call.put(env.createString("line"), new LongValue(expr.getLine())); } call.put(env.createString("function"), env.createString("include")); } else if (expr instanceof IncludeOnceExpr) { boolean isRequire = ((IncludeOnceExpr) expr).isRequire(); ArrayValue call = new ArrayValueImpl(); result.put(call); if (expr.getFileName() != null) { call.put(env.createString("file"), env.createString(expr.getFileName())); call.put(env.createString("line"), LongValue.create(expr.getLine()));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?