|
1
|
|
|
<?php /** MicroLocalDriver */ |
|
2
|
|
|
|
|
3
|
|
|
namespace Micro\File\Drivers; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class LocalDriver is a driver for local filesystem |
|
7
|
|
|
* |
|
8
|
|
|
* @author Oleg Lunegov <[email protected]> |
|
9
|
|
|
* @link https://github.com/linpax/microphp-framework |
|
10
|
|
|
* @copyright Copyright (c) 2013 Oleg Lunegov |
|
11
|
|
|
* @license https://github.com/linpax/microphp-framework/blob/master/LICENSE |
|
12
|
|
|
* @package Micro |
|
13
|
|
|
* @subpackage File\Drivers |
|
14
|
|
|
* @version 1.0 |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
class LocalDriver extends File |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @inheritdoc |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->createStream(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @inheritdoc |
|
29
|
|
|
*/ |
|
30
|
|
|
public function createStream() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->stream = true; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritdoc |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __destruct() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->deleteStream(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritdoc |
|
45
|
|
|
*/ |
|
46
|
|
|
public function deleteStream() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->stream = false; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritdoc |
|
53
|
|
|
*/ |
|
54
|
|
|
public function file_exists($filePath) |
|
55
|
|
|
{ |
|
56
|
|
|
return \file_exists($filePath); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @inheritdoc |
|
61
|
|
|
*/ |
|
62
|
|
|
public function copy($sourcePath, $destinationPath) |
|
63
|
|
|
{ |
|
64
|
|
|
return \copy($sourcePath, $destinationPath); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @inheritdoc |
|
69
|
|
|
*/ |
|
70
|
|
|
public function unlink($filePath) |
|
71
|
|
|
{ |
|
72
|
|
|
return \unlink($filePath); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @inheritdoc |
|
77
|
|
|
*/ |
|
78
|
|
|
public function file_get_contents($filePath) |
|
79
|
|
|
{ |
|
80
|
|
|
return \file_get_contents($filePath); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @inheritdoc |
|
85
|
|
|
*/ |
|
86
|
|
|
public function file_put_contents($filePath, $data) |
|
87
|
|
|
{ |
|
88
|
|
|
return \file_put_contents($filePath, $data); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @inheritdoc |
|
93
|
|
|
*/ |
|
94
|
|
|
public function mtime($filePath) |
|
95
|
|
|
{ |
|
96
|
|
|
return \filemtime($filePath); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @inheritdoc |
|
101
|
|
|
*/ |
|
102
|
|
|
public function size($filePath) |
|
103
|
|
|
{ |
|
104
|
|
|
return \filesize($filePath); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @inheritdoc |
|
109
|
|
|
*/ |
|
110
|
|
|
public function disk_free_space($directory) |
|
111
|
|
|
{ |
|
112
|
|
|
return \disk_free_space($directory); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @inheritdoc |
|
117
|
|
|
*/ |
|
118
|
|
|
public function disk_total_space($directory) |
|
119
|
|
|
{ |
|
120
|
|
|
return \disk_total_space($directory); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @inheritdoc |
|
125
|
|
|
*/ |
|
126
|
|
|
public function readStream() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->stream; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @inheritdoc |
|
133
|
|
|
*/ |
|
134
|
|
|
public function updateStream() |
|
135
|
|
|
{ |
|
136
|
|
|
$this->stream = true; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|