diff --git a/Client/FlysystemClient.php b/Client/FlysystemClient.php new file mode 100644 index 0000000..e5bf114 --- /dev/null +++ b/Client/FlysystemClient.php @@ -0,0 +1,48 @@ +filesystems as $filesystem) { + $filesystem->write(end($fileName), file_get_contents($archive)); + } + } + + /** + * Add a filesystem adapter. + * + * @param FilesystemInterface $filesystem + */ + public function addFilesystem(FilesystemInterface $filesystem) + { + $this->filesystems[] = $filesystem; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'Flysystem'; + } +} diff --git a/DependencyInjection/Compiler/TaggedServicesPass.php b/DependencyInjection/Compiler/TaggedServicesPass.php index 1e65950..69724c7 100644 --- a/DependencyInjection/Compiler/TaggedServicesPass.php +++ b/DependencyInjection/Compiler/TaggedServicesPass.php @@ -82,6 +82,18 @@ public function clientCompilerPass(ContainerBuilder $container) ]); } } + + // If flysystem is set, assign automatically the specified filesystem adapters + if (isset($container->getParameter('dizda_cloud_backup.cloud_storages')['flysystem'])) { + $filesystem = $container->getParameter('dizda_cloud_backup.cloud_storages')['flysystem']['service_name']; + + foreach ($filesystem as $filesystemName) { + $flysystem = $container->getDefinition('dizda.cloudbackup.client.flysystem'); + $flysystem->addMethodCall('addFilesystem', [ + new Reference($filesystemName), + ]); + } + } } /** diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 7c10953..cc8caf6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -90,6 +90,12 @@ public function getConfigTreeBuilder() ->arrayNode('service_name')->prototype('scalar')->end()->isRequired()->requiresAtLeastOneElement()->end() ->end() ->end() + ->arrayNode('flysystem') + ->info('Any flysystem adapter is supported') + ->children() + ->arrayNode('service_name')->prototype('scalar')->end()->isRequired()->requiresAtLeastOneElement()->end() + ->end() + ->end() ->end() ->end() ->arrayNode('databases') diff --git a/DependencyInjection/DizdaCloudBackupExtension.php b/DependencyInjection/DizdaCloudBackupExtension.php index c9d01c9..f01d6de 100644 --- a/DependencyInjection/DizdaCloudBackupExtension.php +++ b/DependencyInjection/DizdaCloudBackupExtension.php @@ -62,6 +62,13 @@ public function load(array $configs, ContainerBuilder $container) } } + /* Verify that we have Flysystem library if activated in the config */ + if (isset($config['cloud_storages']['flysystem'])) { + if (!class_exists('Oneup\\FlysystemBundle\\OneupFlysystemBundle')) { + throw new \LogicException('You need to install "oneup/flysystem-bundle" library to use it as a cloud storage provider.'); + } + } + // When we launch functional tests, there is no DB specified, so skip it if empty if (!$container->hasParameter('dizda_cloud_backup.databases')) { $container->setParameter('dizda_cloud_backup.databases', array()); diff --git a/README.md b/README.md index 5c77e7b..5f8c003 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,17 @@ Databases supported : Cloud services supported : * __Dropbox__ ([Dropbox SDK](https://github.com/dropbox/dropbox-sdk-php)) * __CloudApp__ (thanks to [CloudAPP-API-PHP-wrapper](https://github.com/matthiasplappert/CloudApp-API-PHP-wrapper)) -* __Amazon S3__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle)) +* __Amazon S3__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle) or [OneupFlysystemBundle](https://github.com/1up-lab/OneupFlysystemBundle)) * __Google Drive__ (thanks to [HappyrGoogleSiteAuthenticatorBundle](https://github.com/Happyr/GoogleSiteAuthenticatorBundle)) +* __Rackspace__ (through [OneupFlysystemBundle](https://github.com/1up-lab/OneupFlysystemBundle)) But also : -* __Local__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle)) -* __FTP__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle)) -* __sFTP__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle)) -* __GridFS__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle)) +* __Local__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle) or [OneupFlysystemBundle](https://github.com/1up-lab/OneupFlysystemBundle)) +* __FTP__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle) or [OneupFlysystemBundle](https://github.com/1up-lab/OneupFlysystemBundle)) +* __sFTP__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle) or [OneupFlysystemBundle](https://github.com/1up-lab/OneupFlysystemBundle)) +* __GridFS__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle) or [OneupFlysystemBundle](https://github.com/1up-lab/OneupFlysystemBundle)) * __MogileFS__ (through [KnpGaufretteBundle](https://github.com/KnpLabs/KnpGaufretteBundle)) +* __WebDAV__ (thourgh [OneupFlysystemBundle](https://github.com/1up-lab/OneupFlysystemBundle)) are supported :-) @@ -104,6 +106,9 @@ dizda_cloud_backup: service_name: # Gaufrette filesystem(s) service name - local_backup_filesystem - amazon_backup_filesystem + flysystem: + service_name: # Flysystem filesystem(s) service name + - oneup_flysystem.acme_filesystem google_drive: token_name: ~ # Required remote_path: ~ # Not required, default "/", but you can use path like "/Accounts/backups/" diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 0d6cd16..fd4eaed 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -52,6 +52,11 @@ services: tags: - { name: dizda.cloudbackup.client } + dizda.cloudbackup.client.flysystem: + class: Dizda\CloudBackupBundle\Client\FlysystemClient + tags: + - { name: dizda.cloudbackup.client } + dizda.cloudbackup.database.mongodb: class: Dizda\CloudBackupBundle\Database\MongoDB arguments: diff --git a/composer.json b/composer.json index e6d3b14..d52c095 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "happyr/google-site-authenticator-bundle": "To enable upload dumps on google drive.", "dropbox/dropbox-sdk": "To enable upload to Dropbox", "knplabs/knp-gaufrette-bundle": "To use Gaufrette as a cloud storage", + "oneup/flysystem-bundle": "To use Flysystem as a cloud storage", "jongotlin/deadmanssnitch-bundle": "To report your successful backups to deadmanssnitch.com" },