Skip to content

Commit 0958ea0

Browse files
committed
Updated README.mkd and .gitignore
1 parent 70cc414 commit 0958ea0

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
target/**
2+
output.html

README.mkd

+68-3
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,78 @@ simple file path), or remotely via HTTP.
5252

5353
Once loaded into memory, several execution options become available to you.
5454

55-
The first is calling global functions, as follows
55+
####Calling global functions
56+
57+
Like so
5658

5759
PHPObject returnValue = php.fx("function_name", arg1, arg2, ...);
5860

59-
The return type for the `fx(String, Object ... args)` method is an instance of our <a href="http://aaroncollegeman.com/static/projects/php-in-java/javadoc/net/collegeman/phpinjava/PHPObject.html">`PHPObject`</a> class, which wraps a special kind of Quercus object called <a href="http://www.caucho.com/resin-javadoc/com/caucho/quercus/env/Value.html">`Value`</a>. Through our `PHPObject` API you can
61+
// or...
62+
PHPObject returnValue = php.fx("function_name", new Object[]{arg1, arg2});
63+
64+
// or...
65+
List args = new ArrayList<Object>();
66+
params.add(arg1);
67+
params.add(arg2);
68+
PHPObject returnValue = php.fx("function_name", args.toArray());
69+
70+
The return type of the `fx(String, Object ... args)` method is an instance of our <a href="http://aaroncollegeman.com/static/projects/php-in-java/javadoc/net/collegeman/phpinjava/PHPObject.html">`PHPObject`</a> class, which wraps a special kind of Quercus object called <a href="http://www.caucho.com/resin-javadoc/com/caucho/quercus/env/Value.html">`Value`</a>. Through our `PHPObject` API you can
6071

6172
* retrieve a `String` version of the `Value`'s content with `toString()`
6273
* read/write object properties with `getProperty(String property)` and `setProperty(String property, Object newValue)`
6374
* invoke object methods with `invokeMethod(String name, Object ... args)`
64-
* gain direct access to the wrapped `Value` object through `getWrappedValue()`
75+
* gain direct access to the wrapped `Value` object through `getWrappedValue()`
76+
77+
####Setting and reading global variables
78+
79+
// write
80+
php.set("variable_name", value);
81+
82+
// read
83+
PHPObject value = php.get("variable_name");
84+
85+
####Instantiating PHP classes
86+
87+
// create instance
88+
PHPObject myInstance = php.newInstance("MyPHPClass", arg1, arg2, ...);
89+
90+
// read and write properties
91+
PHPObject propertyValue = myInstance.getProperty("propertyName");
92+
myInstance.setProperty("propertyName", newValue);
93+
94+
// invoke methods
95+
PHPObject returnValue = myInstance.invokeMethod("methodName", arg1, arg2, ...);
96+
97+
####Capturing the output of your script
98+
99+
// load a script
100+
PHP myScript = new PHP("classpath:/path/to/myscript.php");
101+
102+
// do stuff with your script
103+
myScript.set("global_variable", "foo");
104+
myScript.fx("process_foo");
105+
106+
// capture output
107+
String output = myScript.toString();
108+
109+
####Executing arbitrary snippets of PHP
110+
111+
// when no other scripts have yet been parsed
112+
PHP php = new PHP();
113+
php.snippet("<?php echo 'Hello, world!'");
114+
String output = php.toString(); // == "Hello, world!"
115+
116+
// and when a script block is already open
117+
PHP php = new PHP("classpath:/path/to/myscript.php");
118+
php.snippet("my_function('foo', 'bar');");
119+
String output = php.toString();
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+

0 commit comments

Comments
 (0)