-
Notifications
You must be signed in to change notification settings - Fork 36
JavaClass
memory-agape edited this page Apr 18, 2019
·
2 revisions
JavaClass class is provided APIs for reading Java class which implemented PHPJava\Core\Stream\Reader\ReaderInterface.
For an example as follows:
- Write Java:
class HelloWorld
{
public static void main(String[] args)
{
System.out.println(args[0]);
}
}- Compile Java:
$ javac -UTF8 /path/to/HelloWorld.java
- Call the main method as follows:
<?php
use PHPJava\Core\JavaClass;
use PHPJava\Core\Stream\Reader\FileReader;
(new JavaClass(new FileReader('/path/to/HelloWorld.class')))
->getInvoker()
->getStatic()
->getMethods()
->call(
'main',
["Hello World!"]
);- Get the result
$ php /path/to/HelloWorld.php
Hello World!
public function __construct(ReaderInterface $reader, array $options = [])Initiate a Java Class.
| Name | Type | Description |
|---|---|---|
| $reader | ReaderInterface | Specify reader as such as FileReader or InlineReader
|
| $options | array | Set JavaClass runtime options. |
public function getOptions(): arrayReturn set runtime options on a JavaClass.
No parameters.
public function getClassName(bool $shortName = false): stringReturn running Java's class name.
| Name | Type | Description |
|---|---|---|
| $shortName | bool | Specify to return value which fully qualified class name or short name. (NOTE: Fully qualified return value is including $ if it is a inner class) |
public function getInnerClasses(): arrayReturn included inner classes in JavaClass.
No parameter.
public function getFields(): arrayReturn specified fields in JavaClass.
No parameter.
public function getMethods(): arrayReturn specified methods in JavaClass.
No parameter.
public function getInvoker(): JavaClassInvokerReturn an Invoker which is caller for JavaClass's method.
No parameter.
public function appendDebug(mixed $log): voidAppend one line trace. Maybe, you do not use this method.
| Name | Type | Description |
|---|---|---|
| $log | mixed | Specify a log |
public function hasParentClass(): boolCheck the JavaClass's parent class.
No parameter.
public function setParentClass(JavaClass $class): JavaClassSet parent class.
| Name | Type | Description |
|---|---|---|
| $class | JavaClass | Specify JavaClass |
public function getParentClass(): JavaClassReturn parent class.
No parameter.
public function getSuperClass()No feature.
No feature.
public function debug(): voidOutput debug trace.
No parameter.
- The Contribution Guide
- CHANGELOG
- How to run JavaClass
- How to run JavaArchive
- How to run Kotlin
-
Provided classes
- Core
- Types
- Utilities
- Provided options
- Operation Injector