|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package Fuel\FileSystem |
|
4
|
|
|
* @version 2.0 |
|
5
|
|
|
* @author Fuel Development Team |
|
6
|
|
|
* @license MIT License |
|
7
|
|
|
* @copyright 2010 - 2015 Fuel Development Team |
|
8
|
|
|
* @link http://fuelphp.com |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Fuel\FileSystem; |
|
12
|
|
|
|
|
13
|
|
|
abstract class Handler |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $path; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param string $path |
|
22
|
|
|
*/ |
|
23
|
3 |
|
public function __construct($path) |
|
24
|
|
|
{ |
|
25
|
3 |
|
$this->path = $path; |
|
26
|
3 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Checks whether a file/dir exists |
|
30
|
|
|
* |
|
31
|
|
|
* @return boolean |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function exists() |
|
34
|
|
|
{ |
|
35
|
1 |
|
return file_exists($this->path); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Deletes a file/dir |
|
40
|
|
|
* |
|
41
|
|
|
* @return boolean |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function delete() |
|
44
|
|
|
{ |
|
45
|
1 |
|
return unlink($this->path); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Moves a file/dir |
|
50
|
|
|
* |
|
51
|
|
|
* @return boolean |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function moveTo($destination) |
|
54
|
|
|
{ |
|
55
|
1 |
|
return $this->renameTo($destination); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Renames a file/dir |
|
60
|
|
|
* |
|
61
|
|
|
* @return boolean |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function renameTo($name) |
|
64
|
|
|
{ |
|
65
|
1 |
|
if (strpos($name, DIRECTORY_SEPARATOR) !== 0) |
|
66
|
|
|
{ |
|
67
|
1 |
|
$name = pathinfo($this->path, PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.$name; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
if ( ! pathinfo($name, PATHINFO_EXTENSION)) |
|
71
|
|
|
{ |
|
72
|
1 |
|
$name .= '.'.pathinfo($this->path, PATHINFO_EXTENSION); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
if ($result = rename($this->path, $name)) |
|
76
|
|
|
{ |
|
77
|
1 |
|
$this->path = realpath($name); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
return $result; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Creates a symlink to a file/dir |
|
85
|
|
|
* |
|
86
|
|
|
* @return boolean |
|
87
|
|
|
*/ |
|
88
|
|
|
public function symlinkTo($destination) |
|
89
|
|
|
{ |
|
90
|
|
|
return symlink($this->path, $destination); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Checks wether a file/dir is writable |
|
95
|
|
|
* |
|
96
|
|
|
* @return boolean |
|
97
|
|
|
*/ |
|
98
|
|
|
public function isWritable() |
|
99
|
|
|
{ |
|
100
|
|
|
return is_writable($this->path); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Checks wether a file/dir is readable |
|
105
|
|
|
* |
|
106
|
|
|
* @return boolean |
|
107
|
|
|
*/ |
|
108
|
|
|
public function isReadable() |
|
109
|
|
|
{ |
|
110
|
|
|
return is_readable($this->path); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Retrieves wether the path is a file or a dir |
|
115
|
|
|
* |
|
116
|
|
|
* @return string |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function getType() |
|
119
|
|
|
{ |
|
120
|
1 |
|
return filetype($this->path); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Retrieves the last access time |
|
125
|
|
|
* |
|
126
|
|
|
* @return integer |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function getAccessTime() |
|
129
|
|
|
{ |
|
130
|
1 |
|
return fileatime($this->path); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Retrieves the last modified time |
|
135
|
|
|
* |
|
136
|
|
|
* @return integer |
|
137
|
|
|
*/ |
|
138
|
1 |
|
public function getModifiedTime() |
|
139
|
|
|
{ |
|
140
|
1 |
|
return filemtime($this->path); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Retrieves the created time |
|
145
|
|
|
* |
|
146
|
|
|
* @return integer |
|
147
|
|
|
*/ |
|
148
|
1 |
|
public function getCreatedTime() |
|
149
|
|
|
{ |
|
150
|
1 |
|
return filectime($this->path); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Retrieves the permissions |
|
155
|
|
|
* |
|
156
|
|
|
* @return integer |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getPermissions() |
|
159
|
|
|
{ |
|
160
|
|
|
return fileperms($this->path); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Sets the permissions |
|
165
|
|
|
* |
|
166
|
|
|
* @return boolean |
|
167
|
|
|
*/ |
|
168
|
|
|
public function setPermissions($permissions) |
|
169
|
|
|
{ |
|
170
|
|
|
if (is_string($permissions)) |
|
171
|
|
|
{ |
|
172
|
|
|
$permissions = '0'.ltrim($permissions, '0'); |
|
173
|
|
|
$permissions = octdec($permissions); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
return chmod($this->path, $permissions); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Retrieves the path |
|
181
|
|
|
* |
|
182
|
|
|
* @return string |
|
183
|
|
|
*/ |
|
184
|
1 |
|
public function getPath() |
|
185
|
|
|
{ |
|
186
|
1 |
|
return $this->path; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Converts to path |
|
191
|
|
|
* |
|
192
|
|
|
* @return string |
|
193
|
|
|
*/ |
|
194
|
|
|
public function __toString() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->getPath(); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|