Skip to content

Commit

Permalink
Merge pull request #1794 from GromNaN/gridfs
Browse files Browse the repository at this point in the history
Add MongoDB GridFS Adapter
  • Loading branch information
frankdejonge authored May 22, 2024
2 parents 0487c25 + 612b104 commit 17f5fab
Show file tree
Hide file tree
Showing 11 changed files with 823 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/quality-assurance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ env:
FLYSYSTEM_AWS_S3_KEY: '${{ secrets.FLYSYSTEM_AWS_S3_KEY }}'
FLYSYSTEM_AWS_S3_SECRET: '${{ secrets.FLYSYSTEM_AWS_S3_SECRET }}'
FLYSYSTEM_AWS_S3_BUCKET: '${{ secrets.FLYSYSTEM_AWS_S3_BUCKET }}'
MONGODB_URI: 'mongodb://127.0.0.1:27017/'
FLYSYSTEM_TEST_DANGEROUS_THINGS: "yes"
FLYSYSTEM_TEST_SFTP: "yes"

Expand Down Expand Up @@ -70,6 +71,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mongodb
coverage: pcov
tools: composer:v2
- run: composer update --no-progress ${{ matrix.composer-flags }}
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"ext-zip": "*",
"ext-fileinfo": "*",
"ext-ftp": "*",
"ext-mongodb": "^1.3",
"microsoft/azure-storage-blob": "^1.1",
"phpunit/phpunit": "^9.5.11|^10.0",
"phpstan/phpstan": "^1.10",
Expand All @@ -35,6 +36,7 @@
"google/cloud-storage": "^1.23",
"async-aws/s3": "^1.5 || ^2.0",
"async-aws/simple-s3": "^1.1 || ^2.0",
"mongodb/mongodb": "^1.2",
"sabre/dav": "^4.6.0",
"guzzlehttp/psr7": "^2.6"
},
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
version: "3"
services:
mongodb:
image: mongo:7
ports:
- "27017:27017"
sabredav:
image: php:8.1-alpine3.15
restart: always
Expand Down
19 changes: 18 additions & 1 deletion src/AdapterTestUtilities/FilesystemAdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use League\Flysystem\FileAttributes;
use League\Flysystem\FilesystemAdapter;
use League\Flysystem\StorageAttributes;
use League\Flysystem\UnableToCopyFile;
use League\Flysystem\UnableToMoveFile;
use League\Flysystem\UnableToProvideChecksum;
use League\Flysystem\UnableToReadFile;
Expand Down Expand Up @@ -151,7 +152,9 @@ public function writing_a_file_with_a_stream(): void
$adapter = $this->adapter();
$writeStream = stream_with_contents('contents');

$adapter->writeStream('path.txt', $writeStream, new Config());
$adapter->writeStream('path.txt', $writeStream, new Config([
Config::OPTION_VISIBILITY => Visibility::PUBLIC,
]));

if (is_resource($writeStream)) {
fclose($writeStream);
Expand Down Expand Up @@ -592,10 +595,23 @@ public function copying_a_file(): void
$this->assertTrue($adapter->fileExists('source.txt'));
$this->assertTrue($adapter->fileExists('destination.txt'));
$this->assertEquals(Visibility::PUBLIC, $adapter->visibility('destination.txt')->visibility());
$this->assertEquals('text/plain', $adapter->mimeType('destination.txt')->mimeType());
$this->assertEquals('contents to be copied', $adapter->read('destination.txt'));
});
}

/**
* @test
*/
public function copying_a_file_that_does_not_exist(): void
{
$this->expectException(UnableToCopyFile::class);

$this->runScenario(function () {
$this->adapter()->copy('source.txt', 'destination.txt', new Config());
});
}

/**
* @test
*/
Expand Down Expand Up @@ -640,6 +656,7 @@ public function moving_a_file(): void
'After moving, a file should be present at the new location.'
);
$this->assertEquals(Visibility::PUBLIC, $adapter->visibility('destination.txt')->visibility());
$this->assertEquals('text/plain', $adapter->mimeType('destination.txt')->mimeType());
$this->assertEquals('contents to be copied', $adapter->read('destination.txt'));
});
}
Expand Down
8 changes: 8 additions & 0 deletions src/GridFS/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* text=auto

.github export-ignore
.gitattributes export-ignore
.gitignore export-ignore
**/*Test.php export-ignore
**/*Stub.php export-ignore
README.md export-ignore
30 changes: 30 additions & 0 deletions src/GridFS/.github/workflows/close-subsplit-prs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Close sub-split PRs

on:
push:
branches:
- 2.x
- 3.x
pull_request:
branches:
- 2.x
- 3.x
schedule:
- cron: '30 7 * * *'

jobs:
close_subsplit_prs:
runs-on: ubuntu-latest
name: Close sub-split PRs
steps:
- uses: frankdejonge/[email protected]
with:
close_pr: 'yes'
target_branch_match: '^(?!master).+$'
message: |
Hi :wave:,
Thank you for contributing to Flysystem. Unfortunately, you've sent a PR to a read-only sub-split repository.
All pull requests should be directed towards: https://github.com/thephpleague/flysystem
Loading

0 comments on commit 17f5fab

Please sign in to comment.