Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
directory.php
1<?php
2namespace Bitrix\Main\IO;
3
5 extends DirectoryEntry
6{
7 public function __construct($path, $siteId = null)
8 {
9 parent::__construct($path, $siteId);
10 }
11
12 public function isExists()
13 {
14 $p = $this->getPhysicalPath();
15 return file_exists($p) && is_dir($p);
16 }
17
18 public function delete()
19 {
20 return self::deleteInternal($this->getPhysicalPath());
21 }
22
23 private static function deleteInternal($path)
24 {
25 if (is_file($path) || is_link($path))
26 {
27 if (!@unlink($path))
28 throw new FileDeleteException($path);
29 }
30 elseif (is_dir($path))
31 {
32 if ($handle = opendir($path))
33 {
34 while (($file = readdir($handle)) !== false)
35 {
36 if ($file == "." || $file == "..")
37 continue;
38
39 self::deleteInternal(Path::combine($path, $file));
40 }
41 closedir($handle);
42 }
43 if (!@rmdir($path))
44 throw new FileDeleteException($path);
45 }
46
47 return true;
48 }
49
54 public function getChildren()
55 {
56 if (!$this->isExists())
57 throw new FileNotFoundException($this->originalPath);
58
59 $arResult = array();
60
61 if ($handle = opendir($this->getPhysicalPath()))
62 {
63 while (($file = readdir($handle)) !== false)
64 {
65 if ($file == "." || $file == "..")
66 continue;
67
68 $pathLogical = Path::combine($this->path, Path::convertPhysicalToLogical($file));
70 if (is_dir($pathPhysical))
71 $arResult[] = new Directory($pathLogical, $this->siteId);
72 else
73 $arResult[] = new File($pathLogical, $this->siteId);
74 }
75 closedir($handle);
76 }
77
78 return $arResult;
79 }
80
85 public function createSubdirectory($name)
86 {
87 $dir = new Directory(Path::combine($this->path, $name));
88 if (!$dir->isExists())
89 {
90 try
91 {
92 mkdir($dir->getPhysicalPath(), BX_DIR_PERMISSIONS, true);
93 }
94 catch (\ErrorException $exception)
95 {
96 if (!$dir->isExists())
97 {
98 throw $exception;
99 }
100 }
101 }
102
103 return $dir;
104 }
105
106 public function getCreationTime()
107 {
108 if (!$this->isExists())
109 throw new FileNotFoundException($this->originalPath);
110
111 return filectime($this->getPhysicalPath());
112 }
113
114 public function getLastAccessTime()
115 {
116 if (!$this->isExists())
117 throw new FileNotFoundException($this->originalPath);
118
119 return fileatime($this->getPhysicalPath());
120 }
121
122 public function getModificationTime()
123 {
124 if (!$this->isExists())
125 throw new FileNotFoundException($this->originalPath);
126
127 return filemtime($this->getPhysicalPath());
128 }
129
130 public function markWritable()
131 {
132 if (!$this->isExists())
133 throw new FileNotFoundException($this->originalPath);
134
135 @chmod($this->getPhysicalPath(), BX_DIR_PERMISSIONS);
136 }
137
138 public function getPermissions()
139 {
140 return fileperms($this->getPhysicalPath());
141 }
142
148 public static function createDirectory($path)
149 {
150 $dir = new self($path);
151 $dir->create();
152
153 return $dir;
154 }
155
156 public static function deleteDirectory($path)
157 {
158 $dir = new self($path);
159 $dir->delete();
160 }
161
162 public static function isDirectoryExists($path)
163 {
164 $f = new self($path);
165 return $f->isExists();
166 }
167}
static createDirectory($path)
static deleteDirectory($path)
__construct($path, $siteId=null)
Definition directory.php:7
static isDirectoryExists($path)
$path
$pathPhysical
$siteId
getPhysicalPath()
static convertPhysicalToLogical($path)
Definition path.php:128
static combine()
Definition path.php:221