Skip to content

Commit

Permalink
Throw Flysystem FileNotFoundException at appropriate points.
Browse files Browse the repository at this point in the history
This still needs to be formally tested to catch them all.
  • Loading branch information
judgej committed Feb 26, 2018
1 parent 514ebab commit 4afd7c4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
16 changes: 7 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

This repo is fork of [League\Flysystem\Azure](https://github.com/thephpleague/flysystem-azure)

# Why forked?

The original Azure Flysystem adapter supported Blobs.
This alternative adapter supports Azure File Storage, with directory support.

I separate service provider package for Laravel 5.5+ will be available.
I separate service provider package for Laravel 5.5+ is available here:
https://github.com/academe/laravel-azure-file-storage-driver
The service provider allows Azure File Storage shares tbe be used
as native filesystems within Laravel.

# How to install

Expand Down Expand Up @@ -56,13 +54,13 @@ $filesystem = new Filesystem(new AzureFileAdapter(

// Now the $filesystem object can be used as a standard
// Flysystem file system.
// See https://flysystem.thephpleague.com/api/

// A few examples:

$content = $filesystem->read('path/to/my/file.txt');
$resource = $filesystem->readResource('path/to/my/file.txt');
$success = $filesystem->createDir('new/directory/here');
$success = $filesystem->rename('path/to/my/file.txt', 'some/other/folder/another.txt');

// etc.

```

36 changes: 29 additions & 7 deletions src/AzureFileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait;
use League\Flysystem\Config;
use League\Flysystem\Util;
use League\Flysystem\FileNotFoundException;

use MicrosoftAzure\Storage\File\Internal\IFile;
use MicrosoftAzure\Storage\File\Models\ListDirectoriesAndFilesOptions;
use MicrosoftAzure\Storage\File\Models\ListDirectoriesAndFilesResult;
Expand All @@ -14,6 +16,8 @@
use MicrosoftAzure\Storage\File\Models\GetDirectoryPropertiesResult;
use MicrosoftAzure\Storage\File\Models\CreateFileFromContentOptions;

use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;

class AzureFileAdapter extends AbstractAdapter
{
use NotSupportingVisibilityTrait;
Expand Down Expand Up @@ -329,6 +333,8 @@ public function read($pathName)

$result['contents'] = stream_get_contents($result['stream']);

unset($result['stream']);

return $result;
}

Expand All @@ -339,7 +345,15 @@ public function readStream($pathName)
{
$pathName = $this->applyPathPrefix($pathName);

$fileResult = $this->client->getFile($this->container, $pathName);
try {
$fileResult = $this->client->getFile($this->container, $pathName);
} catch (ServiceException $e) {
if ($e->getCode() === 404) {
throw new FileNotFoundException($pathName, $e->getCode(), $e);
}

throw $e;
}

return array_merge(
$this->normalizeFileProperties($pathName, $fileResult->getProperties()),
Expand Down Expand Up @@ -369,12 +383,20 @@ protected function getContents($directory, $recursive = false)

$directory = trim($directory, '/');

/** @var ListDirectoriesAndFilesResult $listResults */
$listResults = $this->client->listDirectoriesAndFiles(
$this->container,
$directory,
$options
);
try {
/** @var ListDirectoriesAndFilesResult $listResults */
$listResults = $this->client->listDirectoriesAndFiles(
$this->container,
$directory,
$options
);
} catch (ServiceException $e) {
if ($e->getCode() === 404) {
throw new FileNotFoundException($directory, $e->getCode(), $e);
}

throw $e;
}

$contents = [];

Expand Down

0 comments on commit 4afd7c4

Please sign in to comment.