Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
filesystementry.php
1<?php
2namespace Bitrix\Main\IO;
3
5
6abstract class FileSystemEntry
7{
8 protected $path;
9 protected $originalPath;
10 protected $pathPhysical;
11 protected $siteId;
12
13 public function __construct($path, $siteId = null)
14 {
15 if ($path == '')
16 throw new InvalidPathException($path);
17
18 $this->originalPath = $path;
19 $this->path = Path::normalize($path);
20 $this->siteId = $siteId;
21
22 if ($this->path == '')
23 throw new InvalidPathException($path);
24 }
25
26 public function isSystem()
27 {
28 if (preg_match("#/\\.#", $this->path))
29 return true;
30
31 $documentRoot = static::getDocumentRoot($this->siteId);
32
33 if (mb_substr($this->path, 0, mb_strlen($documentRoot)) === $documentRoot)
34 {
35 $relativePath = mb_substr($this->path, mb_strlen($documentRoot));
36 $relativePath = ltrim($relativePath, "/");
37 if (($pos = mb_strpos($relativePath, "/")) !== false)
38 $s = mb_substr($relativePath, 0, $pos);
39 else
40 $s = $relativePath;
41 $s = mb_strtolower(rtrim($s, "."));
42
43 $ar = array(
44 "bitrix" => 1,
45 Main\Config\Option::get("main", "upload_dir", "upload") => 1,
46 "local" => 1,
47 "urlrewrite.php" => 1,
48 );
49 if (isset($ar[$s]))
50 return true;
51 }
52
53 return false;
54 }
55
56 public function getName()
57 {
58 return Path::getName($this->path);
59 }
60
61 public function getDirectoryName()
62 {
63 return Path::getDirectory($this->path);
64 }
65
66 public function getPath()
67 {
68 return $this->path;
69 }
70
71 public function getDirectory()
72 {
73 return new Directory($this->getDirectoryName());
74 }
75
76 abstract public function getCreationTime();
77 abstract public function getLastAccessTime();
78 abstract public function getModificationTime();
79
80 abstract public function isExists();
81
82 public abstract function isDirectory();
83 public abstract function isFile();
84 public abstract function isLink();
85
86 public abstract function markWritable();
87 public abstract function getPermissions();
88 public abstract function delete();
89
90 public function getPhysicalPath()
91 {
92 if (is_null($this->pathPhysical))
93 $this->pathPhysical = Path::convertLogicalToPhysical($this->path);
94
96 }
97
98 public function rename($newPath)
99 {
100 $newPathNormalized = Path::normalize($newPath);
101
102 $success = true;
103 if ($this->isExists())
104 $success = rename($this->getPhysicalPath(), Path::convertLogicalToPhysical($newPathNormalized));
105
106 if ($success)
107 {
108 $this->originalPath = $newPath;
109 $this->path = $newPathNormalized;
110 $this->pathPhysical = null;
111 }
112
113 return $success;
114 }
115
116 protected static function getDocumentRoot($siteId)
117 {
118 if($siteId === null)
119 {
120 $documentRoot = Main\Application::getDocumentRoot();
121 }
122 else
123 {
124 $documentRoot = Main\SiteTable::getDocumentRoot($siteId);
125 }
126 return $documentRoot;
127 }
128}
$path
$pathPhysical
isDirectory()
getPath()
getName()
getDirectoryName()
getModificationTime()
rename($newPath)
isFile()
static getDocumentRoot($siteId)
isLink()
getCreationTime()
getPermissions()
isSystem()
$originalPath
__construct($path, $siteId=null)
$siteId
getPhysicalPath()
markWritable()
getDirectory()
isExists()
getLastAccessTime()
static normalize($path)
Definition path.php:26
static convertLogicalToPhysical($path)
Definition path.php:114
static getDirectory($path)
Definition path.php:109
static getName($path)
Definition path.php:98