1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
filesystementry.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\IO;
4
5use Bitrix\Main;
6
7abstract class FileSystemEntry
8{
9 protected $path;
10 protected $originalPath;
11 protected $pathPhysical;
12 protected $siteId;
13 protected ?bool $exists = null;
14
15 public function __construct($path, $siteId = null)
16 {
17 if ($path == '')
18 {
19 throw new InvalidPathException($path);
20 }
21
22 $this->originalPath = $path;
23 $this->path = Path::normalize($path);
24 $this->siteId = $siteId;
25
26 if ($this->path == '')
27 {
28 throw new InvalidPathException($path);
29 }
30 }
31
32 public function isSystem()
33 {
34 if (preg_match("#/\\.#", $this->path))
35 {
36 return true;
37 }
38
39 $documentRoot = static::getDocumentRoot($this->siteId);
40
41 if (mb_substr($this->path, 0, mb_strlen($documentRoot)) === $documentRoot)
42 {
43 $relativePath = mb_substr($this->path, mb_strlen($documentRoot));
44 $relativePath = ltrim($relativePath, "/");
45 if (($pos = mb_strpos($relativePath, "/")) !== false)
46 {
47 $s = mb_substr($relativePath, 0, $pos);
48 }
49 else
50 {
51 $s = $relativePath;
52 }
53 $s = mb_strtolower(rtrim($s, "."));
54
55 $ar = [
56 "bitrix" => 1,
57 Main\Config\Option::get("main", "upload_dir", "upload") => 1,
58 "local" => 1,
59 "urlrewrite.php" => 1,
60 ];
61 if (isset($ar[$s]))
62 {
63 return true;
64 }
65 }
66
67 return false;
68 }
69
70 public function getName()
71 {
72 return Path::getName($this->path);
73 }
74
75 public function getDirectoryName()
76 {
77 return Path::getDirectory($this->path);
78 }
79
80 public function getPath()
81 {
82 return $this->path;
83 }
84
85 public function getDirectory()
86 {
87 return new Directory($this->getDirectoryName());
88 }
89
90 public function getCreationTime()
91 {
92 if (!$this->isExists())
93 {
94 throw new FileNotFoundException($this->originalPath);
95 }
96
97 return filectime($this->getPhysicalPath());
98 }
99
100 public function getLastAccessTime()
101 {
102 if (!$this->isExists())
103 {
104 throw new FileNotFoundException($this->originalPath);
105 }
106
107 return fileatime($this->getPhysicalPath());
108 }
109
110 public function getModificationTime()
111 {
112 if (!$this->isExists())
113 {
114 throw new FileNotFoundException($this->originalPath);
115 }
116
117 return filemtime($this->getPhysicalPath());
118 }
119
120 abstract public function isExists();
121
122 abstract public function isDirectory();
123
124 abstract public function isFile();
125
126 abstract public function isLink();
127
128 abstract public function markWritable();
129
130 public function getPermissions()
131 {
132 if (!$this->isExists())
133 {
134 throw new FileNotFoundException($this->originalPath);
135 }
136
137 return fileperms($this->getPhysicalPath());
138 }
139
140 abstract public function delete();
141
142 public function getPhysicalPath()
143 {
144 if (is_null($this->pathPhysical))
145 {
146 $this->pathPhysical = Path::convertLogicalToPhysical($this->path);
147 }
148
149 return $this->pathPhysical;
150 }
151
152 public function rename($newPath)
153 {
154 $newPathNormalized = Path::normalize($newPath);
155
156 $success = true;
157 if ($this->isExists())
158 {
159 $success = rename($this->getPhysicalPath(), Path::convertLogicalToPhysical($newPathNormalized));
160 }
161
162 if ($success)
163 {
164 $this->originalPath = $newPath;
165 $this->path = $newPathNormalized;
166 $this->pathPhysical = null;
167 $this->exists = null;
168 }
169
170 return $success;
171 }
172
173 protected static function getDocumentRoot($siteId)
174 {
175 if ($siteId === null)
176 {
178 }
179 else
180 {
182 }
183 return $documentRoot;
184 }
185}
static getDocumentRoot()
Определения application.php:736
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения filesystementry.php:8
$path
Определения filesystementry.php:9
$pathPhysical
Определения filesystementry.php:11
isDirectory()
getPath()
Определения filesystementry.php:80
getName()
Определения filesystementry.php:70
getDirectoryName()
Определения filesystementry.php:75
getModificationTime()
Определения filesystementry.php:110
rename($newPath)
Определения filesystementry.php:152
isFile()
static getDocumentRoot($siteId)
Определения filesystementry.php:173
isLink()
getCreationTime()
Определения filesystementry.php:90
bool $exists
Определения filesystementry.php:13
getPermissions()
Определения filesystementry.php:130
isSystem()
Определения filesystementry.php:32
$originalPath
Определения filesystementry.php:10
__construct($path, $siteId=null)
Определения filesystementry.php:15
$siteId
Определения filesystementry.php:12
getPhysicalPath()
Определения filesystementry.php:142
markWritable()
getDirectory()
Определения filesystementry.php:85
isExists()
getLastAccessTime()
Определения filesystementry.php:100
static normalize($path)
Определения path.php:22
static convertLogicalToPhysical($path)
Определения path.php:124
static getDirectory($path)
Определения path.php:119
static getName($path)
Определения path.php:108
static getDocumentRoot($siteId=null)
Определения site.php:36
$success
Определения mail_entry.php:69
foreach(['Bitrix\\Main'=> '/lib', 'Psr\\Container'=> '/vendor/psr/container/src', 'Psr\\Log'=> '/vendor/psr/log/src', 'Psr\\Http\\Message'=> '/vendor/psr/http-message/src', 'Psr\\Http\\Client'=> '/vendor/psr/http-client/src', 'Http\\Promise'=> '/vendor/php-http/promise/src', 'PHPMailer\\PHPMailer'=> '/vendor/phpmailer/phpmailer/src', 'GeoIp2'=> '/vendor/geoip2/geoip2/src', 'MaxMind\\Db'=> '/vendor/maxmind-db/reader/src/MaxMind/Db', 'PhpParser'=> '/vendor/nikic/php-parser/lib/PhpParser', 'Recurr'=> '/vendor/simshaun/recurr/src/Recurr',] as $namespace=> $namespacePath) $documentRoot
Определения autoload.php:27
$ar
Определения options.php:199
path
Определения template_copy.php:201