Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 1 |
| tao_models_classes_service_StorageDirectory | |
0.00% |
0 / 27 |
|
0.00% |
0 / 18 |
420 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getFlySystem | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isPublic | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPublicAccessUrl | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getRelativePath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| write | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| writeStream | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| writePsrStream | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| read | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| readStream | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| readPsrStream | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| updateStream | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| updatePsrStream | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| delete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| has | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getIterator | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | use League\Flysystem\Local\LocalFilesystemAdapter; |
| 24 | use oat\tao\model\websource\Websource; |
| 25 | use League\Flysystem\Filesystem; |
| 26 | use oat\oatbox\filesystem\Directory; |
| 27 | use Psr\Http\Message\StreamInterface; |
| 28 | |
| 29 | /** |
| 30 | * Represents directory for file storage |
| 31 | * |
| 32 | * @access public |
| 33 | * @author Joel Bout, <joel@taotesting.com> |
| 34 | * @package tao |
| 35 | */ |
| 36 | class tao_models_classes_service_StorageDirectory extends Directory |
| 37 | { |
| 38 | private $id; |
| 39 | |
| 40 | /** @var Websource */ |
| 41 | private $accessProvider; |
| 42 | |
| 43 | public function __construct($id, $filesystemId, $path, Websource $provider = null) |
| 44 | { |
| 45 | parent::__construct($filesystemId, $path); |
| 46 | $this->id = $id; |
| 47 | $this->accessProvider = $provider; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @deprecated Should not be called |
| 52 | * |
| 53 | * @return Filesystem |
| 54 | */ |
| 55 | public function getFlySystem() |
| 56 | { |
| 57 | return parent::getFilesystem(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the identifier of this directory |
| 62 | * |
| 63 | * @return string |
| 64 | */ |
| 65 | public function getId() |
| 66 | { |
| 67 | return $this->id; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns whenever or not this directory is public |
| 72 | * |
| 73 | * @return boolean |
| 74 | */ |
| 75 | public function isPublic() |
| 76 | { |
| 77 | return !is_null($this->accessProvider); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns a URL that allows you to access the files in a directory |
| 82 | * preserving the relative paths |
| 83 | * |
| 84 | * @return string |
| 85 | * @throws common_Exception |
| 86 | */ |
| 87 | public function getPublicAccessUrl() |
| 88 | { |
| 89 | if (is_null($this->accessProvider)) { |
| 90 | common_Logger::e('accessss'); |
| 91 | throw new common_Exception('Tried obtaining access to private directory with ID ' . $this->getId()); |
| 92 | } |
| 93 | return $this->accessProvider->getAccessUrl($this->prefix . DIRECTORY_SEPARATOR); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @deprecated use $this->getPrefix instead |
| 98 | * @return mixed|string |
| 99 | */ |
| 100 | public function getRelativePath() |
| 101 | { |
| 102 | return $this->getPrefix(); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @deprecated use File->write instead |
| 107 | * |
| 108 | * @param $path |
| 109 | * @param $string |
| 110 | * @param null $mimeType |
| 111 | * @return bool |
| 112 | * @throws common_Exception |
| 113 | */ |
| 114 | public function write($path, $string, $mimeType = null) |
| 115 | { |
| 116 | return $this->getFile($path)->write($string, $mimeType); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @deprecated use File->write instead |
| 121 | * |
| 122 | * @param $path |
| 123 | * @param $resource |
| 124 | * @param null $mimeType |
| 125 | * @return bool |
| 126 | * @throws common_Exception |
| 127 | */ |
| 128 | public function writeStream($path, $resource, $mimeType = null) |
| 129 | { |
| 130 | return $this->getFile($path)->write($resource, $mimeType); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * @deprecated use File->write instead |
| 135 | * |
| 136 | * @param $path |
| 137 | * @param $stream |
| 138 | * @param null $mimeType |
| 139 | * @return bool |
| 140 | * @throws common_Exception |
| 141 | */ |
| 142 | public function writePsrStream($path, $stream, $mimeType = null) |
| 143 | { |
| 144 | return $this->getFile($path)->write($stream, $mimeType); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * @deprecated use File->read instead |
| 149 | * |
| 150 | * @param $path |
| 151 | * @return false|string |
| 152 | */ |
| 153 | public function read($path) |
| 154 | { |
| 155 | return $this->getFile($path)->read(); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * @deprecated use File->readStream instead |
| 160 | * |
| 161 | * @param $path |
| 162 | * @return false|resource |
| 163 | */ |
| 164 | public function readStream($path) |
| 165 | { |
| 166 | return $this->getFile($path)->readStream(); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * @deprecated use File->readPsrStream instead |
| 171 | * |
| 172 | * @param $path |
| 173 | * @return StreamInterface |
| 174 | */ |
| 175 | public function readPsrStream($path) |
| 176 | { |
| 177 | return $this->getFile($path)->readPsrStream(); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * @deprecated use File->update instead |
| 182 | * |
| 183 | * @param $path |
| 184 | * @param $content |
| 185 | * @param null $mimeType |
| 186 | * @return bool |
| 187 | * @throws common_Exception |
| 188 | */ |
| 189 | public function update($path, $content, $mimeType = null) |
| 190 | { |
| 191 | return $this->getFile($path)->update($content, $mimeType); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * @deprecated use File->update instead |
| 196 | * |
| 197 | * @param $path |
| 198 | * @param $resource |
| 199 | * @param null $mimeType |
| 200 | * @return bool |
| 201 | * @throws common_Exception |
| 202 | */ |
| 203 | public function updateStream($path, $resource, $mimeType = null) |
| 204 | { |
| 205 | return $this->getFile($path)->update($resource, $mimeType); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * @deprecated use File->update instead |
| 210 | * |
| 211 | * @param $path |
| 212 | * @param StreamInterface $stream |
| 213 | * @param null $mimeType |
| 214 | * @return bool |
| 215 | * @throws common_Exception |
| 216 | */ |
| 217 | public function updatePsrStream($path, StreamInterface $stream, $mimeType = null) |
| 218 | { |
| 219 | return $this->getFile($path)->update($stream, $mimeType); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * @deprecated use File->delete instead |
| 224 | * |
| 225 | * @param $path |
| 226 | * @return bool |
| 227 | */ |
| 228 | public function delete($path) |
| 229 | { |
| 230 | return $this->getFile($path)->delete(); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @deprecated use File->exists instead |
| 235 | * |
| 236 | * @param $path |
| 237 | * @return bool |
| 238 | */ |
| 239 | public function has($path) |
| 240 | { |
| 241 | return $this->getDirectory($path)->exists(); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * @deprecated use $this->getFlyIterator instead |
| 246 | * |
| 247 | * @return ArrayIterator |
| 248 | */ |
| 249 | public function getIterator(): Traversable |
| 250 | { |
| 251 | $files = []; |
| 252 | $iterator = $this->getFlyIterator(Directory::ITERATOR_FILE | Directory::ITERATOR_RECURSIVE); |
| 253 | foreach ($iterator as $file) { |
| 254 | $files[] = $this->getRelPath($file); |
| 255 | } |
| 256 | return new ArrayIterator($files); |
| 257 | } |
| 258 | } |