Skip to content

Commit 6493f7f

Browse files
dunglasmaxhelias
authored andcommitted
feat: add support for the WebDAV adapter
1 parent f99c1f7 commit 6493f7f

File tree

6 files changed

+174
-1
lines changed

6 files changed

+174
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ For each storage defined under `flysystem.storages`, an associated service is cr
5151
name you provide (in this case, a service `default.storage` will be created). The bundle also
5252
creates a named alias for each of these services.
5353

54-
This means you have two way of using the defined storages:
54+
This means you have two ways of using the defined storages:
5555

5656
* either using autowiring, by typehinting against the `FilesystemOperator` and using the
5757
variable name matching one of your storages:
@@ -111,6 +111,7 @@ to interact with your storage.
111111
4. [Using a lazy adapter to switch storage backend using an environment variable](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/4-using-lazy-adapter-to-switch-at-runtime.md)
112112
5. [Creating a custom adapter](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/5-creating-a-custom-adapter.md)
113113
6. [MongoDB GridFS](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/6-gridfs.md)
114+
7. [WebDAV](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/7-webdav.md)
114115

115116
* [Security issue disclosure procedure](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/A-security-disclosure-procedure.md)
116117
* [Configuration reference](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/B-configuration-reference.md)

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"league/flysystem-memory": "^3.1",
4646
"league/flysystem-read-only": "^3.15",
4747
"league/flysystem-sftp-v3": "^3.1",
48+
"league/flysystem-webdav": "^3.29",
4849
"symfony/dotenv": "^5.4 || ^6.0 || ^7.0",
4950
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
5051
"symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0",

docs/7-webdav.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# WebDAV
2+
3+
Flysystem is able to [interact with WebDAV servers](https://flysystem.thephpleague.com/docs/adapter/webdav/).
4+
To configure this bundle for such usage, you can rely on adapters in the same way you would
5+
for other storages.
6+
7+
### Installation
8+
9+
```
10+
composer require league/flysystem-webdav
11+
```
12+
13+
### Usage
14+
15+
```yaml
16+
# config/packages/flysystem.yaml
17+
18+
services:
19+
webdav_client:
20+
class: Sabre\DAV\Client
21+
arguments:
22+
- { baseUri: 'https://webdav.example.com/', userName: 'your_user', password: 'superSecret1234' }
23+
24+
flysystem:
25+
storages:
26+
webdav.storage:
27+
adapter: 'webdav'
28+
options:
29+
client: 'webdav_client'
30+
prefix: 'optional/path/prefix'
31+
visibility_handling: !php/const \League\Flysystem\WebDAV\WebDAVAdapter::ON_VISIBILITY_THROW_ERROR # throw
32+
manual_copy: false
33+
manual_move: false
34+
```

src/Adapter/AdapterDefinitionFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function __construct()
3838
new Builder\LocalAdapterDefinitionBuilder(),
3939
new Builder\MemoryAdapterDefinitionBuilder(),
4040
new Builder\SftpAdapterDefinitionBuilder(),
41+
new Builder\WebDAVAdapterDefinitionBuilder(),
4142
];
4243
}
4344

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the flysystem-bundle project.
5+
*
6+
* (c) Titouan Galopin <galopintitouan@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace League\FlysystemBundle\Adapter\Builder;
13+
14+
use League\Flysystem\WebDAV\WebDAVAdapter;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @author Kévin Dunglas <kevin@dunglas.dev>
21+
*
22+
* @internal
23+
*/
24+
final class WebDAVAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder
25+
{
26+
public function getName(): string
27+
{
28+
return 'webdav';
29+
}
30+
31+
protected function getRequiredPackages(): array
32+
{
33+
return [
34+
WebDAVAdapter::class => 'league/flysystem-webdav',
35+
];
36+
}
37+
38+
protected function configureOptions(OptionsResolver $resolver): void
39+
{
40+
$resolver->setRequired('client');
41+
$resolver->setAllowedTypes('client', 'string');
42+
43+
$resolver->setDefault('prefix', '');
44+
$resolver->setAllowedTypes('prefix', 'string');
45+
46+
$resolver->setDefault('visibility_handling', WebDAVAdapter::ON_VISIBILITY_THROW_ERROR);
47+
$resolver->setAllowedTypes('visibility_handling', ['string']);
48+
49+
$resolver->setDefault('manual_copy', false);
50+
$resolver->setAllowedTypes('manual_copy', 'bool');
51+
52+
$resolver->setDefault('manual_move', false);
53+
$resolver->setAllowedTypes('manual_move', 'bool');
54+
}
55+
56+
protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void
57+
{
58+
$definition->setClass(WebDAVAdapter::class);
59+
$definition->setArguments([
60+
new Reference($options['client']),
61+
$options['prefix'],
62+
$options['visibility_handling'],
63+
$options['manual_copy'],
64+
$options['manual_move'],
65+
]);
66+
}
67+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the flysystem-bundle project.
5+
*
6+
* (c) Titouan Galopin <galopintitouan@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\League\FlysystemBundle\Adapter\Builder;
13+
14+
use League\Flysystem\Visibility;
15+
use League\Flysystem\WebDAV\WebDAVAdapter;
16+
use League\FlysystemBundle\Adapter\Builder\WebDAVAdapterDefinitionBuilder;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* @author Kévin Dunglas <kevin@dunglas.dev>
21+
*/
22+
class WebDAVAdapterDefinitionBuilderTest extends TestCase
23+
{
24+
public function createBuilder(): WebDAVAdapterDefinitionBuilder
25+
{
26+
return new WebDAVAdapterDefinitionBuilder();
27+
}
28+
29+
public static function provideValidOptions(): \Generator
30+
{
31+
yield 'minimal' => [[
32+
'client' => 'webdav_client',
33+
]];
34+
35+
yield 'full' => [[
36+
'client' => 'webdav_client',
37+
'prefix' => 'optional/path/prefix',
38+
'visibility_handling' => WebDAVAdapter::ON_VISIBILITY_THROW_ERROR,
39+
'manual_copy' => false,
40+
'manual_move' => false,
41+
]];
42+
}
43+
44+
/**
45+
* @dataProvider provideValidOptions
46+
*/
47+
public function testCreateDefinition(array $options): void
48+
{
49+
$this->assertSame(WebDAVAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass());
50+
}
51+
52+
public function testOptionsBehavior(): void
53+
{
54+
$definition = $this->createBuilder()->createDefinition([
55+
'client' => 'webdav_client',
56+
'prefix' => 'optional/path/prefix',
57+
'visibility_handling' => WebDAVAdapter::ON_VISIBILITY_IGNORE,
58+
'manual_copy' => false,
59+
'manual_move' => false,
60+
], Visibility::PUBLIC);
61+
62+
$this->assertSame(WebDAVAdapter::class, $definition->getClass());
63+
$this->assertSame('webdav_client', (string) $definition->getArgument(0));
64+
$this->assertSame('optional/path/prefix', $definition->getArgument(1));
65+
$this->assertSame(WebDAVAdapter::ON_VISIBILITY_IGNORE, $definition->getArgument(2));
66+
$this->assertFalse($definition->getArgument(3));
67+
$this->assertFalse($definition->getArgument(4));
68+
}
69+
}

0 commit comments

Comments
 (0)