php.java.script.servlet
Class InvocablePhpServletLocalScriptEngine

java.lang.Object
  extended by javax.script.AbstractScriptEngine
      extended by php.java.script.SimplePhpScriptEngine
          extended by php.java.script.InvocablePhpScriptEngine
              extended by php.java.script.servlet.InvocablePhpServletLocalHttpServerScriptEngine
                  extended by php.java.script.servlet.InvocablePhpServletLocalScriptEngine
All Implemented Interfaces:
Invocable, ScriptEngine
Direct Known Subclasses:
InvocablePhpServletScriptEngine

 class InvocablePhpServletLocalScriptEngine
extends InvocablePhpServletLocalHttpServerScriptEngine

A PHP script engine which implements the Invocable interface for Servlets. See ContextLoaderListener for details. PHP scripts are evaluated as follows:

  1. "http://127.0.0.1:CURRENT_PORT/CURRENT_WEBAPP/java/JavaProxy.php" is requested from Java
  2. Your script is evaluated
  3. <?php java_context()->call(java_closure());?> is called in order to make the script invocable
In order to evaluate PHP methods follow these steps:
  1. Create a factory which creates a PHP script file from a reader using the methods from EngineFactory:
    private static File script;
    private static final File getScriptF() {
       if (script!=null) return script;

       String webCacheDir = ctx.getRealPath(req.getServletPath());
       Reader reader = new StringReader ("<?php function f($v) {return "passed:".$v;} ?>");
       return EngineFactory.getPhpScript(webCacheDir, reader);
    }
  2. Acquire a PHP invocable script engine from the EngineFactory:
    ScriptEngine scriptEngine = EngineFactory.getInvocablePhpScriptEngine(this, ctx, req, res);
  3. Create a FileReader for the created script file:
    Reader readerF = EngineFactory.createPhpScriptFileReader(getScriptF());
  4. Evaluate the engine:
    scriptEngine.eval(readerF);
  5. Close the reader obtained from the EngineFactory:
    readerF.close();
  6. Cast the engine to Invocable:
    Invocable invocableEngine = (Invocable)scriptEngine;
  7. Call PHP functions or methods:
    System.out.println("result from PHP:" + invocableEngine.invoceFunction(f, new Object[]{"arg1"}));
  8. Release the invocable by evaluating the engine again with a NULL value.
    ((Closeable)scriptEngine).close();


Field Summary
 
Fields inherited from class php.java.script.servlet.InvocablePhpServletLocalHttpServerScriptEngine
overrideHosts, port, protocol, proxy, req, res, scriptContext, servlet, servletCtx, url, webPath
 
Fields inherited from class php.java.script.SimplePhpScriptEngine
continuation, ctx, env, name, processEnvironment, resultProxy, script, scriptClosure
 
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
 
Constructor Summary
InvocablePhpServletLocalScriptEngine(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String protocol, int port)
           
 
Method Summary
protected  java.lang.String getProxy()
           
protected  void releaseReservedContinuation()
           
protected  void reserveContinuation()
           
 
Methods inherited from class php.java.script.servlet.InvocablePhpServletLocalHttpServerScriptEngine
eval, evalShortPath, getPhpScriptContext, getPhpScriptContextFactory, getURL, invoke, release, setNewScriptFileContextFactory, setStandardEnvironmentValues
 
Methods inherited from class php.java.script.InvocablePhpScriptEngine
getInterface, getInterface, handleRelease, invoke, invokeFunction, invokeMethod
 
Methods inherited from class php.java.script.SimplePhpScriptEngine
close, createBindings, doEval, eval, eval, getContinuation, getFactory, initialize, setName, setNewContextFactory
 
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InvocablePhpServletLocalScriptEngine

public InvocablePhpServletLocalScriptEngine(javax.servlet.Servlet servlet,
                                            javax.servlet.ServletContext ctx,
                                            javax.servlet.http.HttpServletRequest req,
                                            javax.servlet.http.HttpServletResponse res,
                                            java.lang.String protocol,
                                            int port)
                                     throws java.net.MalformedURLException,
                                            java.net.URISyntaxException
Throws:
java.net.MalformedURLException
java.net.URISyntaxException
Method Detail

getProxy

protected java.lang.String getProxy()
Overrides:
getProxy in class InvocablePhpServletLocalHttpServerScriptEngine

releaseReservedContinuation

protected void releaseReservedContinuation()
Overrides:
releaseReservedContinuation in class InvocablePhpServletLocalHttpServerScriptEngine

reserveContinuation

protected void reserveContinuation()
                            throws ScriptException
Overrides:
reserveContinuation in class InvocablePhpServletLocalHttpServerScriptEngine
Throws:
ScriptException