Search in sources :

Example 1 with SplClassLoader

use of php.runtime.env.SplClassLoader 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 2 with SplClassLoader

use of php.runtime.env.SplClassLoader in project jphp by jphp-compiler.

the class WrapClassLoader method _getSplClassLoader.

protected synchronized SplClassLoader _getSplClassLoader(Environment env) {
    if (splClassLoader == null) {
        ArrayMemory callback = new ArrayMemory();
        callback.add(this);
        callback.add("loadClass");
        Invoker invoker = Invoker.valueOf(env, null, callback);
        splClassLoader = new SplClassLoader(invoker, callback);
    }
    return splClassLoader;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) SplClassLoader(php.runtime.env.SplClassLoader) Invoker(php.runtime.invoke.Invoker)

Example 3 with SplClassLoader

use of php.runtime.env.SplClassLoader 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)

Example 4 with SplClassLoader

use of php.runtime.env.SplClassLoader in project jphp by jphp-compiler.

the class SPLFunctions method spl_autoload_functions.

public static Memory spl_autoload_functions(Environment env) {
    ArrayMemory result = new ArrayMemory();
    for (SplClassLoader loader : env.getClassLoaders()) {
        result.add(loader.getCallback().toImmutable());
    }
    if (result.size() == 0) {
        if (env.__autoload == null) {
            Invoker invoker = Invoker.valueOf(env, null, __autoloadMethod);
            if (invoker != null) {
                env.__autoload = new SplClassLoader(invoker, __autoloadMethod);
                result.add(env.__autoload.getCallback().toImmutable());
            }
        }
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) SplClassLoader(php.runtime.env.SplClassLoader) Invoker(php.runtime.invoke.Invoker)

Aggregations

SplClassLoader (php.runtime.env.SplClassLoader)4 Invoker (php.runtime.invoke.Invoker)4 ArrayMemory (php.runtime.memory.ArrayMemory)2 PWebRequest (org.develnext.jphp.ext.webserver.classes.PWebRequest)1 PWebResponse (org.develnext.jphp.ext.webserver.classes.PWebResponse)1 PWebServer (org.develnext.jphp.ext.webserver.classes.PWebServer)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 CompileScope (php.runtime.env.CompileScope)1 Environment (php.runtime.env.Environment)1