The Groovy script is located by searching the include path of the PHP runtime.
Groovy classes can be imported in to the PHP runtime using the groovy_import
extension function. This creates a PHP class which has the same shape as the original
Groovy class, including methods and fields (both static and instance). Any interactions
with the imported Groovy class are redirected automatically to the underlying Groovy class.
groovy_import imports both Groovy classes and interfaces.
When a Groovy class is imported, the resulting PHP class can optionally be defined to implement one or more PHP interfaces. This is a convenience for PHP scripts as many Groovy classes implement interfaces that are not required in PHP.
groovy_import will optionally declare a super class for the class being
imported. The super class must already have been imported into the PHP runtime.
To avoid class name collisions it is sometimes useful to rename classes during the
import. An optional class name can be passed to groovy_import.
boolean groovy_import(string script_name, array interfaces, boolean include_base_class, string php_class_name)
string script_name - the file name of the Groovy script containing a class
array interfaces - an optional array of PHP interfaces names for the
imported Groovy class to declare as implemented
boolean include_base_class - true for the PHP class to
declare the same base class as the Groovy class being imported
string php_class_name - the name of the class when it is created in
the PHP runtime - this is optional and so can be NULL
in which case the PHP class name is set the same as the Groovy class name
boolean - true if the import succeeded; false otherwise
extension = com.ibm.p8.engine.xapi.groovy.GroovyExtensionLibrary
class Import {
def public FIELD = "Hello World!";
def public static VALUE = "BlahBlahBlah";
def getMessage() {
return "Hello World!";
}
def static getStaticMessage() {
return "Static Hello World!";
}
}
<?php
groovy_import("import.groovy");
echo Import::getStaticMessage()."\n";
echo Import::$VALUE."\n";
Import::$VALUE = "FooBarGuff";
echo Import::$VALUE."\n";
$foo = new Import();
echo $foo->getMessage()."\n";
echo $foo->FIELD."\n";
$foo->FIELD = "FooBarGuff";
echo $foo->FIELD."\n";
?>