1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package CleverStyle Framework |
4
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
5
|
|
|
* @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi |
6
|
|
|
* @license MIT License, see license.txt |
7
|
|
|
*/ |
8
|
|
|
namespace cs\Storage; |
9
|
|
|
class Local extends _Abstract { |
10
|
|
|
/** |
11
|
|
|
* @inheritdoc |
12
|
|
|
*/ |
13
|
2 |
|
public function __construct ($base_url, $host, $user = '', $password = '') { |
14
|
2 |
|
$this->base_url = url_by_source(PUBLIC_STORAGE); |
15
|
2 |
|
$this->connected = true; |
16
|
2 |
|
} |
17
|
|
|
/** |
18
|
|
|
* @inheritdoc |
19
|
|
|
*/ |
20
|
2 |
|
public function get_files_list ( |
21
|
|
|
$dir, |
22
|
|
|
$mask = false, |
23
|
|
|
$mode = 'f', |
24
|
|
|
$prefix_path = false, |
25
|
|
|
$subfolders = false, |
26
|
|
|
$sort = false, |
27
|
|
|
$exclusion = false, |
28
|
|
|
$system_files = false, |
29
|
|
|
$apply = null, |
30
|
|
|
$limit = null |
31
|
|
|
) { |
32
|
2 |
|
return get_files_list($this->absolute_path($dir), $mask, $mode, $prefix_path, $subfolders, $sort, $exclusion, $system_files, $apply, $limit); |
33
|
|
|
} |
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
2 |
|
public function file ($filename, $flags = null) { |
38
|
2 |
|
return file($this->absolute_path($filename), $flags); |
39
|
|
|
} |
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
2 |
|
public function file_get_contents ($filename, $flags = null) { |
44
|
2 |
|
return file_get_contents($this->absolute_path($filename), $flags); |
45
|
|
|
} |
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
2 |
|
public function file_put_contents ($filename, $data, $flags = null) { |
50
|
2 |
|
return file_put_contents($this->absolute_path($filename), $data, $flags); |
51
|
|
|
} |
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
*/ |
55
|
2 |
|
public function copy ($source, $dest) { |
56
|
2 |
|
return copy($this->absolute_path($source), $this->absolute_path($dest)); |
57
|
|
|
} |
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
2 |
|
public function unlink ($filename) { |
62
|
2 |
|
return unlink($this->absolute_path($filename)); |
63
|
|
|
} |
64
|
|
|
/** |
65
|
|
|
* @inheritdoc |
66
|
|
|
*/ |
67
|
2 |
|
public function file_exists ($filename) { |
68
|
2 |
|
return file_exists($this->absolute_path($filename)); |
69
|
|
|
} |
70
|
|
|
/** |
71
|
|
|
* @inheritdoc |
72
|
|
|
*/ |
73
|
2 |
|
public function rename ($oldname, $newname) { |
74
|
2 |
|
return rename($this->absolute_path($oldname), $this->absolute_path($newname)); |
75
|
|
|
} |
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
2 |
|
public function mkdir ($pathname, $mode = 0777, $recursive = false) { |
80
|
|
|
/** @noinspection MkdirRaceConditionInspection */ |
81
|
2 |
|
return mkdir($this->absolute_path($pathname), $mode, $recursive); |
82
|
|
|
} |
83
|
|
|
/** |
84
|
|
|
* @inheritdoc |
85
|
|
|
*/ |
86
|
2 |
|
public function rmdir ($dirname) { |
87
|
2 |
|
return rmdir($this->absolute_path($dirname)); |
88
|
|
|
} |
89
|
|
|
/** |
90
|
|
|
* @inheritdoc |
91
|
|
|
*/ |
92
|
2 |
|
public function is_file ($filename) { |
93
|
2 |
|
return is_file($this->absolute_path($filename)); |
94
|
|
|
} |
95
|
|
|
/** |
96
|
|
|
* @inheritdoc |
97
|
|
|
*/ |
98
|
2 |
|
public function is_dir ($filename) { |
99
|
2 |
|
return is_dir($this->absolute_path($filename)); |
100
|
|
|
} |
101
|
|
|
/** |
102
|
|
|
* @inheritdoc |
103
|
|
|
*/ |
104
|
2 |
|
public function url_by_source ($source) { |
105
|
2 |
|
return url_by_source($this->absolute_path($source)); |
106
|
|
|
} |
107
|
|
|
/** |
108
|
|
|
* @inheritdoc |
109
|
|
|
*/ |
110
|
2 |
|
public function source_by_url ($url) { |
111
|
2 |
|
return $this->relative_path(source_by_url($url)); |
112
|
|
|
} |
113
|
2 |
|
protected function absolute_path ($path) { |
|
|
|
|
114
|
2 |
|
return preg_match('#^(([a-z]+:)?//|/)#i', $path) ? $path : PUBLIC_STORAGE.'/'.ltrim($path); |
115
|
|
|
} |
116
|
2 |
|
protected function relative_path ($path) { |
|
|
|
|
117
|
2 |
|
return strpos($path, PUBLIC_STORAGE.'/') === 0 ? $path : substr($path, strlen(PUBLIC_STORAGE.'/')); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.