| @@ -1,16 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace WPIDE\App\Services\Storage\Adapters; |
| 3 | 3 | |
| 4 | -use finfo as Finfo; | |
| 5 | 4 | use DirectoryIterator; |
| 6 | 5 | use FilesystemIterator; |
| 7 | -use League\Flysystem\Config; | |
| 8 | 6 | use League\Flysystem\Exception; |
| 9 | 7 | use League\Flysystem\NotSupportedException; |
| 10 | 8 | use League\Flysystem\UnreadableFileException; |
| 11 | 9 | use League\Flysystem\Util; |
| 12 | 10 | use League\Flysystem\Adapter\AbstractAdapter; |
| 11 | +use League\MimeTypeDetection\ExtensionMimeTypeDetector; | |
| 12 | +use League\MimeTypeDetection\FinfoMimeTypeDetector; | |
| 13 | 13 | use LogicException; |
| 14 | 14 | use RecursiveDirectoryIterator; |
| 15 | 15 | use RecursiveIteratorIterator; |
| 16 | 16 | use SplFileInfo; |
| @@ -146,9 +146,9 @@ | ||
| 146 | 146 | /** |
| 147 | 147 | * @inheritdoc |
| 148 | 148 | * @throws Exception |
| 149 | 149 | */ |
| 150 | - public function write($path, $contents, Config $config) | |
| 150 | + public function write($path, $contents, $config) | |
| 151 | 151 | { |
| 152 | 152 | $path = $this->getRelativePath( $path ); |
| 153 | 153 | $location = $this->applyPathPrefix($path); |
| 154 | 154 | $this->ensureDirectory(dirname($location)); |
| @@ -171,14 +171,14 @@ | ||
| 171 | 171 | /** |
| 172 | 172 | * @inheritdoc |
| 173 | 173 | * @throws Exception |
| 174 | 174 | */ |
| 175 | - public function writeStream($path, $resource, Config $config) | |
| 175 | + public function writeStream($path, $resource, $config) | |
| 176 | 176 | { |
| 177 | 177 | $path = $this->getRelativePath( $path ); |
| 178 | 178 | $location = $this->applyPathPrefix($path); |
| 179 | 179 | $this->ensureDirectory(dirname($location)); |
| 180 | - $stream = fopen($location, 'w+b'); | |
| 180 | + $stream = @fopen($location, 'w+b'); | |
| 181 | 181 | |
| 182 | 182 | if ( ! $stream || stream_copy_to_stream($resource, $stream) === false || ! fclose($stream)) { |
| 183 | 183 | return false; |
| 184 | 184 | } |
| @@ -200,9 +200,9 @@ | ||
| 200 | 200 | public function readStream($path) |
| 201 | 201 | { |
| 202 | 202 | $path = $this->getRelativePath( $path ); |
| 203 | 203 | $location = $this->applyPathPrefix($path); |
| 204 | - $stream = fopen($location, 'rb'); | |
| 204 | + $stream = @fopen($location, 'rb'); | |
| 205 | 205 | |
| 206 | 206 | return ['type' => 'file', 'path' => $path, 'stream' => $stream]; |
| 207 | 207 | } |
| 208 | 208 | |
| @@ -208,9 +208,9 @@ | ||
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | 210 | * @inheritdoc |
| 211 | 211 | */ |
| 212 | - public function updateStream($path, $resource, Config $config) | |
| 212 | + public function updateStream($path, $resource, $config) | |
| 213 | 213 | { |
| 214 | 214 | $path = $this->getRelativePath( $path ); |
| 215 | 215 | return $this->writeStream($path, $resource, $config); |
| 216 | 216 | } |
| @@ -217,9 +217,9 @@ | ||
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | 219 | * @inheritdoc |
| 220 | 220 | */ |
| 221 | - public function update($path, $contents, Config $config) | |
| 221 | + public function update($path, $contents, $config) | |
| 222 | 222 | { |
| 223 | 223 | $path = $this->getRelativePath( $path ); |
| 224 | 224 | $location = $this->applyPathPrefix($path); |
| 225 | 225 | |
| @@ -356,14 +356,15 @@ | ||
| 356 | 356 | public function getMimetype($path) |
| 357 | 357 | { |
| 358 | 358 | $path = $this->getRelativePath( $path ); |
| 359 | 359 | $location = $this->applyPathPrefix($path); |
| 360 | - $finfo = new Finfo(FILEINFO_MIME_TYPE); | |
| 361 | - $mimetype = $finfo->file($location); | |
| 362 | 360 | |
| 363 | - if (in_array($mimetype, ['application/octet-stream', 'inode/x-empty', 'application/x-empty'])) { | |
| 364 | - $mimetype = Util\MimeType::detectByFilename($location); | |
| 361 | + if(extension_loaded('fileinfo')) { | |
| 362 | + $mimeDetector = new FinfoMimeTypeDetector(); | |
| 363 | + }else{ | |
| 364 | + $mimeDetector = new ExtensionMimeTypeDetector(); | |
| 365 | 365 | } |
| 366 | + $mimetype = $mimeDetector->detectMimeTypeFromPath($location); | |
| 366 | 367 | |
| 367 | 368 | return ['path' => $path, 'type' => 'file', 'mimetype' => $mimetype]; |
| 368 | 369 | } |
| 369 | 370 | |
| @@ -417,9 +418,9 @@ | ||
| 417 | 418 | |
| 418 | 419 | /** |
| 419 | 420 | * @inheritdoc |
| 420 | 421 | */ |
| 421 | - public function createDir($dirname, Config $config) | |
| 422 | + public function createDir($dirname, $config) | |
| 422 | 423 | { |
| 423 | 424 | |
| 424 | 425 | $dirname = $this->getRelativePath( $dirname ); |
| 425 | 426 | $location = $this->applyPathPrefix($dirname); |