Bitrix-D7  20.0.0
filesystementry.php
См. документацию.
1 <?php
2 namespace Bitrix\Main\IO;
3 
4 use Bitrix\Main;
5 
6 abstract 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 (substr($this->path, 0, strlen($documentRoot)) === $documentRoot)
34  {
35  $relativePath = substr($this->path, strlen($documentRoot));
36  $relativePath = ltrim($relativePath, "/");
37  if (($pos = strpos($relativePath, "/")) !== false)
38  $s = substr($relativePath, 0, $pos);
39  else
40  $s = $relativePath;
41  $s = 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 
95  return $this->pathPhysical;
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 }
Bitrix\Main\SiteTable\getDocumentRoot
static getDocumentRoot($siteId=null)
Definition: main/lib/site.php:16
Bitrix\Main\Config
Definition: main/lib/config/configuration.php:2
Bitrix\Main\IO\Path\getName
static getName($path)
Definition: main/lib/io/path.php:98
Bitrix\Main\IO\FileSystemEntry\$path
$path
Definition: filesystementry.php:8
Bitrix\Main\IO\FileSystemEntry\isLink
isLink()
Bitrix\Main\IO\FileSystemEntry\getModificationTime
getModificationTime()
Bitrix\Main\IO\FileSystemEntry\$pathPhysical
$pathPhysical
Definition: filesystementry.php:10
Bitrix\Main\IO\FileSystemEntry\getPhysicalPath
getPhysicalPath()
Definition: filesystementry.php:90
Bitrix\Main
Bitrix\Main\IO\InvalidPathException
Definition: ioexception.php:35
Bitrix\Main\IO\FileSystemEntry\rename
rename($newPath)
Definition: filesystementry.php:98
Bitrix\Main\IO\Path\normalize
static normalize($path)
Definition: main/lib/io/path.php:26
Bitrix\Main\IO\FileSystemEntry\markWritable
markWritable()
Bitrix\Main\IO\FileSystemEntry\$siteId
$siteId
Definition: filesystementry.php:11
Bitrix\Main\IO\FileSystemEntry\isFile
isFile()
Bitrix\Main\IO\Directory
Definition: main/lib/io/directory.php:4
Bitrix\Main\Config\Option\get
static get($moduleId, $name, $default="", $siteId=false)
Returns a value of an option.
Definition: main/lib/config/option.php:29
Bitrix\Main\IO\Path\getDirectory
static getDirectory($path)
Definition: main/lib/io/path.php:109
Bitrix\Main\IO\FileSystemEntry\$originalPath
$originalPath
Definition: filesystementry.php:9
Bitrix\Main\IO\FileSystemEntry\getCreationTime
getCreationTime()
Bitrix\Main\IO\FileSystemEntry
Definition: filesystementry.php:6
Bitrix\Main\IO\FileSystemEntry\getLastAccessTime
getLastAccessTime()
Bitrix\Main\Application\getDocumentRoot
static getDocumentRoot()
Returns server document root.
Definition: main/lib/application.php:460
Bitrix\Main\IO
Definition: main/lib/io/directory.php:2
Bitrix\Main\IO\FileSystemEntry\getDirectory
getDirectory()
Definition: filesystementry.php:71
Bitrix\Main\IO\FileSystemEntry\__construct
__construct($path, $siteId=null)
Definition: filesystementry.php:13
Bitrix\Main\IO\FileSystemEntry\getPath
getPath()
Definition: filesystementry.php:66
Bitrix\Main\IO\FileSystemEntry\getDirectoryName
getDirectoryName()
Definition: filesystementry.php:61
Bitrix\Main\IO\FileSystemEntry\isDirectory
isDirectory()
Bitrix\Main\IO\FileSystemEntry\getPermissions
getPermissions()
Bitrix\Main\IO\FileSystemEntry\getName
getName()
Definition: filesystementry.php:56
Bitrix\Main\IO\FileSystemEntry\getDocumentRoot
static getDocumentRoot($siteId)
Definition: filesystementry.php:116
Bitrix\Main\IO\Path\convertLogicalToPhysical
static convertLogicalToPhysical($path)
Definition: main/lib/io/path.php:114
Bitrix\Main\IO\FileSystemEntry\isExists
isExists()
Bitrix\Main\IO\FileSystemEntry\isSystem
isSystem()
Definition: filesystementry.php:26