php.java.script.servlet
Class PhpServletLocalHttpServerScriptEngine
java.lang.Object
javax.script.AbstractScriptEngine
php.java.script.SimplePhpScriptEngine
php.java.script.PhpScriptEngine
php.java.script.servlet.PhpServletLocalHttpServerScriptEngine
- All Implemented Interfaces:
- ScriptEngine
- Direct Known Subclasses:
- PhpServletScriptEngine
class PhpServletLocalHttpServerScriptEngine
- extends PhpScriptEngine
A PHP script engine for Servlets. See ContextLoaderListener for details.
In order to evaluate PHP methods follow these steps:
- 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);
}
- Acquire a PHP script engine from the
EngineFactory:
ScriptEngine scriptEngine = EngineFactory.getPhpScriptEngine(this, ctx, req, res, "HTTP", 80);
- Create a FileReader for the created script file:
Reader readerHello = EngineFactory.createPhpScriptFileReader(getHelloScript());
- Connect its output:
scriptEngine.getContext().setWriter (out);
- Evaluate the engine:
scriptEngine.eval(readerHello);
- Close the reader:
readerHello.close();
|
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)
|
| 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 |
servlet
protected javax.servlet.Servlet servlet
servletCtx
protected javax.servlet.ServletContext servletCtx
req
protected javax.servlet.http.HttpServletRequest req
res
protected javax.servlet.http.HttpServletResponse res
scriptContext
protected PhpSimpleHttpScriptContext scriptContext
webPath
protected java.lang.String webPath
overrideHosts
protected boolean overrideHosts
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
getURL
protected java.net.URL getURL(java.lang.String filePath)
throws java.net.MalformedURLException,
java.net.URISyntaxException
- Throws:
java.net.MalformedURLException
java.net.URISyntaxException
getPhpScriptContext
protected ScriptContext getPhpScriptContext()
- Overrides:
getPhpScriptContext in class SimplePhpScriptEngine
setNewContextFactory
protected void setNewContextFactory()
- Create a new context ID and a environment map which we send to the client.
- Overrides:
setNewContextFactory in class SimplePhpScriptEngine
eval
protected java.lang.Object eval(java.io.Reader reader,
ScriptContext context,
java.lang.String name)
throws ScriptException
- Overrides:
eval in class PhpScriptEngine
- Throws:
ScriptException
releaseReservedContinuation
protected void releaseReservedContinuation()
reserveContinuation
protected void reserveContinuation()
throws ScriptException
- Throws:
ScriptException
setStandardEnvironmentValues
protected void setStandardEnvironmentValues(java.util.Map env)
- Set the context id (X_JAVABRIDGE_CONTEXT) and the override flag (X_JAVABRIDGE_OVERRIDE_HOSTS) into env
- Overrides:
setStandardEnvironmentValues in class SimplePhpScriptEngine
- Parameters:
env - the environment which will be passed to PHP
setStandardEnvironmentValues
static void setStandardEnvironmentValues(IContextFactory ctx,
java.util.Map env,
javax.servlet.http.HttpServletRequest req,
java.lang.String webPath,
boolean overrideHosts)