Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
* main:
  return correct type from mimeType and fileSize methods
  implement readStream method
  restore composer to original
  use forked branch
  Add branch alias for dev-master
  Fix listing the root directory if the prefix is /
  • Loading branch information
jnovermars committed Oct 5, 2023
2 parents 1fd75b8 + 5d68877 commit c6f190e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-main": "1.0.x-dev"
}
}
}
42 changes: 39 additions & 3 deletions src/FlysystemSharepointAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ public function read(string $path): string
*/
public function readStream(string $path)
{
// TODO: Implement readStream() method.
$path = $this->applyPrefix($path);
/** @var resource $readStream */
$readStream = fopen($this->connector->getFile()->requestFileStreamUrl($path), 'rb');

if (! $readStream) {
fclose($readStream);
throw UnableToReadFile::fromLocation($path);
}

return $readStream;
}

/**
Expand Down Expand Up @@ -183,7 +192,19 @@ public function visibility(string $path): FileAttributes
*/
public function mimeType(string $path): FileAttributes
{
$this->connector->getFile()->checkFileMimeType($this->applyPrefix($path));
$path = $this->applyPrefix($path);

try {
$mimetype = $this->connector->getFile()->checkFileMimeType($path);
} catch (Throwable $exception) {
throw UnableToRetrieveMetadata::mimeType($path, $exception->getMessage(), $exception);
}

if ($mimetype === null) {
throw UnableToRetrieveMetadata::mimeType($path, 'Unknown.');
}

return new FileAttributes($path, null, null, null, $mimetype);
}

/**
Expand All @@ -203,7 +224,19 @@ public function lastModified(string $path): FileAttributes
*/
public function fileSize(string $path): FileAttributes
{
$this->connector->getFile()->checkFileSize($this->applyPrefix($path));
$path = $this->applyPrefix($path);

try {
$fileSize = $this->connector->getFile()->checkFileSize($this->applyPrefix($path));
} catch (Throwable $exception) {
throw UnableToRetrieveMetadata::fileSize($path, $exception->getMessage(), $exception);
}

if ($fileSize === null) {
throw UnableToRetrieveMetadata::fileSize($path, 'Unknown.');
}

return new FileAttributes($path, $fileSize);
}

/**
Expand Down Expand Up @@ -268,6 +301,9 @@ public function copy(string $source, string $destination, Config $config): void
}

private function applyPrefix(string $path): string {
if($path === '' || $path === '/'){
return $this->getPrefix();
}
return sprintf('%s/%s', $this->getPrefix(), ltrim($path));
}
}

0 comments on commit c6f190e

Please sign in to comment.