Search in sources :

Example 36 with Invoker

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();
    }
}
Also used : PWebServer(org.develnext.jphp.ext.webserver.classes.PWebServer) CompileScope(php.runtime.env.CompileScope) SplClassLoader(php.runtime.env.SplClassLoader) Invoker(php.runtime.invoke.Invoker) Environment(php.runtime.env.Environment) PWebRequest(org.develnext.jphp.ext.webserver.classes.PWebRequest) PWebResponse(org.develnext.jphp.ext.webserver.classes.PWebResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with Invoker

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();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) LongMemory(php.runtime.memory.LongMemory) KeyValueMemory(php.runtime.memory.KeyValueMemory)

Example 38 with Invoker

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;
}
Also used : ComponentProperties(org.develnext.jphp.swing.ComponentProperties) Invoker(php.runtime.invoke.Invoker) EventProvider(org.develnext.jphp.swing.event.EventProvider)

Example 39 with Invoker

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;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) LongMemory(php.runtime.memory.LongMemory) KeyValueMemory(php.runtime.memory.KeyValueMemory)

Example 40 with Invoker

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;
}
Also used : SplClassLoader(php.runtime.env.SplClassLoader) Invoker(php.runtime.invoke.Invoker)

Aggregations

Invoker (php.runtime.invoke.Invoker)50 Memory (php.runtime.Memory)21 ArrayMemory (php.runtime.memory.ArrayMemory)13 ForeachIterator (php.runtime.lang.ForeachIterator)12 LongMemory (php.runtime.memory.LongMemory)9 ObjectMemory (php.runtime.memory.ObjectMemory)9 KeyValueMemory (php.runtime.memory.KeyValueMemory)7 StringMemory (php.runtime.memory.StringMemory)7 Environment (php.runtime.env.Environment)6 ReferenceMemory (php.runtime.memory.ReferenceMemory)5 SplClassLoader (php.runtime.env.SplClassLoader)4 File (java.io.File)2 MemorySerializer (org.develnext.jphp.json.gson.MemorySerializer)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 TraceInfo (php.runtime.env.TraceInfo)2 FileObject (php.runtime.ext.core.classes.stream.FileObject)2 ActionEvent (java.awt.event.ActionEvent)1 MessageDigest (java.security.MessageDigest)1 Scanner (java.util.Scanner)1 FileFilter (javax.swing.filechooser.FileFilter)1