|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) 2016, Robin Appelman <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
8
|
|
|
* as published by the Free Software Foundation. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU Affero General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace OC\Lockdown\Filesystem; |
|
21
|
|
|
|
|
22
|
|
|
use OC\Files\Cache\CacheEntry; |
|
23
|
|
|
use OCP\Constants; |
|
24
|
|
|
use OCP\Files\Cache\ICache; |
|
25
|
|
|
use OCP\Files\Cache\ICacheEntry; |
|
26
|
|
|
use OCP\Files\FileInfo; |
|
27
|
|
|
|
|
28
|
|
|
class NullCache implements ICache { |
|
29
|
|
|
public function getNumericStorageId() { |
|
30
|
|
|
return -1; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function get($file) { |
|
34
|
|
|
return $file !== '' ? null : |
|
35
|
|
|
new CacheEntry([ |
|
36
|
|
|
'fileid' => -1, |
|
37
|
|
|
'parent' => -1, |
|
38
|
|
|
'name' => '', |
|
39
|
|
|
'path' => '', |
|
40
|
|
|
'size' => '0', |
|
41
|
|
|
'mtime' => time(), |
|
42
|
|
|
'storage_mtime' => time(), |
|
43
|
|
|
'etag' => '', |
|
44
|
|
|
'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
45
|
|
|
'mimepart' => 'httpd', |
|
46
|
|
|
'permissions' => Constants::PERMISSION_READ |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getFolderContents($folder) { |
|
51
|
|
|
return []; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getFolderContentsById($fileId) { |
|
55
|
|
|
return []; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function put($file, array $data) { |
|
59
|
|
|
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function insert($file, array $data) { |
|
63
|
|
|
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function update($id, array $data) { |
|
67
|
|
|
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getId($file) { |
|
71
|
|
|
return -1; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getParentId($file) { |
|
75
|
|
|
return -1; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function inCache($file) { |
|
79
|
|
|
return $file === ''; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function remove($file) { |
|
83
|
|
|
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function move($source, $target) { |
|
87
|
|
|
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
91
|
|
|
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getStatus($file) { |
|
95
|
|
|
return ICache::COMPLETE; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function search($pattern) { |
|
99
|
|
|
return []; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function searchByMime($mimetype) { |
|
103
|
|
|
return []; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function searchByTag($tag, $userId) { |
|
107
|
|
|
return []; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getIncomplete() { |
|
111
|
|
|
return []; |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getPathById($id) { |
|
115
|
|
|
return ''; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function normalize($path) { |
|
119
|
|
|
return $path; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.