-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVirtualFile.php
More file actions
36 lines (28 loc) · 731 Bytes
/
Copy pathVirtualFile.php
File metadata and controls
36 lines (28 loc) · 731 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
<?php
namespace Permafrost\PhpCodeSearch\Support;
class VirtualFile extends File
{
public function __construct(string $code)
{
$this->createTempFile($code);
$this->filename = $this->getRealPath();
}
public function __destruct()
{
$this->unlink();
}
public function unlink()
{
if (strpos(dirname($this->path), sys_get_temp_dir()) === false) {
return;
}
if (is_file($this->path)) {
unlink($this->path);
}
}
protected function createTempFile(string $contents): bool
{
$this->path = tempnam(sys_get_temp_dir(), 'pcs');
return file_put_contents($this->path, $contents) !== false;
}
}