for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\Backup\BackupDestination;
use Exception;
class BackupPath
{
/** @var array */
protected static $allowedMimeTypes = [
'application/zip', 'application/x-zip', 'application/x-gzip',
];
/**
* Check if a path on a disk represents a backup.
*
* @param \Illuminate\Contracts\Filesystem\Filesystem|null $disk
* @param string $path
* @return bool
*/
public function check($disk, $path)
return $this->checkMimeType($disk, $path) ?: $this->checkExtension($path);
}
protected function checkExtension($path)
return pathinfo($path, PATHINFO_EXTENSION) === 'zip';
protected function checkMimeType($disk, $path)
return in_array($this->mimeType($disk, $path), self::$allowedMimeTypes);
* @return string|false
protected function mimeType($disk, $path)
try {
if ($disk && method_exists($disk, 'mimeType')) {
return $disk->mimeType($path) ?: false;
} catch (Exception $e) {
// Some drivers throw exceptions when checking mime types, we'll
// just fallback to `false`.
return false;