php.java.script.servlet
Class PhpServletLocalHttpServerScriptEngine

java.lang.Object
  extended by javax.script.AbstractScriptEngine
      extended by php.java.script.SimplePhpScriptEngine
          extended by php.java.script.PhpScriptEngine
              extended by php.java.script.servlet.PhpServletLocalHttpServerScriptEngine
All Implemented Interfaces:
java.io.Closeable, ScriptEngine
Direct Known Subclasses:
PhpServletLocalScriptEngine

public class PhpServletLocalHttpServerScriptEngine
extends PhpScriptEngine

A PHP script engine for Servlets. See ContextLoaderListener for details. 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 getHelloScript() {
       if (script!=null) return script;

       String webCacheDir = ctx.getRealPath(req.getServletPath());
       Reader reader = new StringReader ("<?php echo 'hello from PHP'; ?>");
       return EngineFactory.getPhpScript(webCacheDir, reader);
    }
  2. Acquire a PHP script engine from the EngineFactory:
    ScriptEngine scriptEngine = EngineFactory.getPhpScriptEngine(this, ctx, req, res, "HTTP", 80);
  3. Create a FileReader for the created script file:
    Reader readerHello = EngineFactory.createPhpScriptFileReader(getHelloScript());
  4. Connect its output:
    scriptEngine.getContext().setWriter (out);
  5. Evaluate the engine:
    scriptEngine.eval(readerHello);
  6. Close the reader:
    readerHello.close();


Field Summary
 
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
 
Constructor Summary
PhpServletLocalHttpServerScriptEngine(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
 
Methods inherited from class php.java.script.SimplePhpScriptEngine
close, createBindings, eval, eval, getFactory, release
 
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContext
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhpServletLocalHttpServerScriptEngine

public PhpServletLocalHttpServerScriptEngine(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
Throws:
java.net.MalformedURLException