Skip to content

Commit cc17b0e

Browse files
committed
Add
1 parent 2fe1a8a commit cc17b0e

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/Core/JavaArchive.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace PHPJava\Core;
33

44
use PHPJava\Imitation\java\io\FileNotFoundException;
5+
use PHPJava\Imitation\java\lang\ClassNotFoundException;
56

67
class JavaArchive
78
{
@@ -13,7 +14,15 @@ class JavaArchive
1314
private $files = [];
1415
private $classes = [];
1516

16-
public function __construct(string $jarFile)
17+
/**
18+
* @param string $jarFile
19+
* @param string|null $entryPoint
20+
* @throws FileNotFoundException
21+
* @throws \PHPJava\Exceptions\ReadEntryException
22+
* @throws \PHPJava\Exceptions\ValidatorException
23+
* @throws \PHPJava\Imitation\java\lang\ClassNotFoundException
24+
*/
25+
public function __construct(string $jarFile, string $entryPoint = null)
1726
{
1827
$this->jarFile = $jarFile;
1928
$archive = new \ZipArchive();
@@ -49,37 +58,48 @@ function ($fileName) {
4958
);
5059

5160
foreach ($this->files as $className => $code) {
52-
$this->classes[$className] = new JavaClass(new JavaClassInlineFileReader(
61+
$this->classes[str_replace('/', '.', $className)] = new JavaClass(new JavaClassInlineFileReader(
5362
$className,
5463
$code
5564
));
5665
}
57-
58-
var_dump($this->classes);
5966
}
6067

6168
public function __debugInfo()
6269
{
6370
return [
6471
'version' => $this->getVersion(),
6572
'createdBy' => $this->getCreatedBy(),
66-
'entrypoint' => $this->getEntryPoint(),
73+
'entryPointName' => $this->getEntryPointName(),
6774
'file' => $this->jarFile,
6875
];
6976
}
7077

71-
public function getVersion()
78+
public function getVersion(): ?string
7279
{
7380
return $this->manifestData['manifest-version'] ?? null;
7481
}
7582

76-
public function getCreatedBy()
83+
public function getCreatedBy(): ?string
7784
{
7885
return $this->manifestData['created-by'] ?? null;
7986
}
8087

81-
public function getEntryPoint()
88+
public function getEntryPointName(): ?string
8289
{
8390
return $this->manifestData['main-class'] ?? null;
8491
}
92+
93+
public function getClasses(): array
94+
{
95+
return $this->classes;
96+
}
97+
98+
public function getClassByName(string $name): JavaClass
99+
{
100+
if (!isset($this->classes[$name])) {
101+
throw new ClassNotFoundException($name . ' does not found on ' . $this->jarFile . '.');
102+
}
103+
return $this->classes[$name];
104+
}
85105
}

0 commit comments

Comments
 (0)