-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathFileReader.php
More file actions
53 lines (45 loc) · 1.11 KB
/
FileReader.php
File metadata and controls
53 lines (45 loc) · 1.11 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace PHPJava\Core\Stream\Reader;
use PHPJava\Core\JVM\Stream\BinaryReader;
use PHPJava\Core\JVM\Stream\StreamReaderInterface;
class FileReader implements ReaderInterface
{
/**
* @var resource
*/
private $handle;
/**
* @var BinaryReader
*/
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 BinaryReader($this->handle);
}
public function getReader(): StreamReaderInterface
{
return $this->binaryReader;
}
public function getJavaPathName(): string
{
return preg_replace(
'/\.class$/',
'',
basename($this->getFileName())
);
}
public function getFileName(): string
{
return stream_get_meta_data($this->handle)['uri'];
}
public function __toString(): string
{
return $this->getFileName();
}
}