本文整理了Java中php.runtime.env.Environment
类的一些代码示例,展示了Environment
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment
类的具体详情如下:
包路径:php.runtime.env.Environment
类名称:Environment
暂无
代码示例来源:origin: jphp-group/jphp
@Override
public ByteArrayInputStream convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
return new ByteArrayInputStream(arg.getBinaryBytes(env.getDefaultCharset()));
}
代码示例来源:origin: jphp-group/jphp
@Signature
final public Memory readAll(Environment env, Memory... args) throws Throwable {
return env.invokeMethod(this, "readFully");
}
代码示例来源:origin: jphp-group/jphp
@Signature({@Arg("value"), @Arg(value = "length", optional = @Optional("NULL"))})
public Memory write(Environment env, Memory... args){
int len = args[1].toInteger();
byte[] bytes = args[0].getBinaryBytes(env.getDefaultCharset());
try {
accessFile.write(bytes, 0, len == 0 ? bytes.length : len);
return LongMemory.valueOf(len == 0 ? bytes.length : len);
} catch (IOException e) {
env.exception(WrapIOException.class, e.getMessage());
}
return Memory.FALSE;
}
代码示例来源:origin: jphp-group/jphp
default Memory callMethod(Environment env, String name, Memory... args) {
try {
return env.invokeMethod(this, name, args);
} catch (Throwable throwable) {
env.forwardThrow(throwable);
return Memory.NULL;
}
}
代码示例来源:origin: jphp-group/jphp
public Memory eval(String code) throws Throwable {
return eval(code, getGlobals());
}
代码示例来源:origin: jphp-group/jphp
public Memory invokeMethodNoThrow(IObject object, String name, Memory... args) {
try {
return invokeMethod(object, name, args);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
this.catchUncaught(e);
return Memory.NULL;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: jphp-group/jphp
environment = new ConcurrentEnvironment(newScope(), outputR);
} else {
environment = new Environment(newScope(), outputR);
environment.setErrorFlags(0);
if (errorFlags != -1)
environment.setErrorFlags(errorFlags);
environment.setErrorFlags(ErrorType.E_ALL.value);
environment.setErrorFlags(ErrorType.E_ALL.value);
module = dumper.load(new ByteArrayInputStream(output.toByteArray()));
environment.getScope().loadModule(module);
environment.getScope().addUserModule(module);
environment.registerModule(module);
environment.getModuleManager().addModule(context.getFileName(), module);
Memory memory = module.includeNoThrow(environment, environment.getGlobals());
} catch (ErrorException e) {
if (withErrors){
environment.getErrorReportHandler().onFatal(e);
} else {
throw new CustomErrorException(e.getType(), e.getMessage()
environment.catchUncaught(e);
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
代码示例来源:origin: jphp-group/jphp
ClassEntity classLoaderEntity = environment.fetchClass(classLoader);
environment.invokeMethod(loader, "register", Memory.TRUE);
ClassEntity pkgLoaderEntity = environment.fetchClass(pkgLoader);
environment.invokeMethod(loader, "register");
environment.getGlobals().put("argv", argv);
environment.getGlobals().put("argc", LongMemory.valueOf(argv.size()));
ModuleEntity fetchModule = environment.getModuleManager().fetchModule(include);
environment.pushCall(stackItem);
try {
bootstrap.includeNoThrow(environment);
environment.doFinal();
} catch (Throwable throwable) {
throw new LaunchException(throwable);
environment.popCall();
代码示例来源:origin: jphp-group/jphp
@Signature
public void addFromString(Environment env, PArchiveEntry entry, Memory contents) throws Throwable {
fetchOutput(env);
byte[] binaryBytes = contents.getBinaryBytes(env.getDefaultCharset());
env.assignProperty(entry, "size", LongMemory.valueOf(binaryBytes.length));
env.invokeMethod(output, "putEntry", ObjectMemory.valueOf(entry));
outputStream.write(binaryBytes);
env.invokeMethod(output, "closeEntry");
}
代码示例来源:origin: jphp-group/jphp
@SuppressWarnings("unchecked")
protected Memory includeResource(String name, ArrayMemory globals){
ByteArrayOutputStream output = new ByteArrayOutputStream();
Environment environment;
if (isConcurrent()) {
environment = new ConcurrentEnvironment(newScope(), output);
} else {
environment = new Environment(newScope(), output);
}
File file = new File(Thread.currentThread().getContextClassLoader().getResource("resources/" + name).getFile());
Context context = new Context(file);
JvmCompiler compiler = new JvmCompiler(environment, context, getSyntax(context));
ModuleEntity module = compiler.compile();
environment.getScope().loadModule(module);
try {
environment.registerModule(module);
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
if (globals != null)
environment.getGlobals().putAll(globals);
Memory memory = module.includeNoThrow(environment, environment.getGlobals());
try {
environment.doFinal();
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
lastOutput = output.toString();
return memory;
}
代码示例来源:origin: jphp-group/jphp
public static Memory ftell(Environment env, TraceInfo trace, Memory stream) {
if (stream.instanceOf(Stream.CLASS_NAME)) {
try {
return env.invokeMethod(trace, stream, "getPosition");
} catch (Throwable throwable) {
env.warning(trace, "ftell(): " + throwable.getMessage());
return Memory.FALSE;
}
}
env.warning(trace, "ftell(): unable to get position from a non-stream");
return Memory.FALSE;
}
代码示例来源:origin: jphp-group/jphp
private ScheduledExecutorService getScheduledExecutorService(Environment env){
if (!(service instanceof ScheduledExecutorService)){
env.exception("Unsupported operation for non-scheduled executor service");
return null;
}
return (ScheduledExecutorService) service;
}
代码示例来源:origin: jphp-group/jphp
@Immutable
public static Memory strlen(Environment env, TraceInfo trace, Memory string) {
if (string.isArray()) {
env.warning(trace, "expects parameter 1 to be string, array given");
return Memory.NULL;
}
if (string instanceof BinaryMemory)
return LongMemory.valueOf(string.getBinaryBytes(env.getDefaultCharset()).length);
return LongMemory.valueOf(string.toString().length());
}
代码示例来源:origin: jphp-group/jphp
@Signature({
@Arg(value = "parent", nativeType = WrapEnvironment.class, optional = @Optional("NULL")),
@Arg(value = "flags", optional = @Optional(value = "0", type = HintType.INT))
})
public Memory __construct(Environment env, Memory... args){
CompileScope scope = env.scope;
int flags = args[1].toInteger();
boolean hotReload = (flags & HOT_RELOAD) == HOT_RELOAD;
boolean concurrent = (flags & CONCURRENT) == CONCURRENT;
if (hotReload) {
scope = new CompileScope(scope);
}
if (args[0].isNull()) {
if (concurrent)
setEnvironment(new ConcurrentEnvironment(scope, env.getDefaultBuffer().getOutput()));
else
setEnvironment(new Environment(scope, env.getDefaultBuffer().getOutput()));
} else {
if (hotReload)
env.exception("Environment cannot be hot-reloadable with parent");
if (concurrent)
setEnvironment(new ConcurrentEnvironment(args[0].toObject(WrapEnvironment.class).getWrapEnvironment()));
else
setEnvironment(new Environment(args[0].toObject(WrapEnvironment.class).getWrapEnvironment()));
}
return Memory.NULL;
}
代码示例来源:origin: jphp-group/jphp
@Signature({
@Arg("name"), @Arg(value = "value", optional = @Optional("null"))
})
public Memory addSuperGlobal(Environment env, Memory... args) {
if (hasSuperGlobal(env, args[0]).toBoolean()) {
environment.exception("Super-global variable $%s already exists", args[0]);
}
environment.getScope().superGlobals.add(args[0].toString());
environment.getGlobals().putAsKeyString(args[0].toString(), args[1].toImmutable());
return Memory.UNDEFINED;
}
代码示例来源:origin: jphp-group/jphp
@Signature(@Arg("callback"))
public Memory onOutput(Environment env, Memory... args) {
if (args[0].isNull()) {
Invoker invoker = Invoker.valueOf(this.environment, null, args[0]);
if (invoker == null) {
env.exception("Argument 1 must be callable in environment");
return Memory.NULL;
}
invoker.setTrace(env.trace());
this.environment.getDefaultBuffer().setCallback(args[0], invoker);
} else {
this.environment.getDefaultBuffer().setCallback(null);
}
return Memory.NULL;
}
代码示例来源:origin: jphp-group/jphp
: new Environment(compileScope, out);
environment.setErrorFlags(ErrorType.E_ALL.value ^ ErrorType.E_NOTICE.value);
environment.getDefaultBuffer().setImplicitFlush(true);
代码示例来源:origin: jphp-group/jphp
public static Memory getValue(Debugger context, String value) {
DebugTick tick = context.getRegisteredTick();
Environment environment = new Environment(new CompileScope(tick.getEnvironment().getScope()));
try {
return LangFunctions.eval(environment, tick.getTrace(), tick.getLocals(), "return " + value + ";");
} catch (Throwable throwable) {
return null;
}
}
代码示例来源:origin: jphp-group/jphp
protected Memory runDynamic(String code, boolean returned){
runIndex += 1;
Environment environment = new Environment(newScope());
code = (returned ? "return " : "") + code + ";";
Context context = new Context(code);
JvmCompiler compiler = new JvmCompiler(environment, context, getSyntax(context));
ModuleEntity module = compiler.compile();
environment.getScope().loadModule(module);
try {
environment.registerModule(module);
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
return module.includeNoThrow(environment);
}
代码示例来源:origin: jphp-group/jphp
public AbstractCompiler(Environment environment, Context context){
this.context = context;
this.scope = environment.getScope();
this.environment = environment;
}
内容来源于网络,如有侵权,请联系作者删除!