├── .gitignore ├── LICENSE ├── README.md ├── javadoc ├── allclasses-frame.html ├── allclasses-noframe.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-all.html ├── index.html ├── net │ └── collegeman │ │ └── phpinjava │ │ ├── PHP.html │ │ ├── PHPObject.html │ │ ├── class-use │ │ ├── PHP.html │ │ └── PHPObject.html │ │ ├── groovy │ │ ├── GroovyPHP.html │ │ ├── GroovyPHPObject.html │ │ ├── PHP.html │ │ ├── class-use │ │ │ ├── GroovyPHP.html │ │ │ ├── GroovyPHPObject.html │ │ │ └── PHP.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── overview-frame.html ├── overview-summary.html ├── overview-tree.html ├── package-list ├── resources │ └── inherit.gif └── stylesheet.css ├── lib ├── quercus-3.1.jar ├── resin-3.1.jar ├── resin-support-3.1.jar ├── resin-util-3.1.jar ├── spring-core-2.5.6.jar └── spring-test-2.5.6.jar ├── php-in-java.tmproj ├── pom.xml └── src ├── main └── java │ └── net │ └── collegeman │ └── phpinjava │ ├── PHP.java │ ├── PHPObject.java │ └── groovy │ ├── GroovyPHP.java │ └── GroovyPHPObject.java └── test ├── java └── net │ └── collegeman │ └── phpinjava │ └── PHPInJavaTest.java └── resources ├── com └── faux │ └── php │ ├── HelloWorld.php │ ├── HelloWorldClass.php │ └── HelloWorldFx.php └── net └── collegeman └── phpinjava └── php ├── lib └── lib.php └── test.php /.gitignore: -------------------------------------------------------------------------------- 1 | target/** 2 | output.html 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP-in-Java: execute PHP code from within Java and Groovy 2 | 3 | ## Introduction 4 | 5 | ### Why would I want to execute PHP from within my Java code? 6 | 7 | As a consultant, I have spent a lot of time moving back and forth between two Open Source 8 | communities: Java and PHP. Despite some major criticisms against its verbosity and depth, 9 | Java has left an indelible mark on software development and developers. If there's a 10 | programming problem to be solved, odds are you can find a solution or a pattern for solving 11 | it in the Java ecosystem. 12 | 13 | But long before Java was usable in Web applications, PHP was making it possible for a 14 | host of young and old developers to write CGI scripts without shouldering the burden of learning PERL 15 | or C. Like Java, PHP's ecosystem is thriving, especially given its adoption at the heart of 16 | many major Web companies the likes of Facebook and [Squidoo](http://www.squidoo.com). 17 | 18 | Essentially what we have then are two beautiful worlds of software, and a lot of overlap. But 19 | where they don't overlap I seem to find myself working in one language and longing for the 20 | features of the other. For some time now it has been possible to access [Java code from 21 | within PHP](http://www.php.net/manual/en/java.examples-basic.php). But accessing PHP from 22 | within Java has never been as straight-forward. 23 | 24 | ### So, how does it work? 25 | 26 | As it turns out, years ago an enterprising company named [Caucho](http://caucho.com) 27 | decided to write the "most reliable application server in the Open Source market." Their 28 | core product is a Java EE compliant Web server they call *Resin*, and at its heart is *Quercus*: 29 | a fast PHP interpreter written in cross-platform Java. 30 | 31 | So if your goal is to run PHP in a Java EE Web container, then Resin is your tool. 32 | 33 | But I wondered if I could use Quercus from within any old Java application, and at along last gain 34 | access to my favorite PHP libraries from within Java. As it turns out, this is quite possible. 35 | I've recently pushed out my first Java-wrapped PHP library: [GeSHi4J](http://github.com/collegeman/geshi4j), 36 | making my favorite HTML-based code highlighting library available to me in any Java application! 37 | 38 | ## Writing Your Own Wrappers 39 | 40 | ### Using the PHP wrapper API 41 | 42 | The following examples, while not practical on an individual basis, should be used in 43 | combination to create great PHP wrappers. 44 | 45 | #### Executing a PHP script 46 | 47 | PHP scripts may be loaded from the classpath (my personal favorite, as the scripts end up packed 48 | with the Java code in a JAR file), loaded from the local file system (by a `File` object or a 49 | simple file path), or remotely via HTTP. 50 | 51 | PHP php = new PHP("classpath:/com/faux/php/HelloWorld.php"); 52 | 53 | Once loaded into memory, several execution options become available to you. 54 | 55 | #### Calling global functions 56 | 57 | Like so 58 | 59 | PHPObject returnValue = php.fx("function_name", arg1, arg2, ...); 60 | 61 | // or... 62 | PHPObject returnValue = php.fx("function_name", new Object[]{arg1, arg2}); 63 | 64 | // or... 65 | List args = new ArrayList(); 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 `PHPObject` class, which wraps a special kind of Quercus object called `Value`. Through our `PHPObject` API you can 71 | 72 | * retrieve a `String` version of the `Value`'s content with `toString()` 73 | * read/write object properties with `getProperty(String property)` and `setProperty(String property, Object newValue)` 74 | * invoke object methods with `invokeMethod(String name, Object ... args)` 75 | * gain direct access to the wrapped `Value` object through `getWrappedValue()` 76 | 77 | Extra line of text here to create whitespace between unordered list and H4. :-P 78 | 79 | #### Setting and reading global variables 80 | 81 | // write 82 | php.set("variable_name", value); 83 | 84 | // read 85 | PHPObject value = php.get("variable_name"); 86 | 87 | #### Instantiating PHP classes 88 | 89 | // create instance 90 | PHPObject myInstance = php.newInstance("MyPHPClass", arg1, arg2, ...); 91 | 92 | // read and write properties 93 | PHPObject propertyValue = myInstance.getProperty("propertyName"); 94 | myInstance.setProperty("propertyName", newValue); 95 | 96 | // invoke methods 97 | PHPObject returnValue = myInstance.invokeMethod("methodName", arg1, arg2, ...); 98 | 99 | #### Capturing the output of your script 100 | 101 | // load a script 102 | PHP myScript = new PHP("classpath:/path/to/myscript.php"); 103 | 104 | // do stuff with your script 105 | myScript.set("global_variable", "foo"); 106 | myScript.fx("process_foo"); 107 | 108 | // capture output 109 | String output = myScript.toString(); 110 | 111 | ####Executing arbitrary snippets of PHP 112 | 113 | // when no other scripts have yet been parsed 114 | PHP php = new PHP(); 115 | php.snippet(" The intent of `ADAPTER` is to provide the interface that a client expects while 130 | > using the services of a class with a different interface. 131 | 132 | Of course, our use of *interface* here is a bit more abstract (no pun intended): the 133 | interface for your wrapper should reflect the interface of your PHP-scripted class, not the interface 134 | of our Java-based PHP class. 135 | 136 | With a good adapter in place, your users should never have to do this 137 | 138 | PHP php = new PHP("classpath:/path/to/MyPHPClass.php"); 139 | PHPObject instance = php.newInstance("MyPHPClass", arg1, arg2); 140 | PHPObject value = instance.invokeMethod("myMethod", arg3, arg4); 141 | String result = value.toString(); 142 | 143 | but should instead be instantiating and interacting with an API that reflects your PHP class 144 | 145 | MyPHPClass instance = new MyPHPClass(arg1, arg2); 146 | String result = instance.myMethod(arg3, arg4); 147 | 148 | As the author of the wrapper, your job is to take care of bridging the gap between 149 | the native PHP API and your Java-based implementation of the same. 150 | 151 | The best example for writing your own wrapper is my wrapper for GeSHi: [GeSHi4J](http://github.com/collegeman/geshi4j). 152 | 153 | If you've written your own PHP wrapper with PHP-in-Java, [follow me on Twitter](http://twitter.com/collegeman) or [GitHub](http://github.com/collegeman), 154 | and message me with the URL to your own project. 155 | 156 | ### GroovyPHP and GroovyPHPObject 157 | 158 | For you Groovy developers, we've made your job even easier. If you build your adapter on 159 | top of our own Groovy adaptations of `PHP` and `PHPObject`, then your work is practically 160 | complete. 161 | 162 | Taking advantage of the `GroovyObject` interface, the `invokeMethod(String, Object)`, 163 | `getProperty(String)` and `setProperty(String, Object)` methods of `GroovyPHPObject` 164 | comply with the method signatures needed to make their invocation dynamic. 165 | 166 | So you can say goodbye to having to write methods in your adapter to mirror those in 167 | your PHP classes' API. Instead, all you'll need to focus on are implementing the 168 | necessary constructors, and implementing any methods whose return type you wish to 169 | unwrap from `GroovyPHPObject` or Quercus `Value` instances. 170 | 171 | Here's an example of a `GroovyPHP`-based PHP class adapter 172 | 173 | class MyPHPClass { 174 | 175 | def instance 176 | 177 | public MyPHPClass(arg1, arg2) { 178 | instance = new GroovyPHP("classpath:/path/to/MyPHPClass.php").newInstance("MyPHPClass", arg1, arg2) 179 | } 180 | 181 | Integer specificMethod = { arg -> 182 | instance.invokeMethod("specificMethod", arg).toJavaInteger() 183 | } 184 | 185 | } 186 | 187 | And an example of usage 188 | 189 | def myPHP = new MyPHPClass(arg1, arg2) 190 | 191 | // since we need a specific return type here, we've implemented a specific signature 192 | Integer value = myPHP.specificMethod(arg) 193 | 194 | // but for all other use cases, we rely on GroovyObject support 195 | def otherValue = myPHP.someOtherMethod(args) 196 | 197 | This usage example assumes that in the definition of our PHP class `MyPHPClass` there exists 198 | some method `someOtherMethod` that accepts at least one parameter. 199 | 200 | The return type of `myPHP.someOtherMethod(args)` will be another instance of `GroovyPHPObject`, 201 | thus allowing for the same dynamic approach to interfaces provided by the Groovy-powered 202 | instance of `MyPHPClass`. 203 | 204 | ### What's next? 205 | 206 | For the time being, our `PHP` and `GroovyPHP` classes adapt only the most useful 207 | aspects of the Quercus interpreter API. Missing from our implementation are 208 | 209 | * Access to constants 210 | * Access to static methods and properties of classes 211 | * Access to the PHP ini model 212 | * Access to methods for importing PHP scripts (from within Java - you can still use `require`, `include`, `require_once`, and `include_once` in your PHP scripts) 213 | 214 | If you require access to these methods or any other aspect of Quercus, you can always get to it 215 | with the method `PHP#getEnv()` and `GroovyPHP#getEnv()`, each returning an instance of Env, 216 | thus exposing the interpreter API to your own code in totality. 217 | 218 | If you need to make reference to it without downloading this project, you can browse our [javadoc online](http://aaroncollegeman.com/static/projects/java-in-php/javadoc). 219 | 220 | **Good luck, and happy coding.** 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /javadoc/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | All Classes (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | All Classes 21 |
22 | 23 | 24 | 25 | 34 | 35 |
GroovyPHP 26 |
27 | GroovyPHPObject 28 |
29 | PHP 30 |
31 | PHPObject 32 |
33 |
36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /javadoc/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | All Classes (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | All Classes 21 |
22 | 23 | 24 | 25 | 34 | 35 |
GroovyPHP 26 |
27 | GroovyPHPObject 28 |
29 | PHP 30 |
31 | PHPObject 32 |
33 |
36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /javadoc/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Constant Field Values (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Constant Field Values

86 |
87 |
88 | Contents 90 | 91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 114 | 117 | 118 | 119 | 120 | 123 | 139 | 140 |
115 | 116 |
141 | 142 | 143 | 144 |
145 | Copyright © 2009. All Rights Reserved. 146 | 147 | 148 | -------------------------------------------------------------------------------- /javadoc/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Deprecated List (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Deprecated API

86 |
87 |
88 | Contents 90 | 91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 114 | 117 | 118 | 119 | 120 | 123 | 139 | 140 |
115 | 116 |
141 | 142 | 143 | 144 |
145 | Copyright © 2009. All Rights Reserved. 146 | 147 | 148 | -------------------------------------------------------------------------------- /javadoc/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | API Help (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | How This API Document Is Organized

86 |
87 | This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

88 | Overview

89 |
90 | 91 |

92 | The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

93 |

94 | Package

95 |
96 | 97 |

98 | Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

100 |
101 |

102 | Class/Interface

103 |
104 | 105 |

106 | Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

112 | Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
113 | 114 |

115 | Annotation Type

116 |
117 | 118 |

119 | Each annotation type has its own separate page with the following sections:

121 |
122 | 123 |

124 | Enum

125 |
126 | 127 |

128 | Each enum has its own separate page with the following sections:

130 |
131 |

132 | Use

133 |
134 | Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
135 |

136 | Tree (Class Hierarchy)

137 |
138 | There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object. 140 |
141 |

142 | Deprecated API

143 |
144 | The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
145 |

146 | Index

147 |
148 | The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
149 |

150 | Prev/Next

151 | These links take you to the next or previous class, interface, package, or related page.

152 | Frames/No Frames

153 | These links show and hide the HTML frames. All pages are available with or without frames. 154 |

155 |

156 | Serialized Form

157 | Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. 158 |

159 |

160 | Constant Field Values

161 | The Constant Field Values page lists the static final fields and their values. 162 |

163 | 164 | 165 | This help file applies to API documentation generated using the standard doclet. 166 | 167 |
168 |


169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 191 | 194 | 195 | 196 | 197 | 200 | 216 | 217 |
192 | 193 |
218 | 219 | 220 | 221 |
222 | Copyright © 2009. All Rights Reserved. 223 | 224 | 225 | -------------------------------------------------------------------------------- /javadoc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | php-in-java 1.0.0 API 9 | 10 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | <H2> 32 | Frame Alert</H2> 33 | 34 | <P> 35 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 36 | <BR> 37 | Link to<A HREF="overview-summary.html">Non-frame version.</A> 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/PHPObject.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | PHPObject (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 | 79 | 81 | 83 | 84 |
53 | 54 |
85 | 86 | 87 | 88 |
89 | 90 |

91 | 92 | net.collegeman.phpinjava 93 |
94 | Class PHPObject

95 |
 96 | java.lang.Object
 97 |   extended by net.collegeman.phpinjava.PHPObject
 98 | 
99 |
100 |
101 |
public class PHPObject
extends java.lang.Object
102 | 103 | 104 |

105 | A thin wrapper around instances of com.caucho.quercus.env.Value, themselves representing 106 | instances of PHP objects. This wrapper makes it easier to invoke methods and set and get properties. 107 |

108 | 109 |

110 |

111 |
Author:
112 |
Aaron Collegeman aaron@collegeman.net
113 |
114 |
115 | 116 |

117 | 118 | 119 | 120 | 121 | 122 | 123 | 125 | 126 | 127 | 132 | 133 |
124 | Constructor Summary
PHPObject(com.caucho.quercus.env.Env env, 128 | com.caucho.quercus.env.Value value) 129 | 130 |
131 |            
134 |   135 | 136 | 137 | 138 | 139 | 140 | 142 | 143 | 144 | 146 | 150 | 151 | 152 | 154 | 158 | 159 | 160 | 162 | 168 | 169 | 170 | 172 | 177 | 178 | 179 | 181 | 185 | 186 |
141 | Method Summary
145 |  PHPObjectgetProperty(java.lang.String name) 147 | 148 |
149 |           Retrieve a public property name of the wrapped Value.
153 |  com.caucho.quercus.env.ValuegetWrappedValue() 155 | 156 |
157 |            
161 |  PHPObjectinvokeMethod(java.lang.String name, 163 | java.lang.Object... args) 164 | 165 |
166 |           Invoke the method name on wrapped Value object, passing 167 | into the invocation parameters args.
171 |  PHPObjectsetProperty(java.lang.String name, 173 | java.lang.Object value) 174 | 175 |
176 |           Set a public property of the wrapped Value to value.
180 |  java.lang.StringtoString() 182 | 183 |
184 |            
187 |   188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
196 |   197 |

198 | 199 | 200 | 201 | 202 | 203 | 204 | 206 | 207 |
205 | Constructor Detail
208 | 209 |

210 | PHPObject

211 |
212 | public PHPObject(com.caucho.quercus.env.Env env,
213 |                  com.caucho.quercus.env.Value value)
214 |
215 |
216 | 217 | 218 | 219 | 220 | 221 | 222 | 224 | 225 |
223 | Method Detail
226 | 227 |

228 | invokeMethod

229 |
230 | public final PHPObject invokeMethod(java.lang.String name,
231 |                                     java.lang.Object... args)
232 |
233 |
Invoke the method name on wrapped Value object, passing 234 | into the invocation parameters args. 235 |

236 |

237 | 238 |
Returns:
An instance of PHPObject, wrapping any return value of nameed method.
239 |
240 |
241 |
242 | 243 |

244 | setProperty

245 |
246 | public final PHPObject setProperty(java.lang.String name,
247 |                                    java.lang.Object value)
248 |
249 |
Set a public property of the wrapped Value to value. 250 |

251 |

252 | 253 |
Returns:
This instance of PHPObject, to support method chaining.
254 |
255 |
256 |
257 | 258 |

259 | getProperty

260 |
261 | public final PHPObject getProperty(java.lang.String name)
262 |
263 |
Retrieve a public property name of the wrapped Value. 264 |

265 |

266 | 267 |
Returns:
A new instance of PHPObject, wrapping the retrieved property.
268 |
269 |
270 |
271 | 272 |

273 | getWrappedValue

274 |
275 | public com.caucho.quercus.env.Value getWrappedValue()
276 |
277 |
278 |
279 |
280 |
281 |
282 | 283 |

284 | toString

285 |
286 | public java.lang.String toString()
287 |
288 |
289 |
Overrides:
toString in class java.lang.Object
290 |
291 |
292 |
293 |
294 |
295 | 296 |
297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 319 | 322 | 323 | 324 | 325 | 328 | 344 | 345 | 346 | 348 | 350 | 351 |
320 | 321 |
352 | 353 | 354 | 355 |
356 | Copyright © 2009. All Rights Reserved. 357 | 358 | 359 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/class-use/PHP.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Uses of Class net.collegeman.phpinjava.PHP (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Uses of Class
net.collegeman.phpinjava.PHP

86 |
87 | 88 | 89 | 90 | 92 | 93 | 94 | 95 | 96 | 97 |
91 | Packages that use PHP
net.collegeman.phpinjava  
98 |   99 |

100 | 101 | 102 | 103 | 105 | 106 |
104 | Uses of PHP in net.collegeman.phpinjava
107 |   108 |

109 | 110 | 111 | 112 | 113 | 114 | 115 | 117 | 122 | 123 | 124 | 126 | 131 | 132 | 133 | 135 | 140 | 141 |
Methods in net.collegeman.phpinjava that return PHP
116 |  PHPPHP.clear() 118 | 119 |
120 |           Clear any text buffered by script execution, presumably in preparation for 121 | executing another PHP snippet.
125 |  PHPPHP.set(java.lang.String name, 127 | java.lang.Object obj) 128 | 129 |
130 |           Set the value of a global variable in the PHP execution environment.
134 |  PHPPHP.snippet(java.lang.String snippet) 136 | 137 |
138 |           Parse and execute a snippet of PHP script, adding to the 139 | execution context any artifacts and/or output generated by the code.
142 |   143 |

144 |


145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 167 | 170 | 171 | 172 | 173 | 176 | 192 | 193 |
168 | 169 |
194 | 195 | 196 | 197 |
198 | Copyright © 2009. All Rights Reserved. 199 | 200 | 201 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/class-use/PHPObject.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Uses of Class net.collegeman.phpinjava.PHPObject (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Uses of Class
net.collegeman.phpinjava.PHPObject

86 |
87 | 88 | 89 | 90 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
91 | Packages that use PHPObject
net.collegeman.phpinjava  
net.collegeman.phpinjava.groovy  
102 |   103 |

104 | 105 | 106 | 107 | 109 | 110 |
108 | Uses of PHPObject in net.collegeman.phpinjava
111 |   112 |

113 | 114 | 115 | 116 | 117 | 118 | 119 | 121 | 126 | 127 | 128 | 130 | 134 | 135 | 136 | 138 | 142 | 143 | 144 | 146 | 152 | 153 | 154 | 156 | 162 | 163 | 164 | 166 | 171 | 172 |
Methods in net.collegeman.phpinjava that return PHPObject
120 |  PHPObjectPHP.fx(java.lang.String fxName, 122 | java.lang.Object... args) 123 | 124 |
125 |           Call the PHP function named fxName with arguments args
129 |  PHPObjectPHP.get(java.lang.String name) 131 | 132 |
133 |           Retrieve the value of a global varialbe in the PHP execution environment.
137 |  PHPObjectPHPObject.getProperty(java.lang.String name) 139 | 140 |
141 |           Retrieve a public property name of the wrapped Value.
145 |  PHPObjectPHPObject.invokeMethod(java.lang.String name, 147 | java.lang.Object... args) 148 | 149 |
150 |           Invoke the method name on wrapped Value object, passing 151 | into the invocation parameters args.
155 |  PHPObjectPHP.newInstance(java.lang.String className, 157 | java.lang.Object... args) 158 | 159 |
160 |           Create a new instance of the PHP class className, initialized with 161 | arguments args.
165 |  PHPObjectPHPObject.setProperty(java.lang.String name, 167 | java.lang.Object value) 168 | 169 |
170 |           Set a public property of the wrapped Value to value.
173 |   174 |

175 | 176 | 177 | 178 | 180 | 181 |
179 | Uses of PHPObject in net.collegeman.phpinjava.groovy
182 |   183 |

184 | 185 | 186 | 187 | 188 | 189 | 190 | 196 | 197 |
Constructors in net.collegeman.phpinjava.groovy with parameters of type PHPObject
GroovyPHPObject(PHPObject obj) 191 | 192 |
193 |           The GroovyPHPObject is only allowed to wrap one kind of 194 | object: a PHPObject - the wrapper used by many methods in 195 | the PHP class.
198 |   199 |

200 |


201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 223 | 226 | 227 | 228 | 229 | 232 | 248 | 249 |
224 | 225 |
250 | 251 | 252 | 253 |
254 | Copyright © 2009. All Rights Reserved. 255 | 256 | 257 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/groovy/PHP.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | PHP (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 | 79 | 81 | 83 | 84 |
53 | 54 |
85 | 86 | 87 | 88 |
89 | 90 |

91 | 92 | net.collegeman.phpinjava.groovy 93 |
94 | Class PHP

95 |
 96 | java.lang.Object
 97 |   extended by groovy.lang.GroovyObjectSupport
 98 |       extended by net.collegeman.phpinjava.groovy.PHP
 99 | 
100 |
101 |
All Implemented Interfaces:
groovy.lang.GroovyObject
102 |
103 |
104 |
105 |
public class PHP
extends groovy.lang.GroovyObjectSupport
106 | 107 | 108 |

109 |


110 | 111 |

112 | 113 | 114 | 115 | 116 | 117 | 118 | 120 | 121 | 122 | 126 | 127 |
119 | Constructor Summary
PHP() 123 | 124 |
125 |            
128 |   129 | 130 | 131 | 132 | 133 | 134 | 136 | 137 |
135 | Method Summary
138 |   139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 |
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty
147 |   148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
156 |   157 |

158 | 159 | 160 | 161 | 162 | 163 | 164 | 166 | 167 |
165 | Constructor Detail
168 | 169 |

170 | PHP

171 |
172 | public PHP()
173 |
174 |
175 | 176 |
177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 199 | 202 | 203 | 204 | 205 | 208 | 224 | 225 | 226 | 228 | 230 | 231 |
200 | 201 |
232 | 233 | 234 | 235 |
236 | Copyright © 2009. All Rights Reserved. 237 | 238 | 239 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/groovy/class-use/GroovyPHP.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Uses of Class net.collegeman.phpinjava.groovy.GroovyPHP (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Uses of Class
net.collegeman.phpinjava.groovy.GroovyPHP

86 |
87 | No usage of net.collegeman.phpinjava.groovy.GroovyPHP 88 |

89 |


90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 112 | 115 | 116 | 117 | 118 | 121 | 137 | 138 |
113 | 114 |
139 | 140 | 141 | 142 |
143 | Copyright © 2009. All Rights Reserved. 144 | 145 | 146 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/groovy/class-use/GroovyPHPObject.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Uses of Class net.collegeman.phpinjava.groovy.GroovyPHPObject (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Uses of Class
net.collegeman.phpinjava.groovy.GroovyPHPObject

86 |
87 | 88 | 89 | 90 | 92 | 93 | 94 | 95 | 96 | 97 |
91 | Packages that use GroovyPHPObject
net.collegeman.phpinjava.groovy  
98 |   99 |

100 | 101 | 102 | 103 | 105 | 106 |
104 | Uses of GroovyPHPObject in net.collegeman.phpinjava.groovy
107 |   108 |

109 | 110 | 111 | 112 | 113 | 114 | 115 | 117 | 122 | 123 | 124 | 126 | 130 | 131 | 132 | 134 | 139 | 140 |
Methods in net.collegeman.phpinjava.groovy that return GroovyPHPObject
116 |  GroovyPHPObjectGroovyPHP.fx(java.lang.String fxName, 118 | java.lang.Object... args) 119 | 120 |
121 |            
125 |  GroovyPHPObjectGroovyPHP.get(java.lang.String name) 127 | 128 |
129 |            
133 |  GroovyPHPObjectGroovyPHP.newInstance(java.lang.String className, 135 | java.lang.Object... args) 136 | 137 |
138 |            
141 |   142 |

143 |


144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 166 | 169 | 170 | 171 | 172 | 175 | 191 | 192 |
167 | 168 |
193 | 194 | 195 | 196 |
197 | Copyright © 2009. All Rights Reserved. 198 | 199 | 200 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/groovy/class-use/PHP.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Uses of Class net.collegeman.phpinjava.groovy.PHP (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Uses of Class
net.collegeman.phpinjava.groovy.PHP

86 |
87 | No usage of net.collegeman.phpinjava.groovy.PHP 88 |

89 |


90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 112 | 115 | 116 | 117 | 118 | 121 | 137 | 138 |
113 | 114 |
139 | 140 | 141 | 142 |
143 | Copyright © 2009. All Rights Reserved. 144 | 145 | 146 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/groovy/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | net.collegeman.phpinjava.groovy (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | net.collegeman.phpinjava.groovy 21 | 22 | 23 | 30 | 31 |
24 | Classes  25 | 26 |
27 | GroovyPHP 28 |
29 | GroovyPHPObject
32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/groovy/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | net.collegeman.phpinjava.groovy (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |

84 | Package net.collegeman.phpinjava.groovy 85 |

86 | 87 | 88 | 89 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 101 | 102 |
90 | Class Summary
GroovyPHP 
GroovyPHPObjectA simple implementation of the GroovyObject interface, allowing 99 | for the seamless introduction of PHP-powered APIs into your Groovy applications 100 | (including Grails Web apps!).
103 |   104 | 105 |

106 |

107 |
108 |
109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 131 | 134 | 135 | 136 | 137 | 140 | 156 | 157 |
132 | 133 |
158 | 159 | 160 | 161 |
162 | Copyright © 2009. All Rights Reserved. 163 | 164 | 165 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/groovy/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | net.collegeman.phpinjava.groovy Class Hierarchy (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Hierarchy For Package net.collegeman.phpinjava.groovy 86 |

87 |
88 |
89 |
Package Hierarchies:
All Packages
90 |
91 |

92 | Class Hierarchy 93 |

94 | 101 |
102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 124 | 127 | 128 | 129 | 130 | 133 | 149 | 150 |
125 | 126 |
151 | 152 | 153 | 154 |
155 | Copyright © 2009. All Rights Reserved. 156 | 157 | 158 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/groovy/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Uses of Package net.collegeman.phpinjava.groovy (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Uses of Package
net.collegeman.phpinjava.groovy

86 |
87 | 88 | 89 | 90 | 92 | 93 | 94 | 95 | 96 | 97 |
91 | Packages that use net.collegeman.phpinjava.groovy
net.collegeman.phpinjava.groovy  
98 |   99 |

100 | 101 | 102 | 103 | 105 | 106 | 107 | 113 | 114 |
104 | Classes in net.collegeman.phpinjava.groovy used by net.collegeman.phpinjava.groovy
GroovyPHPObject 108 | 109 |
110 |           A simple implementation of the GroovyObject interface, allowing 111 | for the seamless introduction of PHP-powered APIs into your Groovy applications 112 | (including Grails Web apps!).
115 |   116 |

117 |


118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 140 | 143 | 144 | 145 | 146 | 149 | 165 | 166 |
141 | 142 |
167 | 168 | 169 | 170 |
171 | Copyright © 2009. All Rights Reserved. 172 | 173 | 174 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | net.collegeman.phpinjava (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | net.collegeman.phpinjava 21 | 22 | 23 | 30 | 31 |
24 | Classes  25 | 26 |
27 | PHP 28 |
29 | PHPObject
32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | net.collegeman.phpinjava (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |

84 | Package net.collegeman.phpinjava 85 |

86 | 87 | 88 | 89 | 91 | 92 | 93 | 94 | 96 | 97 | 98 | 99 | 101 | 102 |
90 | Class Summary
PHPInstances of this class wrap one or more PHP scripts, making it possible for 95 | those scripts to be compiled into memory and
PHPObjectA thin wrapper around instances of com.caucho.quercus.env.Value, themselves representing 100 | instances of PHP objects.
103 |   104 | 105 |

106 |

107 |
108 |
109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 131 | 134 | 135 | 136 | 137 | 140 | 156 | 157 |
132 | 133 |
158 | 159 | 160 | 161 |
162 | Copyright © 2009. All Rights Reserved. 163 | 164 | 165 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | net.collegeman.phpinjava Class Hierarchy (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Hierarchy For Package net.collegeman.phpinjava 86 |

87 |
88 |
89 |
Package Hierarchies:
All Packages
90 |
91 |

92 | Class Hierarchy 93 |

94 | 98 |
99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 121 | 124 | 125 | 126 | 127 | 130 | 146 | 147 |
122 | 123 |
148 | 149 | 150 | 151 |
152 | Copyright © 2009. All Rights Reserved. 153 | 154 | 155 | -------------------------------------------------------------------------------- /javadoc/net/collegeman/phpinjava/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Uses of Package net.collegeman.phpinjava (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Uses of Package
net.collegeman.phpinjava

86 |
87 | 88 | 89 | 90 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
91 | Packages that use net.collegeman.phpinjava
net.collegeman.phpinjava  
net.collegeman.phpinjava.groovy  
102 |   103 |

104 | 105 | 106 | 107 | 109 | 110 | 111 | 116 | 117 | 118 | 123 | 124 |
108 | Classes in net.collegeman.phpinjava used by net.collegeman.phpinjava
PHP 112 | 113 |
114 |           Instances of this class wrap one or more PHP scripts, making it possible for 115 | those scripts to be compiled into memory and
PHPObject 119 | 120 |
121 |           A thin wrapper around instances of com.caucho.quercus.env.Value, themselves representing 122 | instances of PHP objects.
125 |   126 |

127 | 128 | 129 | 130 | 132 | 133 | 134 | 139 | 140 |
131 | Classes in net.collegeman.phpinjava used by net.collegeman.phpinjava.groovy
PHPObject 135 | 136 |
137 |           A thin wrapper around instances of com.caucho.quercus.env.Value, themselves representing 138 | instances of PHP objects.
141 |   142 |

143 |


144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 166 | 169 | 170 | 171 | 172 | 175 | 191 | 192 |
167 | 168 |
193 | 194 | 195 | 196 |
197 | Copyright © 2009. All Rights Reserved. 198 | 199 | 200 | -------------------------------------------------------------------------------- /javadoc/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Overview List (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 |
23 |
26 | 27 | 28 | 29 | 39 | 40 |
All Classes 30 |

31 | 32 | Packages 33 |
34 | net.collegeman.phpinjava 35 |
36 | net.collegeman.phpinjava.groovy 37 |
38 |

41 | 42 |

43 |   44 | 45 | 46 | -------------------------------------------------------------------------------- /javadoc/overview-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Overview (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |


30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | php-in-java 1.0.0 API 86 |

87 |
88 | 89 | 90 | 91 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 |
92 | Packages
net.collegeman.phpinjava 
net.collegeman.phpinjava.groovy 
103 | 104 |

105 |  


106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 128 | 131 | 132 | 133 | 134 | 137 | 153 | 154 |
129 | 130 |
155 | 156 | 157 | 158 |
159 | Copyright © 2009. All Rights Reserved. 160 | 161 | 162 | -------------------------------------------------------------------------------- /javadoc/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Class Hierarchy (php-in-java 1.0.0 API) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 55 | 56 | 57 | 58 | 61 | 77 | 78 |
53 | 54 |
79 | 80 | 81 | 82 |
83 |
84 |

85 | Hierarchy For All Packages

86 |
87 |
88 |
Package Hierarchies:
net.collegeman.phpinjava, net.collegeman.phpinjava.groovy
89 |
90 |

91 | Class Hierarchy 92 |

93 | 100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 123 | 126 | 127 | 128 | 129 | 132 | 148 | 149 |
124 | 125 |
150 | 151 | 152 | 153 |
154 | Copyright © 2009. All Rights Reserved. 155 | 156 | 157 | -------------------------------------------------------------------------------- /javadoc/package-list: -------------------------------------------------------------------------------- 1 | net.collegeman.phpinjava 2 | net.collegeman.phpinjava.groovy 3 | -------------------------------------------------------------------------------- /javadoc/resources/inherit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OndraZizka/php-in-java/4f0e9bdbedac025c4b0f00cce035e563a48d57a6/javadoc/resources/inherit.gif -------------------------------------------------------------------------------- /javadoc/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | 3 | /* Define colors, fonts and other style attributes here to override the defaults */ 4 | 5 | /* Page background color */ 6 | body { background-color: #FFFFFF; color:#000000 } 7 | 8 | /* Headings */ 9 | h1 { font-size: 145% } 10 | 11 | /* Table colors */ 12 | .TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */ 13 | .TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */ 14 | .TableRowColor { background: #FFFFFF; color:#000000 } /* White */ 15 | 16 | /* Font used in left-hand frame lists */ 17 | .FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 } 18 | .FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } 19 | .FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } 20 | 21 | /* Navigation bar fonts and colors */ 22 | .NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */ 23 | .NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */ 24 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;} 25 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;} 26 | 27 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} 28 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} 29 | 30 | -------------------------------------------------------------------------------- /lib/quercus-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OndraZizka/php-in-java/4f0e9bdbedac025c4b0f00cce035e563a48d57a6/lib/quercus-3.1.jar -------------------------------------------------------------------------------- /lib/resin-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OndraZizka/php-in-java/4f0e9bdbedac025c4b0f00cce035e563a48d57a6/lib/resin-3.1.jar -------------------------------------------------------------------------------- /lib/resin-support-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OndraZizka/php-in-java/4f0e9bdbedac025c4b0f00cce035e563a48d57a6/lib/resin-support-3.1.jar -------------------------------------------------------------------------------- /lib/resin-util-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OndraZizka/php-in-java/4f0e9bdbedac025c4b0f00cce035e563a48d57a6/lib/resin-util-3.1.jar -------------------------------------------------------------------------------- /lib/spring-core-2.5.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OndraZizka/php-in-java/4f0e9bdbedac025c4b0f00cce035e563a48d57a6/lib/spring-core-2.5.6.jar -------------------------------------------------------------------------------- /lib/spring-test-2.5.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OndraZizka/php-in-java/4f0e9bdbedac025c4b0f00cce035e563a48d57a6/lib/spring-test-2.5.6.jar -------------------------------------------------------------------------------- /php-in-java.tmproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | documents 6 | 7 | 8 | expanded 9 | 10 | name 11 | php-in-java 12 | regexFolderFilter 13 | !.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$ 14 | sourceDirectory 15 | 16 | 17 | 18 | fileHierarchyDrawerWidth 19 | 258 20 | metaData 21 | 22 | showFileHierarchyDrawer 23 | 24 | windowFrame 25 | {{14, 0}, {1005, 778}} 26 | 27 | 28 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | net.collegeman.phpinjava 5 | php-in-java 6 | jar 7 | 1.1.1 8 | php-in-java 9 | http://aaroncollegeman.com/projects/php-in-java 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 17 | 1.5 18 | 1.5 19 | 20 | 21 | 22 | org.apache.maven.plugins 23 | maven-javadoc-plugin 24 | 25 | ${project.basedir} 26 | javadoc 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | junit 37 | junit 38 | 3.8.1 39 | test 40 | 41 | 42 | 43 | 44 | javax.servlet 45 | servlet-api 46 | 2.5 47 | 48 | 49 | 50 | 51 | javax.mail 52 | mail 53 | 1.4.1 54 | 55 | 56 | 57 | 58 | org.springframework 59 | spring-test 60 | 2.5.6 61 | 62 | 63 | 64 | org.springframework 65 | spring-core 66 | 2.5.6 67 | 68 | 69 | 70 | 71 | org.codehaus.groovy 72 | groovy-all 73 | 1.7.0 74 | 75 | 76 | 77 | 78 | com.caucho 79 | quercus 80 | 3.1 81 | 82 | 83 | com.caucho 84 | resin 85 | 3.1 86 | 87 | 88 | com.caucho 89 | resin-support 90 | 3.1 91 | 92 | 93 | com.caucho 94 | resin-util 95 | 3.1 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/main/java/net/collegeman/phpinjava/PHP.java: -------------------------------------------------------------------------------- 1 | package net.collegeman.phpinjava; 2 | 3 | /** 4 | * PHP-in-Java PHP wrapper for Java and Groovy. 5 | * Copyright (C) 2009-2010 Collegeman.net, LLC. 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | import com.caucho.quercus.*; 23 | import com.caucho.vfs.*; 24 | import com.caucho.util.*; 25 | import com.caucho.quercus.env.*; 26 | import com.caucho.quercus.page.*; 27 | 28 | import java.util.logging.*; 29 | import java.net.*; 30 | import java.io.*; 31 | import java.util.*; 32 | 33 | import org.springframework.mock.web.*; 34 | 35 | /** 36 | *

Instances of this class wrap one or more PHP scripts, making it possible for 37 | * those scripts to be compiled into memory and

38 | * 43 | *

Also, once instantiated, the PHP object can be used to compile and cache 44 | * arbitrary snippets of PHP into a single PHP script.

45 | *

Quercus and Resin versus PHP-in-Java

46 | *

Our PHP-in-Java library is built on top of Quercus.

47 | *

Quercus is a PHP interpreter written in Java, distributed by Caucho. 48 | * Quercus is embedded inside a Java EE compliant application server called Resin. Resin gives 49 | * you the flexibility of writing PHP applications that have access to the Java ecosystem, and is 50 | * many times more efficient than running PHP in Apache.

51 | *

If you're wanting to run large-scale PHP applications on Java, you need to take a look at Resin. 52 | * But if you're just looking to make PHP libraries like GeSHi 53 | * available to your Java and Groovy code, our PHP-in-Java library is for you.

54 | *

Using PHP-in-Java

55 | *

For usage instructions, please refer to README on our Github project.

56 | * @author Aaron Collegeman aaron@collegeman.net 57 | */ 58 | public class PHP { 59 | 60 | private static final Logger log = Logger.getLogger(PHP.class.getName()); 61 | private static Quercus quercus; 62 | 63 | private synchronized Quercus getQuercus() { 64 | if (quercus == null) { 65 | quercus = new Quercus(); 66 | } 67 | return quercus; 68 | } 69 | 70 | /** 71 | * Initialize a PHP wrapper with either an intial PHP script or a local directory. 72 | *

url can take one of several forms:

73 | * 78 | * @param url An initial PHP script to load or a local directory 79 | */ 80 | public PHP(String url) { 81 | this(url, PHP.class.getClassLoader()); 82 | } 83 | 84 | private QuercusPage main; 85 | 86 | /** 87 | * Create an empty instance of PHP. This instance can be used to execute arbitrary 88 | * snippets of PHP. But if you're looking to load a PHP library and execute snippets against that, 89 | * best to use one of the other constructors, {@link #PHP(String)} or {@link #PHP(String, ClassLoader)} 90 | */ 91 | public PHP() {} 92 | 93 | 94 | /** 95 | * Initialize a PHP wrapper with a specific ClassLoader instance. Refer 96 | * to the doc for {@link #PHP(String)} for a description of the url parameter. 97 | */ 98 | public PHP(String url, ClassLoader classLoader) { 99 | if (url == null || url.length() < 1) 100 | throw new IllegalArgumentException("[url] parameter must be defined"); 101 | 102 | if (classLoader == null) 103 | throw new IllegalArgumentException("[classLoader] parameter must be defined"); 104 | 105 | // classpath reference 106 | if (url.indexOf("classpath:/") == 0) { 107 | URL resource = classLoader.getResource(url.substring(11)); 108 | File ref = new File(resource.getPath()); 109 | initByFile(ref); 110 | } 111 | 112 | // remote script 113 | else if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) { 114 | try { 115 | URLConnection conn = new URL(url).openConnection(); 116 | initByInputStream(conn.getInputStream()); 117 | } catch (Exception e) { 118 | throw new RuntimeException(e); 119 | } 120 | } 121 | 122 | // file reference 123 | else { 124 | initByFile(new File(url)); 125 | } 126 | 127 | } 128 | 129 | /** 130 | * Initialize a PHP wrapper with a specific File loaded by the host. 131 | * @param file A file full of PHP script 132 | */ 133 | public PHP(File file) { 134 | initByFile(file); 135 | } 136 | 137 | private void initByInputStream(InputStream stream) { 138 | try { 139 | StringBuilder sourceCode = new StringBuilder(1024); 140 | BufferedReader in = new BufferedReader(new InputStreamReader(stream)); 141 | char[] buffer = new char[1024]; 142 | int read = 0; 143 | while ((read = in.read(buffer)) != -1) 144 | sourceCode.append(buffer, 0, read); 145 | in.close(); 146 | 147 | snippet(sourceCode.toString()); 148 | } catch (Exception e) { 149 | throw new RuntimeException(e); 150 | } 151 | } 152 | 153 | private void initByFile(File ref) { 154 | if (!ref.exists()) { 155 | throw new RuntimeException(new FileNotFoundException("No PHP file or directory at ["+ref.getAbsolutePath()+"]")); 156 | } 157 | 158 | if (ref.isDirectory()) { 159 | snippet(""); 160 | getEnv().setPwd(new FilePath(ref.getAbsolutePath())); 161 | } 162 | else { 163 | try { 164 | main = getQuercus().parse(new FilePath(ref.getAbsolutePath())); 165 | } catch (IOException e) { 166 | throw new RuntimeException(e); 167 | } 168 | 169 | initEnv(main); 170 | 171 | File dir = ref.getParentFile(); 172 | if (dir != null) 173 | getEnv().setPwd(new FilePath(ref.getParentFile().getAbsolutePath())); 174 | 175 | main.executeTop(getEnv()); 176 | } 177 | } 178 | 179 | private Env env; 180 | private MockHttpServletRequest request; 181 | private MockHttpServletResponse response; 182 | private StreamImpl out; 183 | private WriteStream ws; 184 | 185 | private void initEnv(QuercusPage page) { 186 | if (env == null) { 187 | request = new MockHttpServletRequest(); 188 | response = new MockHttpServletResponse(); 189 | 190 | WriterStreamImpl writer = new WriterStreamImpl(); 191 | try { 192 | writer.setWriter(response.getWriter()); 193 | } catch (UnsupportedEncodingException e) { 194 | throw new RuntimeException(e); 195 | } 196 | 197 | out = writer; 198 | ws = new WriteStream(out); 199 | ws.setNewlineString("\n"); 200 | 201 | env = getQuercus().createEnv(page, ws, request, response); 202 | 203 | env.setPwd(new FilePath(System.getProperty("user.dir"))); 204 | 205 | env.start(); 206 | } 207 | } 208 | 209 | /** 210 | * Retrieves the Quercus execution environment, which your Java code 211 | * can use to interact directly with the Quercus parsing engine. 212 | * @link http://www.caucho.com/resin-javadoc/com/caucho/quercus/env/Env.html 213 | * @throws IllegalStateException When environment has not yet been initialized 214 | */ 215 | public final Env getEnv() { 216 | if (env == null) 217 | throw new IllegalStateException("Environment not yet initialized"); 218 | return env; 219 | } 220 | 221 | /** 222 | * Set the value of a global variable in the PHP execution environment. 223 | * @param name The name of the global parameter to create/update 224 | * @param obj The value to store there 225 | */ 226 | public PHP set(String name, Object obj) { 227 | snippet(""); 228 | getEnv().setGlobalValue(name, toValue(getEnv(), obj)); 229 | return this; 230 | } 231 | 232 | /** 233 | * Retrieve the value of a global varialbe in the PHP execution environment. 234 | * @param name The name of the global parameter tto read 235 | */ 236 | public PHPObject get(String name) { 237 | snippet(""); 238 | return new PHPObject(getEnv(), getEnv().getGlobalValue(name)); 239 | } 240 | 241 | /** 242 | * Ensures that obj is of type or wrapped in an instance 243 | * of Quercus' Value, with respect to the given execution 244 | * environment env. 245 | * @return obj or obj wrapped in a Value instance. 246 | */ 247 | public static Value toValue(Env env, Object obj) { 248 | if (obj == null) 249 | return env.wrapJava(obj); 250 | else if (obj instanceof PHPObject) 251 | return ((PHPObject) obj).getWrappedValue(); 252 | else if (obj instanceof Value) 253 | return (Value) obj; 254 | else 255 | return env.wrapJava(obj); 256 | } 257 | 258 | /** 259 | * Parse and execute a snippet of PHP script, adding to the 260 | * execution context any artifacts and/or output generated by the code. 261 | */ 262 | public PHP snippet(String snippet) { 263 | try { 264 | QuercusPage page = getQuercus().parse(StringStream.open(snippet)); 265 | initEnv(page); 266 | page.executeTop(getEnv()); 267 | } catch (IOException e) { 268 | throw new RuntimeException(e); 269 | } 270 | 271 | return this; 272 | } 273 | 274 | /** 275 | * Retrieve the output generated by all PHP scripts executed in this context. 276 | */ 277 | public String toString() { 278 | if (env != null) { 279 | try { 280 | ws.flush(); 281 | return response.getContentAsString(); 282 | } catch (UnsupportedEncodingException e) { 283 | throw new RuntimeException(e); 284 | } catch (IOException e) { 285 | throw new RuntimeException(e); 286 | } 287 | } 288 | else { 289 | return null; 290 | } 291 | } 292 | 293 | /** 294 | * Clear any text buffered by script execution, presumably in preparation for 295 | * executing another PHP snippet. 296 | * @return This instance of PHP, to support method chaining. 297 | */ 298 | public PHP clear() { 299 | response.setCommitted(false); 300 | response.reset(); 301 | return this; 302 | } 303 | 304 | /** 305 | * Call the PHP function named fxName with arguments args 306 | * @return An instance of PHPObject, wrapped around the return value of the function. 307 | */ 308 | public PHPObject fx(String fxName, Object ... args) { 309 | if (args != null && args.length > 0) { 310 | Value[] values = new Value[args.length]; 311 | for (int i=0; iclassName, initialized with 323 | * arguments args. 324 | * @return An instance of PHPObject, wrapping the new instance of className. 325 | */ 326 | public PHPObject newInstance(String className, Object ... args) { 327 | QuercusClass clazz = getEnv().findClass(className); 328 | if (clazz == null) 329 | throw new RuntimeException(new ClassNotFoundException("PHP:"+className)); 330 | 331 | if (args != null && args.length > 0) { 332 | Value[] values = new Value[args.length]; 333 | for (int i=0; icom.caucho.quercus.env.Value, themselves representing 26 | * instances of PHP objects. This wrapper makes it easier to invoke methods and set and get properties. 27 | * @author Aaron Collegeman aaron@collegeman.net 28 | */ 29 | public class PHPObject { 30 | 31 | private Value wrapped; 32 | 33 | private Env env; 34 | 35 | public PHPObject(Env env, Value value) { 36 | this.env = env; 37 | this.wrapped = value; 38 | } 39 | 40 | /** 41 | * Invoke the method name on wrapped Value object, passing 42 | * into the invocation parameters args. 43 | * @return An instance of PHPObject, wrapping any return value of nameed method. 44 | */ 45 | public final PHPObject invokeMethod(String name, Object ... args) { 46 | if (args != null && args.length > 0) { 47 | Value values[] = new Value[args.length]; 48 | for(int i=0; iValue to value. 60 | * @return This instance of PHPObject, to support method chaining. 61 | */ 62 | public final PHPObject setProperty(String name, Object value) { 63 | wrapped.putField(env, new StringBuilderValue(name), PHP.toValue(env, value)); 64 | return this; 65 | } 66 | 67 | /** 68 | * Retrieve a public property name of the wrapped Value. 69 | * @return A new instance of PHPObject, wrapping the retrieved property. 70 | */ 71 | public final PHPObject getProperty(String name) { 72 | return new PHPObject(env, wrapped.getField(env, new StringBuilderValue(name))); 73 | } 74 | 75 | public Value getWrappedValue() { 76 | return wrapped; 77 | } 78 | 79 | public String toString() { 80 | return wrapped.toJavaString(); 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /src/main/java/net/collegeman/phpinjava/groovy/GroovyPHP.java: -------------------------------------------------------------------------------- 1 | package net.collegeman.phpinjava.groovy; 2 | 3 | /** 4 | * PHP-in-Java PHP wrapper for Java and Groovy. 5 | * Copyright (C) 2009-2010 Collegeman.net, LLC. 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | import net.collegeman.phpinjava.*; 23 | import groovy.lang.*; 24 | import java.io.*; 25 | import java.lang.reflect.*; 26 | 27 | public class GroovyPHP extends GroovyObjectSupport { 28 | 29 | private PHP php; 30 | 31 | public GroovyPHP(String url) { 32 | php = new PHP(url, GroovyPHP.class.getClassLoader()); 33 | } 34 | 35 | public GroovyPHP(String url, ClassLoader classLoader) { 36 | php = new PHP(url, classLoader); 37 | } 38 | 39 | public GroovyPHP(File file) { 40 | php = new PHP(file); 41 | } 42 | 43 | public GroovyPHP() { 44 | php = new PHP(); 45 | } 46 | 47 | public Object invokeMethod(String name, Object ... args) { 48 | try { 49 | if (args != null && args.length > 0) { 50 | Class[] classes = new Class[args.length]; 51 | for (int i=0; iGroovyObject interface, allowing 27 | * for the seamless introduction of PHP-powered APIs into your Groovy applications 28 | * (including Grails Web apps!). 29 | *

I really don't think it could get less complicated than this.

30 | * @author Aaron Collegeman aaron@collegeman.net 31 | */ 32 | public class GroovyPHPObject extends GroovyObjectSupport { 33 | 34 | private PHPObject obj; 35 | 36 | /** 37 | * The GroovyPHPObject is only allowed to wrap one kind of 38 | * object: a PHPObject - the wrapper used by many methods in 39 | * the PHP class. 40 | *

The methods {@link GroovyPHP#get(String)}, {@link GroovyPHP#fx(String, Object[])}, 41 | * and {@link GroovyPHP#newInstance(String, Object...)} each return instances 42 | * of GroovyPHPObjects. 43 | */ 44 | public GroovyPHPObject(PHPObject obj) { 45 | this.obj = obj; 46 | } 47 | 48 | /** 49 | * Invokes the function or method name with arguments args 50 | * on the PHP object reference wrapped within. 51 | * @return An instance of GroovyPHPObject wrapping the return value of the function or method. 52 | */ 53 | public Object invokeMethod(String name, Object args) { 54 | return new GroovyPHPObject(obj.invokeMethod(name, args)); 55 | } 56 | 57 | /** 58 | * Retrieves the value of property property of the PHP object reference wrapped within. 59 | * @return An instance of GroovyPHPObject wrapping the value of the property. 60 | */ 61 | public Object getProperty(String property) { 62 | return new GroovyPHPObject(obj.getProperty(property)); 63 | } 64 | 65 | /** 66 | * Assigns newValue to the property property of the PHP object reference 67 | * wrapped within. 68 | */ 69 | public void setProperty(String property, Object newValue) { 70 | obj.setProperty(property, newValue); 71 | } 72 | 73 | public String toString() { 74 | return obj.toString(); 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /src/test/java/net/collegeman/phpinjava/PHPInJavaTest.java: -------------------------------------------------------------------------------- 1 | package net.collegeman.phpinjava; 2 | 3 | import junit.framework.*; 4 | import com.caucho.quercus.env.*; 5 | import java.util.*; 6 | import java.io.*; 7 | 8 | import net.collegeman.phpinjava.groovy.*; 9 | 10 | public class PHPInJavaTest extends TestCase { 11 | 12 | public void testExecuteFromClasspath() { 13 | assertEquals("Hello, world!", new PHP("classpath:/com/faux/php/HelloWorld.php").toString()); 14 | 15 | assertEquals("Hello, world!", new GroovyPHP("classpath:/com/faux/php/HelloWorld.php").toString()); 16 | } 17 | 18 | public void testExecuteSnippet() { 19 | assertEquals("Hello, world!", new PHP().snippet("message = $message; 9 | } 10 | 11 | function setMessage($message) { 12 | $this->message = $message; 13 | } 14 | 15 | function repeat() { 16 | return $this->message; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /src/test/resources/com/faux/php/HelloWorldFx.php: -------------------------------------------------------------------------------- 1 |