Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checksum + fixed bug vars type #77

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
vendor
bin
coverage
coverage.xml
composer.lock
.DS_Store
.idea/
phpunit.xml
.phpunit.result.cache
18 changes: 17 additions & 1 deletion WebDAVAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace League\Flysystem\WebDAV;

use League\Flysystem\ChecksumProvider;
use League\Flysystem\Config;
use League\Flysystem\DirectoryAttributes;
use League\Flysystem\FileAttributes;
Expand All @@ -16,6 +17,7 @@
use League\Flysystem\UnableToDeleteDirectory;
use League\Flysystem\UnableToDeleteFile;
use League\Flysystem\UnableToMoveFile;
use League\Flysystem\UnableToProvideChecksum;
use League\Flysystem\UnableToReadFile;
use League\Flysystem\UnableToRetrieveMetadata;
use League\Flysystem\UnableToSetVisibility;
Expand All @@ -37,7 +39,7 @@
use function parse_url;
use function rawurldecode;

class WebDAVAdapter implements FilesystemAdapter, PublicUrlGenerator
class WebDAVAdapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumProvider
{
public const ON_VISIBILITY_THROW_ERROR = 'throw';
public const ON_VISIBILITY_IGNORE = 'ignore';
Expand Down Expand Up @@ -447,4 +449,18 @@ public function publicUrl(string $path, Config $config): string
{
return $this->client->getAbsoluteUrl($this->encodePath($this->prefixer->prefixPath($path)));
}

public function checksum(string $path, Config $config): string
{
$algo = $config->get('checksum_algo', 'md5');
$contents = $this->read($path);
error_clear_last();
$checksum = @hash($algo, $contents);

if ($checksum === false) {
throw new UnableToProvideChecksum(error_get_last()['message'] ?? '', $path);
}

return $checksum;
}
}