-
Notifications
You must be signed in to change notification settings - Fork 0
/
TempMemoryFile.php
78 lines (68 loc) · 1.83 KB
/
TempMemoryFile.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Aternos\IO\System\File;
use Aternos\IO\Exception\IOException;
use Aternos\IO\Interfaces\Types\VolatileFileInterface;
use Aternos\IO\System\Socket\Traits\CloseSocketTrait;
use Aternos\IO\System\Socket\Traits\GetSizeTrait;
use Aternos\IO\System\Socket\Traits\GetSocketPositionTrait;
use Aternos\IO\System\Socket\Traits\IsEndOfFileSocketTrait;
use Aternos\IO\System\Socket\Traits\OpenSocketTrait;
use Aternos\IO\System\Socket\Traits\ReadSocketTrait;
use Aternos\IO\System\Socket\Traits\SetSocketPositionTrait;
use Aternos\IO\System\Socket\Traits\TruncateSocketTrait;
use Aternos\IO\System\Socket\Traits\WriteSocketTrait;
/**
* Class TempMemoryFile
*
* Temporary file in memory
*
* @package Aternos\IO\System\File
*/
class TempMemoryFile implements VolatileFileInterface
{
protected string $address = "php://memory";
protected string $mode = "c+b";
use OpenSocketTrait,
CloseSocketTrait,
GetSocketPositionTrait,
IsEndOfFileSocketTrait,
ReadSocketTrait,
SetSocketPositionTrait,
TruncateSocketTrait,
WriteSocketTrait,
GetSizeTrait;
/**
* @inheritDoc
*/
public function getName(): ?string
{
return "memory";
}
/**
* @inheritDoc
*/
protected function getTypeForErrors(): string
{
return $this->getName() . " file";
}
/**
* @inheritDoc
*/
protected function getErrorContext(): ?string
{
return null;
}
/**
* @inheritDoc
* @throws IOException
* @noinspection PhpMixedReturnTypeCanBeReducedInspection
*/
protected function openSocketResource(): mixed
{
$resource = @fopen($this->address, $this->mode);
if (!$resource) {
$this->throwException("Could not open {type}");
}
return $resource;
}
}