Skip to content

Commit

Permalink
[FIX] Reduced complexity of ConfigForm.php
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhowland committed Feb 5, 2019
1 parent b5dd62a commit a528536
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion config/module.ini
Expand Up @@ -4,7 +4,7 @@ description = "Omeka S module for storing items in the cloud storage of your ch
tags = "amazon s3, azure, digital ocean, dropbox, google, rackspace, scaleway, storage, file system"
author = "Jared Howland"
author_link = "https://www.jaredhowland.com"
version = "0.3.0"
version = "0.4.0"
configurable = true
module_link = "https://github.com/HBLL-Collection-Development/omeka-s-any-cloud"
support_link = "https://github.com/HBLL-Collection-Development/omeka-s-any-cloud/issues"
Expand Down
65 changes: 42 additions & 23 deletions src/Form/ConfigForm.php
Expand Up @@ -17,8 +17,24 @@ public function setSettings($settings)

public function init()
{
// CSRF
///////
$this->addCsrf();
$this->addAdapter();
$this->addAws();
$this->addAzure();
$this->addGoogle();
$this->addDigitalOcean();
$this->addScaleway();
$this->addRackspace();
$this->addDropbox();
}

protected function getSetting($name)
{
return $this->settings->get($name);
}

private function addCsrf()
{
$this->add([
'type' => Element\Csrf::class,
'name' => 'csrf',
Expand All @@ -28,9 +44,10 @@ public function init()
],
],
]);
}

// ADAPTER
//////////
private function addAdapter()
{
$this->add([
'name' => 'anycloud_adapter',
'type' => Fieldset::class,
Expand Down Expand Up @@ -62,9 +79,10 @@ public function init()
'id' => 'adapter',
],
]);
}

// AMAZON S3
////////////
private function addAws()
{
$this->add([
'name' => 'anycloud_aws',
'type' => Fieldset::class,
Expand Down Expand Up @@ -128,9 +146,10 @@ public function init()
'id' => 'aws_endpoint',
],
]);
}

// AZURE
////////
private function addAzure()
{
$this->add([
'name' => 'anycloud_azure',
'type' => Fieldset::class,
Expand Down Expand Up @@ -183,9 +202,10 @@ public function init()
'id' => 'azure_endpoint',
],
]);
}

// GOOGLE CLOUD
///////////////
private function addGoogle()
{
$this->add([
'name' => 'anycloud_google',
'type' => Fieldset::class,
Expand Down Expand Up @@ -241,9 +261,10 @@ public function init()
'id' => 'google_storage_uri',
],
]);
}

// DIGITALOCEAN SPACES
//////////////////////
private function addDigitalOcean()
{
$this->add([
'name' => 'anycloud_digital_ocean',
'type' => Fieldset::class,
Expand Down Expand Up @@ -305,9 +326,10 @@ public function init()
'id' => 'digital_ocean_endpoint',
],
]);
}

// SCALEWAY OBJECT STORAGE
//////////////////////////
private function addScaleway()
{
$this->add([
'name' => 'anycloud_scaleway',
'type' => Fieldset::class,
Expand Down Expand Up @@ -369,9 +391,10 @@ public function init()
'id' => 'scaleway_endpoint',
],
]);
}

// RACKSPACE FILES
//////////////////
private function addRackspace()
{
$this->add([
'name' => 'anycloud_rackspace',
'type' => Fieldset::class,
Expand Down Expand Up @@ -434,9 +457,10 @@ public function init()
'id' => 'rackspace_region',
],
]);
}

// DROPBOX
//////////
private function addDropbox()
{
$this->add([
'name' => 'anycloud_dropbox',
'type' => Fieldset::class,
Expand All @@ -459,9 +483,4 @@ public function init()
],
]);
}

protected function getSetting($name)
{
return $this->settings->get($name);
}
}
11 changes: 5 additions & 6 deletions src/Service/File/Store/AnyCloudFactory.php
Expand Up @@ -13,12 +13,12 @@ class AnyCloudFactory implements FactoryInterface
{
use CommonTrait;

const AWS_BASED = ['aws', 'digital_ocean', 'scaleway'];
protected $options;
private $filesystem;
private $uri;
private $tempUri;
private $adapter;
const AWS_BASED = ['aws', 'digital_ocean', 'scaleway'];

/**
* @param ContainerInterface $serviceLocator
Expand All @@ -41,15 +41,14 @@ public function __invoke(ContainerInterface $serviceLocator, $requestedName, arr
*/
private function createFilesystem()
{
if(in_array($this->getAdapter(), self::AWS_BASED)) {
$adapter = new Adapter\AwsAdapter;
if (in_array($this->getAdapter(), self::AWS_BASED)) {
$adapter = new Adapter\AwsAdapter;
$this->adapter = $adapter->createAdapter($this->options);
} else {
$adapter = new Adapter\AzureAdapter;
$adapter = new Adapter\AzureAdapter;
$this->adapter = $adapter->createAdapter($this->options);
$this->tempUri = $adapter->getUri();
}

$this->filesystem = new Filesystem($this->adapter);
}

Expand All @@ -58,7 +57,7 @@ private function createFilesystem()
*/
private function createUri()
{
if(in_array($this->getAdapter(), self::AWS_BASED)) {
if (in_array($this->getAdapter(), self::AWS_BASED)) {
$this->uri = dirname($this->filesystem->getAdapter()->getClient()->getObjectUrl($this->getSetting('bucket'),
$this->getSetting('key')));
} else {
Expand Down

0 comments on commit a528536

Please sign in to comment.