Skip to content

Commit a4270e0

Browse files
committed
WIP commit
1 parent cc17b0e commit a4270e0

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/Core/JavaArchive.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use PHPJava\Imitation\java\io\FileNotFoundException;
55
use PHPJava\Imitation\java\lang\ClassNotFoundException;
6+
use PHPJava\Utilities\ClassResolver;
67

78
class JavaArchive
89
{
@@ -63,6 +64,15 @@ function ($fileName) {
6364
$code
6465
));
6566
}
67+
68+
// Add resolving path
69+
ClassResolver::add(
70+
[
71+
[ClassResolver::RESOURCE_TYPE_FILE, dirname($jarFile)],
72+
[ClassResolver::RESOURCE_TYPE_FILE, getcwd()],
73+
[ClassResolver::RESOURCE_TYPE_JAR, $this],
74+
]
75+
);
6676
}
6777

6878
public function __debugInfo()
@@ -72,6 +82,7 @@ public function __debugInfo()
7282
'createdBy' => $this->getCreatedBy(),
7383
'entryPointName' => $this->getEntryPointName(),
7484
'file' => $this->jarFile,
85+
'classes' => $this->getClasses(),
7586
];
7687
}
7788

@@ -98,7 +109,7 @@ public function getClasses(): array
98109
public function getClassByName(string $name): JavaClass
99110
{
100111
if (!isset($this->classes[$name])) {
101-
throw new ClassNotFoundException($name . ' does not found on ' . $this->jarFile . '.');
112+
throw new ClassNotFoundException(str_replace('/', '.', $name) . ' does not found on ' . $this->jarFile . '.');
102113
}
103114
return $this->classes[$name];
104115
}

src/Utilities/ClassResolver.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22
namespace PHPJava\Utilities;
33

4+
use PHPJava\Core\JavaArchive;
45
use PHPJava\Core\JavaClass;
56
use PHPJava\Core\JavaClassFileReader;
7+
use PHPJava\Imitation\java\lang\ClassNotFoundException;
68

79
class ClassResolver
810
{
@@ -13,6 +15,7 @@ class ClassResolver
1315

1416
// resource types
1517
const RESOURCE_TYPE_FILE = 'RESOURCE_TYPE_FILE';
18+
const RESOURCE_TYPE_JAR = 'RESOLVED_TYPE_JAR';
1619

1720
// resolved types
1821
const RESOLVED_TYPE_CLASS = 'RESOLVED_TYPE_CLASS';
@@ -49,13 +52,25 @@ public static function resolve(string $javaPath, JavaClass $class = null): array
4952
];
5053
}
5154
break;
55+
case static::RESOURCE_TYPE_JAR:
56+
/**
57+
* @var JavaArchive $value
58+
*/
59+
try {
60+
return $resolvedPaths[] = [
61+
static::RESOLVED_TYPE_CLASS,
62+
$value->getClassByName($relativePath),
63+
];
64+
} catch (ClassNotFoundException $e) {
65+
}
66+
break;
5267
}
5368
}
5469

5570
$className = '\\PHPJava\\Imitation\\' . implode('\\', $buildClassPath);
5671

5772
if (!class_exists($className)) {
58-
throw new \PHPJava\Imitation\java\lang\ClassNotFoundException(str_replace(['\\PHPJava\\Imitation\\', '\\'], ['', '.'], $className) . ' class does not exist.');
73+
throw new ClassNotFoundException(str_replace(['\\PHPJava\\Imitation\\', '\\'], ['', '.'], $className) . ' class does not exist.');
5974
}
6075

6176
return [
@@ -70,7 +85,6 @@ public static function add($valuesOrResourceType = self::RESOURCE_TYPE_FILE, $va
7085
foreach ($valuesOrResourceType as [$resourceType, $value]) {
7186
static::add($resourceType, $value);
7287
}
73-
7488
return;
7589
}
7690

0 commit comments

Comments
 (0)