org.drupal.project.computing
Class DUtils.Php
java.lang.Object
org.drupal.project.computing.DUtils.Php
- Enclosing class:
- DUtils
public static class DUtils.Php
- extends java.lang.Object
Utility class to run PHP snippet
Method Summary |
java.lang.String |
evaluate(java.lang.String phpCode)
Evaluates PHP code and return the output in JSON. |
java.lang.String |
extractVariable(java.io.File phpFile,
java.lang.String phpVar)
Extract the php code snippet that defines phpVar from the php file phpFile. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DUtils.Php
public DUtils.Php(java.lang.String phpExec)
DUtils.Php
public DUtils.Php(DConfig config)
DUtils.Php
public DUtils.Php()
evaluate
public java.lang.String evaluate(java.lang.String phpCode)
throws DSystemExecutionException
- Evaluates PHP code and return the output in JSON. JSR 223 should be the recommended approach, but there is no
good PHP engine. PHP-Java bridge is simply a wrapper of php-cgi and doesn't do much, and is not as flexible as
we call php exec. Quercus works well, but the jar file is too big to include here. In short, we'll simply call
PHP executable and get results in JSON. see [#1220194]
- Parameters:
phpCode
- PHP code snippet.
- Returns:
- PHP code execution output.
- Throws:
DSystemExecutionException
extractVariable
public java.lang.String extractVariable(java.io.File phpFile,
java.lang.String phpVar)
throws DSystemExecutionException
- Extract the php code snippet that defines phpVar from the php file phpFile. For example, to get $databases
from settings.php: extractPhpVariable(DConfig.locateFile("settings.php", "$databases");
PHP code: see parse.php.
FIXME: if the file has someting like "var_dump($databases);", the code would return "$databases);", which is incorrect.
need to fix it in the next release.
- Parameters:
phpFile
- the PHP file to be processed.phpVar
- the PHP variable to be extracted. It can only be the canonical form $xxx, not $xxx['xxx'].
- Returns:
- the PHP code that defines phpVar.
- Throws:
DSystemExecutionException