Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
directory.php
1
<?php
2
namespace
Bitrix\Main\IO
;
3
4
class
Directory
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));
69
$pathPhysical
=
Path::combine
($this->
getPhysicalPath
(), $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
}
Bitrix\Main\IO\DirectoryEntry
Definition
directoryentry.php:6
Bitrix\Main\IO\Directory
Definition
directory.php:6
Bitrix\Main\IO\Directory\createDirectory
static createDirectory($path)
Definition
directory.php:148
Bitrix\Main\IO\Directory\createSubdirectory
createSubdirectory($name)
Definition
directory.php:85
Bitrix\Main\IO\Directory\deleteDirectory
static deleteDirectory($path)
Definition
directory.php:156
Bitrix\Main\IO\Directory\getModificationTime
getModificationTime()
Definition
directory.php:122
Bitrix\Main\IO\Directory\getChildren
getChildren()
Definition
directory.php:54
Bitrix\Main\IO\Directory\getCreationTime
getCreationTime()
Definition
directory.php:106
Bitrix\Main\IO\Directory\getPermissions
getPermissions()
Definition
directory.php:138
Bitrix\Main\IO\Directory\__construct
__construct($path, $siteId=null)
Definition
directory.php:7
Bitrix\Main\IO\Directory\isDirectoryExists
static isDirectoryExists($path)
Definition
directory.php:162
Bitrix\Main\IO\Directory\markWritable
markWritable()
Definition
directory.php:130
Bitrix\Main\IO\Directory\isExists
isExists()
Definition
directory.php:12
Bitrix\Main\IO\Directory\getLastAccessTime
getLastAccessTime()
Definition
directory.php:114
Bitrix\Main\IO\FileDeleteException
Definition
ioexception.php:54
Bitrix\Main\IO\File
Definition
file.php:7
Bitrix\Main\IO\FileNotFoundException
Definition
ioexception.php:45
Bitrix\Main\IO\FileSystemEntry\$path
$path
Definition
filesystementry.php:8
Bitrix\Main\IO\FileSystemEntry\$pathPhysical
$pathPhysical
Definition
filesystementry.php:10
Bitrix\Main\IO\FileSystemEntry\$siteId
$siteId
Definition
filesystementry.php:11
Bitrix\Main\IO\FileSystemEntry\getPhysicalPath
getPhysicalPath()
Definition
filesystementry.php:90
Bitrix\Main\IO\Path\convertPhysicalToLogical
static convertPhysicalToLogical($path)
Definition
path.php:128
Bitrix\Main\IO\Path\combine
static combine()
Definition
path.php:221
Bitrix\Main\IO
Definition
directory.php:2
modules
main
lib
io
directory.php
Создано системой
1.10.0