Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #99 from marcaube/flysystem
Browse files Browse the repository at this point in the history
Add support for league/flysystem adapters using oneup/flysystem-bundle
  • Loading branch information
dizda committed May 23, 2016
2 parents 26c7e9c + 9429764 commit 4a46434
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 5 deletions.
48 changes: 48 additions & 0 deletions Client/FlysystemClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace Dizda\CloudBackupBundle\Client;

use League\Flysystem\FilesystemInterface;

/**
* Client for Flysystem adapters.
*
* @author Marc Aubé
*/
class FlysystemClient implements ClientInterface
{
/**
* @var FilesystemInterface[]
*/
private $filesystems;

/**
* {@inheritdoc}
*/
public function upload($archive)
{
$fileName = explode('/', $archive);

/** @var FilesystemInterface $filesystem */
foreach ($this->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';
}
}
12 changes: 12 additions & 0 deletions DependencyInjection/Compiler/TaggedServicesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions DependencyInjection/DizdaCloudBackupExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :-)

Expand Down Expand Up @@ -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/"
Expand Down
5 changes: 5 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},

Expand Down

0 comments on commit 4a46434

Please sign in to comment.