Hi all,
I'm trying to programmatically execute PHP scripts from within Java
[1] (actually Scala in my case but it's the same). I took some
inspiration from CliQuercus.java as some features were not activated
by default. For example, the database connection is not activated by
default but it's works fine now: I can execute any PHP script.
Now, I'm trying to access the functions and classes that are available
in the compiled pages, using the Quercus Java API [2]. The
documentation is not really helpful there and I don't find the
documentation explaining the whole architecture. I understand that the
main classes are QuercusContext, Env and QuercusPage, but I don't
understand the exact relations between them. For example, I never know
where I have to call init() and start(): I'm not sure about the
semantics of them, if they are needed or not and on which classes I'm
supposed to call them. I also see several getClass functions...
Here is what I have so far:
[[
class QuercusLike {
val quercusContext = {
val context = new QuercusContext
context.init()
context.start()
context.setDatabase(null)
context
}
def update(name:String, value:String):Unit =
quercusContext.setIni(name, value)
def execute(filename:File):Unit = {
val path:Path = quercusContext.getPwd.lookup(filename.getAbsolutePath)
val page:QuercusPage = quercusContext.parse(path)
val os:WriteStream = new WriteStream(StdoutStream.create)
os.setNewlineString("\n")
os.setEncoding("utf-8")
val env:Env = quercusContext.createEnv(page, os, null, null)
env.start()
env.execute()
env.close()
os.flush()
}
}
class Test extends FunSuite {
test("execute php script") {
val phpfile = new File("/home/betehess/php/test/index.php")
val quercus = new QuercusLike
quercus("include_path") = ".:/home/betehess/php/"
quercus.execute(phpfile)
}
}
]]
My goal:
* compile a bunch of PHP files
* instantiating PHP objects from Java (these objects are defining in
the compiled files)
* calling the methods for these PHP objects
Alexandre Bertails, W3C Systems Team.
[1]
http://wiki.caucho.com/Quercus:_Command_Line_Interface_%28CLI%29#Programmatically_executing_PHP_scripts_from_within_Java
[2]
http://wiki.caucho.com/Quercus:_Command_Line_Interface_%28CLI%29#Returning_objects_example
_______________________________________________
resin-interest mailing list
[email protected]
http://maillist.caucho.com/mailman/listinfo/resin-interest