1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
directory.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\IO;
4
6{
7 public function __construct($path, $siteId = null)
8 {
9 parent::__construct($path, $siteId);
10 }
11
12 public function isExists()
13 {
14 if ($this->exists === null)
15 {
16 $p = $this->getPhysicalPath();
17 $this->exists = file_exists($p) && is_dir($p);
18 }
19
20 return $this->exists;
21 }
22
23 public function delete()
24 {
25 $this->exists = null;
26 return self::deleteInternal($this->getPhysicalPath());
27 }
28
29 private static function deleteInternal($path)
30 {
31 if (is_file($path) || is_link($path))
32 {
33 if (!@unlink($path))
34 {
35 throw new FileDeleteException($path);
36 }
37 }
38 elseif (is_dir($path))
39 {
40 if ($handle = opendir($path))
41 {
42 while (($file = readdir($handle)) !== false)
43 {
44 if ($file == "." || $file == "..")
45 {
46 continue;
47 }
48
49 self::deleteInternal(Path::combine($path, $file));
50 }
51 closedir($handle);
52 }
53 if (!@rmdir($path))
54 {
55 throw new FileDeleteException($path);
56 }
57 }
58
59 return true;
60 }
61
66 public function getChildren()
67 {
68 if (!$this->isExists())
69 {
70 throw new FileNotFoundException($this->originalPath);
71 }
72
73 $arResult = [];
74
75 if ($handle = opendir($this->getPhysicalPath()))
76 {
77 while (($file = readdir($handle)) !== false)
78 {
79 if ($file == "." || $file == "..")
80 {
81 continue;
82 }
83
84 $pathLogical = Path::combine($this->path, Path::convertPhysicalToLogical($file));
86 if (is_dir($pathPhysical))
87 {
88 $arResult[] = new Directory($pathLogical, $this->siteId);
89 }
90 else
91 {
92 $arResult[] = new File($pathLogical, $this->siteId);
93 }
94 }
95 closedir($handle);
96 }
97
98 return $arResult;
99 }
100
105 public function createSubdirectory($name)
106 {
107 $dir = new Directory(Path::combine($this->path, $name));
108 if (!$dir->isExists())
109 {
110 $dir->exists = null;
111 try
112 {
113 mkdir($dir->getPhysicalPath(), BX_DIR_PERMISSIONS, true);
114 }
115 catch (\ErrorException $exception)
116 {
117 if (!$dir->isExists())
118 {
119 throw $exception;
120 }
121 }
122 }
123
124 return $dir;
125 }
126
127 public function markWritable()
128 {
129 if (!$this->isExists())
130 {
131 throw new FileNotFoundException($this->originalPath);
132 }
133
134 @chmod($this->getPhysicalPath(), BX_DIR_PERMISSIONS);
135 }
136
142 public static function createDirectory($path)
143 {
144 $dir = new self($path);
145 $dir->create();
146
147 return $dir;
148 }
149
150 public static function deleteDirectory($path)
151 {
152 $dir = new self($path);
153 $dir->delete();
154 }
155
156 public static function isDirectoryExists($path)
157 {
158 $f = new self($path);
159 return $f->isExists();
160 }
161}
$path
Определения access_edit.php:21
$arResult
Определения generate_coupon.php:16
Определения directoryentry.php:6
static createDirectory($path)
Определения directory.php:142
createSubdirectory($name)
Определения directory.php:105
static deleteDirectory($path)
Определения directory.php:150
getChildren()
Определения directory.php:66
__construct($path, $siteId=null)
Определения directory.php:7
static isDirectoryExists($path)
Определения directory.php:156
markWritable()
Определения directory.php:127
isExists()
Определения directory.php:12
$path
Определения filesystementry.php:9
$pathPhysical
Определения filesystementry.php:11
bool $exists
Определения filesystementry.php:13
$siteId
Определения filesystementry.php:12
getPhysicalPath()
Определения filesystementry.php:142
static convertPhysicalToLogical($path)
Определения path.php:144
static combine(... $args)
Определения path.php:254
$f
Определения component_props.php:52
$handle
Определения include.php:55
$p
Определения group_list_element_edit.php:23
$name
Определения menu_edit.php:35
Определения Image.php:9
Определения directory.php:3
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$dir
Определения quickway.php:303
path
Определения template_copy.php:201