php.runtime.env.Environment.getScope()方法的使用及代码示例

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

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

Environment.getScope介绍

暂无

代码示例

代码示例来源: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. }

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

  1. @Signature
  2. public Set<String> getSuperGlobals() {
  3. return environment.getScope().superGlobals;
  4. }

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

  1. @Signature
  2. public static void addClassPath(Environment env, File file) throws IOException {
  3. try {
  4. env.getScope().getClassLoader().addLibrary(file.toURI().toURL());
  5. } catch (Throwable t) {
  6. throw new IOException("Error, could not add URL to system classloader, " + t.getMessage());
  7. }
  8. }
  9. }

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

  1. @Signature(@Arg("name"))
  2. public Memory hasSuperGlobal(Environment env, Memory... args) {
  3. return environment.getScope().superGlobals.contains(args[0].toString()) ? Memory.TRUE : Memory.FALSE;
  4. }

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

  1. @Signature(@Arg("name"))
  2. public static Memory exists(Environment env, Memory... args) throws IOException {
  3. String name = args[0].toString();
  4. if (name.startsWith("res:///")) {
  5. name = name.substring(7);
  6. } else if (name.startsWith("res://")) {
  7. name = name.substring(6);
  8. }
  9. return env.getScope().getClassLoader().getResource(name) == null ? Memory.FALSE : Memory.TRUE;
  10. }

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

  1. @Override
  2. @Signature({@Arg("path")})
  3. public Memory __construct(Environment env, Memory... args) throws IOException {
  4. super.__construct(env, args[0], StringMemory.valueOf("r"));
  5. //long t = System.currentTimeMillis();
  6. String path = this.getPath().replace('\\', '/').replace("//", "/");
  7. if (path.startsWith("/")) {
  8. path = path.substring(1);
  9. }
  10. setPath("res://" + path);
  11. url = env.getScope().getClassLoader().getResource(path);
  12. if (url == null) {
  13. throw new IOException("Resource not found - " + getPath());
  14. }
  15. stream = url.openStream();
  16. //System.err.println(path + ", time = " + (System.currentTimeMillis() - t));
  17. return Memory.NULL;
  18. }

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

  1. @Signature(@Arg("name"))
  2. public static Memory getResources(Environment env, Memory... args) throws IOException {
  3. Enumeration<URL> list = env.getScope().getClassLoader().getResources(args[0].toString());
  4. ArrayMemory r = new ArrayMemory();
  5. while (list.hasMoreElements()) {
  6. URL url = list.nextElement();
  7. if (url != null) {
  8. ResourceStream rs = new ResourceStream(env, url.openStream());
  9. rs.setPath("res://" + args[0]);
  10. r.add(rs);
  11. }
  12. }
  13. return r.toConstant();
  14. }
  15. }

代码示例来源: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. 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. @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. 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. protected Memory run(String code, boolean returned){
  2. runIndex += 1;
  3. Environment environment = new Environment(newScope());
  4. code = "class TestClass { static function test(){ " + (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. ClassEntity entity = module.findClass("TestClass");
  10. try {
  11. return entity.findMethod("test").invokeStatic(environment);
  12. } catch (Throwable throwable) {
  13. throw new RuntimeException(throwable);
  14. }
  15. }

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

  1. CompileScope compileScope = this.analyzer.getEnvironment().getScope();

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

  1. environment.getScope().loadModule(module);
  2. environment.getScope().addUserModule(module);
  3. environment.registerModule(module);
  4. environment.getModuleManager().addModule(context.getFileName(), module);

相关文章