1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Flysystem; |
4
|
|
|
|
5
|
|
|
class File extends Handler |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Check whether the file exists. |
9
|
|
|
* |
10
|
|
|
* @return bool |
11
|
|
|
*/ |
12
|
3 |
|
public function exists() |
13
|
|
|
{ |
14
|
3 |
|
return $this->filesystem->has($this->path); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Read the file. |
19
|
|
|
* |
20
|
|
|
* @return string file contents |
21
|
|
|
*/ |
22
|
24 |
|
public function read() |
23
|
|
|
{ |
24
|
24 |
|
return $this->filesystem->read($this->path); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Read the file as a stream. |
29
|
|
|
* |
30
|
|
|
* @return resource file stream |
31
|
|
|
*/ |
32
|
6 |
|
public function readStream() |
33
|
|
|
{ |
34
|
6 |
|
return $this->filesystem->readStream($this->path); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Write the new file. |
39
|
|
|
* |
40
|
|
|
* @param string $content |
41
|
|
|
* |
42
|
|
|
* @return bool success boolean |
43
|
|
|
*/ |
44
|
3 |
|
public function write($content) |
45
|
|
|
{ |
46
|
3 |
|
return $this->filesystem->write($this->path, $content); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Write the new file using a stream. |
51
|
|
|
* |
52
|
|
|
* @param resource $resource |
53
|
|
|
* |
54
|
|
|
* @return bool success boolean |
55
|
|
|
*/ |
56
|
3 |
|
public function writeStream($resource) |
57
|
|
|
{ |
58
|
3 |
|
return $this->filesystem->writeStream($this->path, $resource); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Update the file contents. |
63
|
|
|
* |
64
|
|
|
* @param string $content |
65
|
|
|
* |
66
|
|
|
* @return bool success boolean |
67
|
|
|
*/ |
68
|
6 |
|
public function update($content) |
69
|
|
|
{ |
70
|
6 |
|
return $this->filesystem->update($this->path, $content); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Update the file contents with a stream. |
75
|
|
|
* |
76
|
|
|
* @param resource $resource |
77
|
|
|
* |
78
|
|
|
* @return bool success boolean |
79
|
|
|
*/ |
80
|
6 |
|
public function updateStream($resource) |
81
|
|
|
{ |
82
|
6 |
|
return $this->filesystem->updateStream($this->path, $resource); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Create the file or update if exists. |
87
|
|
|
* |
88
|
|
|
* @param string $content |
89
|
|
|
* |
90
|
|
|
* @return bool success boolean |
91
|
|
|
*/ |
92
|
3 |
|
public function put($content) |
93
|
|
|
{ |
94
|
3 |
|
return $this->filesystem->put($this->path, $content); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Create the file or update if exists using a stream. |
99
|
|
|
* |
100
|
|
|
* @param resource $resource |
101
|
|
|
* |
102
|
|
|
* @return bool success boolean |
103
|
|
|
*/ |
104
|
3 |
|
public function putStream($resource) |
105
|
|
|
{ |
106
|
3 |
|
return $this->filesystem->putStream($this->path, $resource); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Rename the file. |
111
|
|
|
* |
112
|
|
|
* @param string $newpath |
113
|
|
|
* |
114
|
|
|
* @return bool success boolean |
115
|
|
|
*/ |
116
|
6 |
|
public function rename($newpath) |
117
|
|
|
{ |
118
|
6 |
|
if ($this->filesystem->rename($this->path, $newpath)) { |
119
|
3 |
|
$this->path = $newpath; |
120
|
|
|
|
121
|
3 |
|
return true; |
122
|
|
|
} |
123
|
|
|
|
124
|
3 |
|
return false; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Copy the file. |
129
|
|
|
* |
130
|
|
|
* @param string $newpath |
131
|
|
|
* |
132
|
|
|
* @return File|false new file or false |
133
|
|
|
*/ |
134
|
6 |
|
public function copy($newpath) |
135
|
|
|
{ |
136
|
6 |
|
if ($this->filesystem->copy($this->path, $newpath)) { |
137
|
3 |
|
return new File($this->filesystem, $newpath); |
138
|
|
|
} |
139
|
|
|
|
140
|
3 |
|
return false; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get the file's timestamp. |
145
|
|
|
* |
146
|
|
|
* @return int unix timestamp |
147
|
|
|
*/ |
148
|
6 |
|
public function getTimestamp() |
149
|
|
|
{ |
150
|
6 |
|
return $this->filesystem->getTimestamp($this->path); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get the file's mimetype. |
155
|
|
|
* |
156
|
|
|
* @return string mimetime |
157
|
|
|
*/ |
158
|
6 |
|
public function getMimetype() |
159
|
|
|
{ |
160
|
6 |
|
return $this->filesystem->getMimetype($this->path); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Get the file's visibility. |
165
|
|
|
* |
166
|
|
|
* @return string visibility |
167
|
|
|
*/ |
168
|
6 |
|
public function getVisibility() |
169
|
|
|
{ |
170
|
6 |
|
return $this->filesystem->getVisibility($this->path); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get the file's metadata. |
175
|
|
|
* |
176
|
|
|
* @return array |
177
|
|
|
*/ |
178
|
6 |
|
public function getMetadata() |
179
|
|
|
{ |
180
|
6 |
|
return $this->filesystem->getMetadata($this->path); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Get the file size. |
185
|
|
|
* |
186
|
|
|
* @return int file size |
187
|
|
|
*/ |
188
|
6 |
|
public function getSize() |
189
|
|
|
{ |
190
|
6 |
|
return $this->filesystem->getSize($this->path); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Delete the file. |
195
|
|
|
* |
196
|
|
|
* @return bool success boolean |
197
|
|
|
*/ |
198
|
6 |
|
public function delete() |
199
|
|
|
{ |
200
|
6 |
|
return $this->filesystem->delete($this->path); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|