-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for the WebDAV adapter
- Loading branch information
Showing
6 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# WebDAV | ||
|
||
Flysystem is able to [interact with WebDAV servers](https://flysystem.thephpleague.com/docs/adapter/webdav/). | ||
To configure this bundle for such usage, you can rely on adapters in the same way you would | ||
for other storages. | ||
|
||
### Installation | ||
|
||
``` | ||
composer require league/flysystem-webdav | ||
``` | ||
|
||
### Usage | ||
|
||
```yaml | ||
# config/packages/flysystem.yaml | ||
|
||
services: | ||
webdav_client: | ||
class: Sabre\DAV\Client | ||
arguments: | ||
- { baseUri: 'https://webdav.example.com/', userName: 'your_user', password: 'superSecret1234' } | ||
|
||
flysystem: | ||
storages: | ||
webdav.storage: | ||
adapter: 'webdav' | ||
options: | ||
client: 'webdav_client' | ||
prefix: 'optional/path/prefix' | ||
visibility_handling: !php/const \League\Flysystem\WebDAV\WebDAVAdapter::ON_VISIBILITY_THROW_ERROR # throw | ||
manual_copy: false | ||
manual_move: false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the flysystem-bundle project. | ||
* | ||
* (c) Titouan Galopin <galopintitouan@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace League\FlysystemBundle\Adapter\Builder; | ||
|
||
use League\Flysystem\WebDAV\WebDAVAdapter; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Kévin Dunglas <kevin@dunglas.dev> | ||
* | ||
* @internal | ||
*/ | ||
final class WebDAVAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'webdav'; | ||
} | ||
|
||
protected function getRequiredPackages(): array | ||
{ | ||
return [ | ||
WebDAVAdapter::class => 'league/flysystem-webdav', | ||
]; | ||
} | ||
|
||
protected function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setRequired('client'); | ||
$resolver->setAllowedTypes('client', 'string'); | ||
|
||
$resolver->setDefault('prefix', ''); | ||
$resolver->setAllowedTypes('prefix', 'string'); | ||
|
||
$resolver->setDefault('visibility_handling', WebDAVAdapter::ON_VISIBILITY_THROW_ERROR); | ||
$resolver->setAllowedTypes('visibility_handling', ['string']); | ||
|
||
$resolver->setDefault('manual_copy', false); | ||
$resolver->setAllowedTypes('manual_copy', 'bool'); | ||
|
||
$resolver->setDefault('manual_move', false); | ||
$resolver->setAllowedTypes('manual_move', 'bool'); | ||
} | ||
|
||
protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void | ||
{ | ||
$definition->setClass(WebDAVAdapter::class); | ||
$definition->setArguments([ | ||
new Reference($options['client']), | ||
$options['prefix'], | ||
$options['visibility_handling'], | ||
$options['manual_copy'], | ||
$options['manual_move'], | ||
]); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
tests/Adapter/Builder/WebDAVAdapterDefinitionBuilderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the flysystem-bundle project. | ||
* | ||
* (c) Titouan Galopin <galopintitouan@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\League\FlysystemBundle\Adapter\Builder; | ||
|
||
use League\Flysystem\Visibility; | ||
use League\Flysystem\WebDAV\WebDAVAdapter; | ||
use League\FlysystemBundle\Adapter\Builder\WebDAVAdapterDefinitionBuilder; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @author Kévin Dunglas <kevin@dunglas.dev> | ||
*/ | ||
class WebDAVAdapterDefinitionBuilderTest extends TestCase | ||
{ | ||
public function createBuilder(): WebDAVAdapterDefinitionBuilder | ||
{ | ||
return new WebDAVAdapterDefinitionBuilder(); | ||
} | ||
|
||
public static function provideValidOptions(): \Generator | ||
{ | ||
yield 'minimal' => [[ | ||
'client' => 'webdav_client', | ||
]]; | ||
|
||
yield 'full' => [[ | ||
'client' => 'webdav_client', | ||
'prefix' => 'optional/path/prefix', | ||
'visibility_handling' => WebDAVAdapter::ON_VISIBILITY_THROW_ERROR, | ||
'manual_copy' => false, | ||
'manual_move' => false, | ||
]]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideValidOptions | ||
*/ | ||
public function testCreateDefinition(array $options): void | ||
{ | ||
$this->assertSame(WebDAVAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass()); | ||
} | ||
|
||
public function testOptionsBehavior(): void | ||
{ | ||
$definition = $this->createBuilder()->createDefinition([ | ||
'client' => 'webdav_client', | ||
'prefix' => 'optional/path/prefix', | ||
'visibility_handling' => WebDAVAdapter::ON_VISIBILITY_IGNORE, | ||
'manual_copy' => false, | ||
'manual_move' => false, | ||
], Visibility::PUBLIC); | ||
|
||
$this->assertSame(WebDAVAdapter::class, $definition->getClass()); | ||
$this->assertSame('webdav_client', (string) $definition->getArgument(0)); | ||
$this->assertSame('optional/path/prefix', $definition->getArgument(1)); | ||
$this->assertSame(WebDAVAdapter::ON_VISIBILITY_IGNORE, $definition->getArgument(2)); | ||
$this->assertFalse($definition->getArgument(3)); | ||
$this->assertFalse($definition->getArgument(4)); | ||
} | ||
} |