Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
file.php
1<?php
2
3namespace Bitrix\Translate\IO;
4
7
8
9class File extends Main\IO\File implements Translate\IErrorable
10{
11 // trait implements interface Translate\IErrorable
13
23 public static function generateTemporalFile(string $prefix, string $suffix = '.tmp', int $timeToLive = 3): self
24 {
25 $tempDir = \CTempFile::getDirectoryName($timeToLive, array($prefix, \uniqid($prefix, true)));
26 Path::checkCreatePath($tempDir.'/');
27
28 $hash = \str_pad(\dechex(\crc32($tempDir)), 8, '0', STR_PAD_LEFT);
29 $fileName = \uniqid($hash. '_', false). $suffix;
30
31 return new static($tempDir. $fileName);
32 }
33
39 public function openLoad(): bool
40 {
41 if ($this->isExists())
42 {
43 $this->open(Main\IO\FileStreamOpenMode::READ);
44 }
45
46 return $this->isExists() && $this->isReadable();
47 }
48
54 public function openWrite(): bool
55 {
57
58 return $this->isWritable();
59 }
60
61
69 public function read(int $length): string
70 {
71 if (\feof($this->filePointer))
72 {
73 return '';
74 }
75
76 return \fread($this->filePointer, $length);
77 }
78
88 public function write(string $content): int
89 {
90 if (!\is_resource($this->filePointer))
91 {
92 throw new Main\IO\FileNotOpenedException($this->getPath());
93 }
94
95 $length = \fwrite($this->filePointer, $content);
96 if ($length === false)
97 {
98 throw new Main\IO\IoException("Cannot write file");
99 }
100
101 return $length;
102 }
103
110 public function close(): void
111 {
112 if (!\is_resource($this->filePointer))
113 {
114 @\fflush($this->filePointer);
115 }
116
117 parent::close();
118
119 @clearstatcache(true, $this->getPhysicalPath());
120 }
121}
getPath()
getPhysicalPath()
read(int $length)
Definition file.php:69
static generateTemporalFile(string $prefix, string $suffix='.tmp', int $timeToLive=3)
Definition file.php:23
write(string $content)
Definition file.php:88