Decouple Billing and S3 cloud storage stuff from Zend

This commit is contained in:
Albert Santoni 2015-01-26 13:10:10 -05:00
parent 49667e3d2d
commit dbba5a7427
11 changed files with 416 additions and 344 deletions

View file

@ -1,7 +1,7 @@
<?php
require_once 'StorageBackend.php';
require_once 'BillingController.php';
require_once 'Billing.php';
use Aws\S3\S3Client;
@ -68,13 +68,12 @@ class Amazon_S3 extends StorageBackend
{
$this->s3Client->deleteMatchingObjects(
$bucket = $this->getBucket(),
$prefix = self::getAmazonS3FilePrefix());
$prefix = $this->getFilePrefix());
}
public static function getAmazonS3FilePrefix()
public function getFilePrefix()
{
$clientCurrentAirtimeProduct = BillingController::getClientCurrentAirtimeProduct();
$clientCurrentAirtimeProduct = Billing::getClientCurrentAirtimeProduct();
$hostingId = $clientCurrentAirtimeProduct["id"];
return substr($hostingId, -2)."/".$hostingId;
}

View file

@ -0,0 +1,41 @@
<?php
class FileStorageBackend extends StorageBackend
{
//Stub class
public function FileStorageBackend()
{
}
public function getAbsoluteFilePath($resourceId)
{
//TODO
return $resourceId;
}
public function getSignedURL($resourceId)
{
return "";
}
public function getFileSize($resourceId)
{
//TODO
return filesize($resourceId);
}
public function deletePhysicalFile($resourceId)
{
//TODO
}
public function deleteAllCloudFileObjects()
{
return "";
}
public function getFilePrefix()
{
return "";
}
}

View file

@ -1,7 +1,8 @@
<?php
require_once 'StorageBackend.php';
require_once 'Amazon_S3.php';
require_once 'FileStorageBackend.php';
require_once 'Amazon_S3StorageBackend.php';
/**
*
@ -23,7 +24,13 @@ class ProxyStorageBackend extends StorageBackend
//The storage backend in the airtime.conf directly corresponds to
//the name of the class that implements it (eg. Amazon_S3), so we
//can easily create the right backend object dynamically:
$this->storageBackend = new $storageBackend($CC_CONFIG[$storageBackend]);
if ($storageBackend == "Amazon_S3") {
$this->storageBackend = new Amazon_S3StorageBackend($CC_CONFIG["Amazon_S3"]);
} else if ($storageBackend == "file") {
$this->storageBackend = new FileStorageBackend();
} else {
$this->storageBackend = new $storageBackend($CC_CONFIG[$storageBackend]);
}
}
public function getAbsoluteFilePath($resourceId)
@ -51,4 +58,8 @@ class ProxyStorageBackend extends StorageBackend
$this->storageBackend->deleteAllCloudFileObjects();
}
public function getFilePrefix()
{
$this->storageBackend->getFilePrefix();
}
}

View file

@ -26,7 +26,10 @@ abstract class StorageBackend
/** Deletes all objects (files) stored on the cloud service. To be used
* for station termination */
abstract public function deleteAllCloudFileObjects();
/** Get a prefix for the file (which is usually treated like a directory in the cloud) */
abstract public function getFilePrefix();
protected function getBucket()
{
return $this->bucket;