php.runtime.env.Environment类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中php.runtime.env.Environment类的一些代码示例,展示了Environment类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment类的具体详情如下:
包路径:php.runtime.env.Environment
类名称:Environment

Environment介绍

暂无

代码示例

代码示例来源:origin: jphp-group/jphp

  1. @Override
  2. public ByteArrayInputStream convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
  3. return new ByteArrayInputStream(arg.getBinaryBytes(env.getDefaultCharset()));
  4. }

代码示例来源:origin: jphp-group/jphp

  1. @Signature
  2. final public Memory readAll(Environment env, Memory... args) throws Throwable {
  3. return env.invokeMethod(this, "readFully");
  4. }

代码示例来源:origin: jphp-group/jphp

  1. @Signature({@Arg("value"), @Arg(value = "length", optional = @Optional("NULL"))})
  2. public Memory write(Environment env, Memory... args){
  3. int len = args[1].toInteger();
  4. byte[] bytes = args[0].getBinaryBytes(env.getDefaultCharset());
  5. try {
  6. accessFile.write(bytes, 0, len == 0 ? bytes.length : len);
  7. return LongMemory.valueOf(len == 0 ? bytes.length : len);
  8. } catch (IOException e) {
  9. env.exception(WrapIOException.class, e.getMessage());
  10. }
  11. return Memory.FALSE;
  12. }

代码示例来源:origin: jphp-group/jphp

  1. default Memory callMethod(Environment env, String name, Memory... args) {
  2. try {
  3. return env.invokeMethod(this, name, args);
  4. } catch (Throwable throwable) {
  5. env.forwardThrow(throwable);
  6. return Memory.NULL;
  7. }
  8. }

代码示例来源:origin: jphp-group/jphp

  1. public Memory eval(String code) throws Throwable {
  2. return eval(code, getGlobals());
  3. }

代码示例来源:origin: jphp-group/jphp

  1. public Memory invokeMethodNoThrow(IObject object, String name, Memory... args) {
  2. try {
  3. return invokeMethod(object, name, args);
  4. } catch (RuntimeException e) {
  5. throw e;
  6. } catch (Exception e) {
  7. this.catchUncaught(e);
  8. return Memory.NULL;
  9. } catch (Throwable e) {
  10. throw new RuntimeException(e);
  11. }
  12. }

代码示例来源:origin: jphp-group/jphp

  1. environment = new ConcurrentEnvironment(newScope(), outputR);
  2. } else {
  3. environment = new Environment(newScope(), outputR);
  4. environment.setErrorFlags(0);
  5. if (errorFlags != -1)
  6. environment.setErrorFlags(errorFlags);
  7. environment.setErrorFlags(ErrorType.E_ALL.value);
  8. environment.setErrorFlags(ErrorType.E_ALL.value);
  9. module = dumper.load(new ByteArrayInputStream(output.toByteArray()));
  10. environment.getScope().loadModule(module);
  11. environment.getScope().addUserModule(module);
  12. environment.registerModule(module);
  13. environment.getModuleManager().addModule(context.getFileName(), module);
  14. Memory memory = module.includeNoThrow(environment, environment.getGlobals());
  15. } catch (ErrorException e) {
  16. if (withErrors){
  17. environment.getErrorReportHandler().onFatal(e);
  18. } else {
  19. throw new CustomErrorException(e.getType(), e.getMessage()
  20. environment.catchUncaught(e);
  21. } catch (Throwable throwable) {
  22. throw new RuntimeException(throwable);

代码示例来源:origin: jphp-group/jphp

  1. ClassEntity classLoaderEntity = environment.fetchClass(classLoader);
  2. environment.invokeMethod(loader, "register", Memory.TRUE);
  3. ClassEntity pkgLoaderEntity = environment.fetchClass(pkgLoader);
  4. environment.invokeMethod(loader, "register");
  5. environment.getGlobals().put("argv", argv);
  6. environment.getGlobals().put("argc", LongMemory.valueOf(argv.size()));
  7. ModuleEntity fetchModule = environment.getModuleManager().fetchModule(include);
  8. environment.pushCall(stackItem);
  9. try {
  10. bootstrap.includeNoThrow(environment);
  11. environment.doFinal();
  12. } catch (Throwable throwable) {
  13. throw new LaunchException(throwable);
  14. environment.popCall();

代码示例来源:origin: jphp-group/jphp

  1. @Signature
  2. public void addFromString(Environment env, PArchiveEntry entry, Memory contents) throws Throwable {
  3. fetchOutput(env);
  4. byte[] binaryBytes = contents.getBinaryBytes(env.getDefaultCharset());
  5. env.assignProperty(entry, "size", LongMemory.valueOf(binaryBytes.length));
  6. env.invokeMethod(output, "putEntry", ObjectMemory.valueOf(entry));
  7. outputStream.write(binaryBytes);
  8. env.invokeMethod(output, "closeEntry");
  9. }

代码示例来源:origin: jphp-group/jphp

  1. @SuppressWarnings("unchecked")
  2. protected Memory includeResource(String name, ArrayMemory globals){
  3. ByteArrayOutputStream output = new ByteArrayOutputStream();
  4. Environment environment;
  5. if (isConcurrent()) {
  6. environment = new ConcurrentEnvironment(newScope(), output);
  7. } else {
  8. environment = new Environment(newScope(), output);
  9. }
  10. File file = new File(Thread.currentThread().getContextClassLoader().getResource("resources/" + name).getFile());
  11. Context context = new Context(file);
  12. JvmCompiler compiler = new JvmCompiler(environment, context, getSyntax(context));
  13. ModuleEntity module = compiler.compile();
  14. environment.getScope().loadModule(module);
  15. try {
  16. environment.registerModule(module);
  17. } catch (Throwable throwable) {
  18. throw new RuntimeException(throwable);
  19. }
  20. if (globals != null)
  21. environment.getGlobals().putAll(globals);
  22. Memory memory = module.includeNoThrow(environment, environment.getGlobals());
  23. try {
  24. environment.doFinal();
  25. } catch (Throwable throwable) {
  26. throw new RuntimeException(throwable);
  27. }
  28. lastOutput = output.toString();
  29. return memory;
  30. }

代码示例来源:origin: jphp-group/jphp

  1. public static Memory ftell(Environment env, TraceInfo trace, Memory stream) {
  2. if (stream.instanceOf(Stream.CLASS_NAME)) {
  3. try {
  4. return env.invokeMethod(trace, stream, "getPosition");
  5. } catch (Throwable throwable) {
  6. env.warning(trace, "ftell(): " + throwable.getMessage());
  7. return Memory.FALSE;
  8. }
  9. }
  10. env.warning(trace, "ftell(): unable to get position from a non-stream");
  11. return Memory.FALSE;
  12. }

代码示例来源:origin: jphp-group/jphp

  1. private ScheduledExecutorService getScheduledExecutorService(Environment env){
  2. if (!(service instanceof ScheduledExecutorService)){
  3. env.exception("Unsupported operation for non-scheduled executor service");
  4. return null;
  5. }
  6. return (ScheduledExecutorService) service;
  7. }

代码示例来源:origin: jphp-group/jphp

  1. @Immutable
  2. public static Memory strlen(Environment env, TraceInfo trace, Memory string) {
  3. if (string.isArray()) {
  4. env.warning(trace, "expects parameter 1 to be string, array given");
  5. return Memory.NULL;
  6. }
  7. if (string instanceof BinaryMemory)
  8. return LongMemory.valueOf(string.getBinaryBytes(env.getDefaultCharset()).length);
  9. return LongMemory.valueOf(string.toString().length());
  10. }

代码示例来源:origin: jphp-group/jphp

  1. @Signature({
  2. @Arg(value = "parent", nativeType = WrapEnvironment.class, optional = @Optional("NULL")),
  3. @Arg(value = "flags", optional = @Optional(value = "0", type = HintType.INT))
  4. })
  5. public Memory __construct(Environment env, Memory... args){
  6. CompileScope scope = env.scope;
  7. int flags = args[1].toInteger();
  8. boolean hotReload = (flags & HOT_RELOAD) == HOT_RELOAD;
  9. boolean concurrent = (flags & CONCURRENT) == CONCURRENT;
  10. if (hotReload) {
  11. scope = new CompileScope(scope);
  12. }
  13. if (args[0].isNull()) {
  14. if (concurrent)
  15. setEnvironment(new ConcurrentEnvironment(scope, env.getDefaultBuffer().getOutput()));
  16. else
  17. setEnvironment(new Environment(scope, env.getDefaultBuffer().getOutput()));
  18. } else {
  19. if (hotReload)
  20. env.exception("Environment cannot be hot-reloadable with parent");
  21. if (concurrent)
  22. setEnvironment(new ConcurrentEnvironment(args[0].toObject(WrapEnvironment.class).getWrapEnvironment()));
  23. else
  24. setEnvironment(new Environment(args[0].toObject(WrapEnvironment.class).getWrapEnvironment()));
  25. }
  26. return Memory.NULL;
  27. }

代码示例来源:origin: jphp-group/jphp

  1. @Signature({
  2. @Arg("name"), @Arg(value = "value", optional = @Optional("null"))
  3. })
  4. public Memory addSuperGlobal(Environment env, Memory... args) {
  5. if (hasSuperGlobal(env, args[0]).toBoolean()) {
  6. environment.exception("Super-global variable $%s already exists", args[0]);
  7. }
  8. environment.getScope().superGlobals.add(args[0].toString());
  9. environment.getGlobals().putAsKeyString(args[0].toString(), args[1].toImmutable());
  10. return Memory.UNDEFINED;
  11. }

代码示例来源:origin: jphp-group/jphp

  1. @Signature(@Arg("callback"))
  2. public Memory onOutput(Environment env, Memory... args) {
  3. if (args[0].isNull()) {
  4. Invoker invoker = Invoker.valueOf(this.environment, null, args[0]);
  5. if (invoker == null) {
  6. env.exception("Argument 1 must be callable in environment");
  7. return Memory.NULL;
  8. }
  9. invoker.setTrace(env.trace());
  10. this.environment.getDefaultBuffer().setCallback(args[0], invoker);
  11. } else {
  12. this.environment.getDefaultBuffer().setCallback(null);
  13. }
  14. return Memory.NULL;
  15. }

代码示例来源:origin: jphp-group/jphp

  1. : new Environment(compileScope, out);
  2. environment.setErrorFlags(ErrorType.E_ALL.value ^ ErrorType.E_NOTICE.value);
  3. environment.getDefaultBuffer().setImplicitFlush(true);

代码示例来源:origin: jphp-group/jphp

  1. public static Memory getValue(Debugger context, String value) {
  2. DebugTick tick = context.getRegisteredTick();
  3. Environment environment = new Environment(new CompileScope(tick.getEnvironment().getScope()));
  4. try {
  5. return LangFunctions.eval(environment, tick.getTrace(), tick.getLocals(), "return " + value + ";");
  6. } catch (Throwable throwable) {
  7. return null;
  8. }
  9. }

代码示例来源:origin: jphp-group/jphp

  1. protected Memory runDynamic(String code, boolean returned){
  2. runIndex += 1;
  3. Environment environment = new Environment(newScope());
  4. code = (returned ? "return " : "") + code + ";";
  5. Context context = new Context(code);
  6. JvmCompiler compiler = new JvmCompiler(environment, context, getSyntax(context));
  7. ModuleEntity module = compiler.compile();
  8. environment.getScope().loadModule(module);
  9. try {
  10. environment.registerModule(module);
  11. } catch (Throwable throwable) {
  12. throw new RuntimeException(throwable);
  13. }
  14. return module.includeNoThrow(environment);
  15. }

代码示例来源:origin: jphp-group/jphp

  1. public AbstractCompiler(Environment environment, Context context){
  2. this.context = context;
  3. this.scope = environment.getScope();
  4. this.environment = environment;
  5. }

相关文章