1 | <?php |
||
20 | class FileStorage |
||
21 | { |
||
22 | use AccessorTrait; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $root; |
||
28 | |||
29 | protected function get_root() |
||
33 | |||
34 | /** |
||
35 | * @var FileStorageIndex |
||
36 | */ |
||
37 | private $index; |
||
38 | |||
39 | protected function get_index() |
||
43 | |||
44 | /** |
||
45 | * @param string $root |
||
46 | * @param FileStorageIndex $index |
||
47 | */ |
||
48 | public function __construct($root, FileStorageIndex $index) |
||
58 | |||
59 | /** |
||
60 | * Adds a reference. |
||
61 | * |
||
62 | * @param int $nid |
||
63 | * @param string $uuid |
||
64 | * @param string $hash |
||
65 | * |
||
66 | * @return IndexKey |
||
67 | */ |
||
68 | public function index($nid, $uuid, $hash) |
||
78 | |||
79 | /** |
||
80 | * Adds a file. |
||
81 | * |
||
82 | * @param string $source Absolute path to the source file. |
||
83 | * |
||
84 | * @return Pathname |
||
85 | */ |
||
86 | public function add($source) |
||
102 | |||
103 | /** |
||
104 | * Releases a reference to a file. |
||
105 | * |
||
106 | * If a file has no reference left it is deleted. |
||
107 | * |
||
108 | * @param $key_or_id_or_uuid_or_hash |
||
109 | */ |
||
110 | public function release($key_or_id_or_uuid_or_hash) |
||
134 | |||
135 | /** |
||
136 | * Finds a file. |
||
137 | * |
||
138 | * @param IndexKey|int|string $key_or_nid_or_uuid_or_hash |
||
139 | * |
||
140 | * @return Pathname|null |
||
141 | */ |
||
142 | public function find($key_or_nid_or_uuid_or_hash) |
||
157 | |||
158 | /** |
||
159 | * Finds a file using its hash. |
||
160 | * |
||
161 | * @param string $hash A hash from {@link Pathname::hash()}. |
||
162 | * |
||
163 | * @return Pathname|null |
||
164 | */ |
||
165 | protected function find_by_hash($hash) |
||
177 | |||
178 | /** |
||
179 | * Hashes a file. |
||
180 | * |
||
181 | * The file is hashed with {@link Pathname::hash()}. |
||
182 | * |
||
183 | * @param string $pathname Absolute pathname to the file. |
||
184 | * |
||
185 | * @return string The hash of the file. |
||
186 | * |
||
187 | * @throws \LogicException if the file cannot be hashed. |
||
188 | */ |
||
189 | public function hash($pathname) |
||
193 | |||
194 | /** |
||
195 | * Creates hash pathname. |
||
196 | * |
||
197 | * @param string $pathname |
||
198 | * @param string $hash A hash from {@link Pathname::hash()}. If empty a hash is computed from |
||
199 | * the file. |
||
200 | * |
||
201 | * @return Pathname |
||
202 | */ |
||
203 | public function create_pathname($pathname, $hash = null) |
||
209 | |||
210 | /** |
||
211 | * Asserts that a hash is used by a file. |
||
212 | * |
||
213 | * @param string $hash |
||
214 | */ |
||
215 | protected function assert_hash_is_used($hash) |
||
222 | } |
||
223 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.