use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WebServerController method get.
@RequestMapping
public void get(OutputStream stream, HttpServletRequest request, HttpServletResponse response) throws Throwable {
PWebServer webServer = webServerMap.get(serverId);
Environment environment = webServer.getEnvironment();
CompileScope scope = environment.getScope();
Environment requestEnvironment;
if (!webServer.isIsolated()) {
requestEnvironment = new Environment(environment);
} else {
if (webServer.isHotReload()) {
scope = new CompileScope(scope);
}
requestEnvironment = new Environment(scope);
}
requestEnvironment.getDefaultBuffer().setOutput(stream);
if (webServer.isImportAutoloaders()) {
for (SplClassLoader loader : environment.getClassLoaders()) {
requestEnvironment.registerAutoloader(loader.forEnvironment(requestEnvironment), false);
}
}
Invoker onRequest = webServer.getOnRequest().forEnvironment(requestEnvironment);
PWebRequest webRequest = new PWebRequest(requestEnvironment, request);
PWebResponse webResponse = new PWebResponse(requestEnvironment, response);
requestEnvironment.setUserValue(webServer);
requestEnvironment.setUserValue(webRequest);
requestEnvironment.setUserValue(webResponse);
try {
onRequest.call(ObjectMemory.valueOf(webRequest), ObjectMemory.valueOf(webResponse));
} catch (Throwable throwable) {
Environment.catchThrowable(throwable, requestEnvironment);
} finally {
requestEnvironment.doFinal();
}
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class ArrayFunctions method array_filter.
public static Memory array_filter(Environment env, TraceInfo trace, Memory input, Memory callback) throws Throwable {
if (!expecting(env, trace, 1, input, ARRAY)) {
return Memory.NULL;
}
Invoker invoker = null;
if (callback != null && callback.toBoolean()) {
invoker = expectingCallback(env, trace, 2, callback);
if (invoker == null)
return Memory.NULL;
}
ArrayMemory result = new ArrayMemory();
ForeachIterator iterator = input.getNewIterator(env, true, false);
while (iterator.next()) {
Object key = iterator.getKey();
Memory value = iterator.getValue();
if (invoker == null) {
if (!value.toBoolean())
continue;
} else if (!invoker.call(value).toBoolean())
continue;
result.put(key, value.toImmutable());
}
return result.toConstant();
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class UIElement method on.
@Signature({ @Arg("name"), @Arg("callback"), @Arg(value = "group", optional = @Optional("general")) })
public Memory on(Environment env, Memory... args) {
Invoker invoker = Invoker.valueOf(env, null, args[1]);
if (invoker == null) {
env.exception(env.trace(), "Argument 2 must be callable");
return Memory.NULL;
}
String name = args[0].toString().toLowerCase();
EventProvider eventProvider = SwingExtension.isAllowedEventType(getComponent(), name);
invoker.setTrace(env.trace());
if (eventProvider == null) {
if (allowedEvents == null || !allowedEvents.contains(name))
throw new IllegalArgumentException("Unknown event type - " + args[0]);
//env.exception(env.trace(), "Unknown event type - " + args[0]);
}
onBindEvent(env, name, invoker);
ComponentProperties properties = SwingExtension.getProperties(getComponent(), true);
properties.updateEvents(env);
getEventContainer().addEvent(name, args[2].toString(), invoker);
return Memory.NULL;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class ArrayFunctions method array_walk.
public static boolean array_walk(Environment env, TraceInfo trace, @Reference Memory input, Memory callback, Memory userData) throws Throwable {
if (!expectingReference(env, trace, input, "array_walk"))
return false;
if (!expecting(env, trace, 1, input, ARRAY))
return false;
Invoker invoker = expectingCallback(env, trace, 2, callback);
if (invoker == null)
return false;
ForeachIterator iterator = input.getNewIterator(env, true, false);
while (iterator.next()) {
Memory item = iterator.getValue();
Memory key = iterator.getMemoryKey();
invoker.call(item, key, userData);
}
return true;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class SPLFunctions method spl_autoload_register.
public static boolean spl_autoload_register(Environment env, TraceInfo trace, Memory callback, boolean _throw, boolean prepend) {
Invoker invoker = expectingCallback(env, trace, 1, callback);
if (invoker == null)
return false;
env.registerAutoloader(new SplClassLoader(invoker, callback), prepend);
return true;
}
Aggregations