Skip to content

Commit e10ffbd

Browse files
authored
Merge pull request #24 from memory-agape/0.0.4
Add a part of java.lang.* classes
2 parents e08c424 + 86029e1 commit e10ffbd

File tree

9 files changed

+115
-0
lines changed

9 files changed

+115
-0
lines changed

src/Core/JVM/Invoker/InvokerInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ interface InvokerInterface
88
public function __construct(JavaClassInvoker $javaClassInvoker, array $methods);
99
public function call(string $name, ...$arguments);
1010
public function isDynamic(): bool;
11+
public function getList(): array;
1112
}

src/Core/JavaClass.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ public function __construct(JavaClassReader $reader)
165165
$this->invoker = new JavaClassInvoker($this);
166166
}
167167

168+
public function __debugInfo()
169+
{
170+
return [
171+
'className' => $this->getClassName(),
172+
'superClass' => get_class($this->getSuperClass()),
173+
'methods' => [
174+
'static' => array_keys($this->invoker->getStatic()->getMethods()->getList()),
175+
'dynamic' => array_keys($this->invoker->getDynamic()->getMethods()->getList()),
176+
],
177+
];
178+
}
179+
168180
public function getClassName(bool $shortName = false): string
169181
{
170182
if ($shortName === true) {

src/Imitation/PHPJava/Extended/_Object.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public function __construct(...$parameters)
99
{
1010
}
1111

12+
public function __destruct()
13+
{
14+
$this->finalize();
15+
}
16+
1217
public function __call($name, $arguments)
1318
{
1419
throw new NoSuchMethodException($name . ' does not exist on ' . get_class($this));
@@ -62,4 +67,8 @@ public function wait(int $timeout = null, int $nanos = null): void
6267
{
6368
// not implemented.
6469
}
70+
71+
public function finalize(): void
72+
{
73+
}
6574
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\io;
3+
4+
use PHPJava\Imitation\java\lang\Exception;
5+
6+
class IOException extends Exception
7+
{
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\io;
3+
4+
class UnsupportedEncodingException extends IOException
5+
{
6+
}

src/Imitation/java/lang/Math.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\lang;
3+
4+
class Math extends _Object
5+
{
6+
public static $E = M_E;
7+
public static $PI = M_PI;
8+
9+
/**
10+
* This method wrapped abs function
11+
*
12+
* @param $number
13+
* @return float|int
14+
*/
15+
public static function abs($number)
16+
{
17+
return abs($number);
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\net;
3+
4+
use PHPJava\Imitation\java\lang\_Object;
5+
6+
class URLDecoder extends _Object
7+
{
8+
9+
/**
10+
* This method wrapped PHP's urldecoder
11+
*
12+
* @param string $s
13+
* @param string $enc
14+
* @return string
15+
*/
16+
public static function decode(string $s, string $enc)
17+
{
18+
return rawurldecode($s);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\net;
3+
4+
use PHPJava\Imitation\java\lang\_Object;
5+
6+
class URLEncoder extends _Object
7+
{
8+
9+
/**
10+
* This method wrapped PHP's urlencoder
11+
*
12+
* @param string $s
13+
* @param string $enc
14+
* @return string
15+
*/
16+
public static function encode(string $s, string $enc)
17+
{
18+
return rawurlencode($s);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\nio\charset;
3+
4+
use PHPJava\Imitation\java\lang\_Object;
5+
6+
class Charset extends _Object
7+
{
8+
9+
/**
10+
* This method wrapped PHP's urldecoder
11+
*
12+
* @param string $s
13+
* @param string $enc
14+
* @return string
15+
*/
16+
public static function decode(string $s, string $enc)
17+
{
18+
return rawurldecode($s);
19+
}
20+
}

0 commit comments

Comments
 (0)