-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathAbstractStream.php
More file actions
59 lines (51 loc) · 1.57 KB
/
AbstractStream.php
File metadata and controls
59 lines (51 loc) · 1.57 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
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace PHPJava\Compiler\Lang\Stream;
use PHPJava\Exceptions\AssembleStructureException;
use PHPJava\Utilities\Formatter;
abstract class AbstractStream implements StreamReaderInterface
{
protected $filePath;
protected $source;
protected $distributeDirectory;
abstract public function __construct($source);
public function getCode(): string
{
return $this->source;
}
public function getFilePath(): string
{
if ($this->filePath === null) {
throw new AssembleStructureException(
'File path is not specified.'
);
}
return $this->filePath;
}
public function setDistributeDirectory(string $path): StreamReaderInterface
{
$this->distributeDirectory = $path;
return $this;
}
/**
* @return resource
*/
public function getDistributeStreamByClassPath(string $classPath)
{
if (!isset($this->distributeDirectory)) {
throw new AssembleStructureException(
'Distribution directory is not set. ' .
'You must to set distribution directory with the `setDistributeDirectory` method on StreamInterface.'
);
}
[$namespace, $className] = Formatter::getNamespaceAndClassName($classPath);
$path = $this->distributeDirectory . '/' . implode('/', $namespace);
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
return fopen(
$path . '/' . $className . '.class',
'w+'
);
}
}