-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathInlineReader.php
More file actions
53 lines (44 loc) · 1.07 KB
/
InlineReader.php
File metadata and controls
53 lines (44 loc) · 1.07 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 InlineReader implements ReaderInterface
{
/**
* @var string
*/
private $fileName;
/**
* @var resource
*/
private $handle;
/**
* @var BinaryReader
*/
private $binaryReader;
public function __construct(string $fileName, string $code)
{
$this->fileName = $fileName;
$this->handle = fopen('php://memory', 'rw');
fwrite($this->handle, $code);
rewind($this->handle);
$this->binaryReader = new BinaryReader($this->handle);
}
public function getReader(): StreamReaderInterface
{
return $this->binaryReader;
}
public function getJavaPathName(): string
{
return str_replace('/', '.', $this->getFileName());
}
public function getFileName(): string
{
return $this->fileName;
}
public function __toString(): string
{
return $this->getFileName();
}
}