forked from php-java/php-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaClassFileReader.php
More file actions
38 lines (32 loc) · 949 Bytes
/
JavaClassFileReader.php
File metadata and controls
38 lines (32 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace PHPJava\Core;
use PHPJava\Utilities\ClassResolver;
class JavaClassFileReader implements JavaClassReaderInterface
{
private $handle;
private $binaryReader;
public function __construct(string $file)
{
if (!preg_match('/\.class$/', $file, $matches)) {
// Add extension
$file = $file . '.class';
}
$this->handle = fopen($file, 'r');
$this->binaryReader = new JVM\Stream\BinaryReader($this->handle);
// Add resolving path
ClassResolver::add(
[
[ClassResolver::RESOURCE_TYPE_FILE, dirname($file)],
[ClassResolver::RESOURCE_TYPE_FILE, getcwd()],
]
);
}
public function getBinaryReader(): JVM\Stream\BinaryReader
{
return $this->binaryReader;
}
public function __toString(): string
{
return stream_get_meta_data($this->handle)['uri'];
}
}