Skip to content

Commit

Permalink
RackspaceCloudFilesAdapter authenticate only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ftassi committed May 13, 2012
1 parent 5c56f06 commit f0a9e5e
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions Storage/Adapter/RackspaceCloudFilesAdapter.php
Expand Up @@ -11,29 +11,33 @@
*/
class RackspaceCloudFilesAdapter implements CDNAdapterInterface
{

/**
*
* @var \CF_Authentication
*/
protected $rackspaceAuthentication;

/**
*
* @var \CF_Connection
*/
protected $rackspaceConnection;

/**
*
* @var string
*/
protected $container;


/**
*
* @var boolean
*/
protected $authenticated = false;

function __construct(\CF_Authentication $rackspaceAuthentication)
{
$this->rackspaceAuthentication = $rackspaceAuthentication;
$this->rackspaceAuthentication->authenticate();
}

/**
Expand All @@ -52,7 +56,7 @@ public function setContainer($container)
{
$this->container = $container;
}

/**
*
* @return \CF_Connection
Expand All @@ -70,15 +74,15 @@ public function setRackspaceConnection(\CF_Connection $rackspaceConnection)
{
$this->rackspaceConnection = $rackspaceConnection;
}

/**
*
* @param string $filename
* @return string
*/
public function getAbsoluteUri($filename)
{

$this->authenticate();
$mediaContainer = $this->rackspaceConnection->get_container($this->container);
$object = $mediaContainer->get_object($filename);
return $object->public_uri();
Expand All @@ -91,20 +95,33 @@ public function getAbsoluteUri($filename)
*/
public function put($filePath, $fileName)
{
$this->authenticate();
$mediaContainer = $this->rackspaceConnection->get_container($this->container);
$object = $mediaContainer->create_object($fileName);
return $object->load_from_filename($filePath);
return $object->load_from_filename($filePath);
}

/**
*
* @param string $fileName
* @return boolean
*/
public function remove($fileName)
{
$this->authenticate();
$mediaContainer = $this->rackspaceConnection->get_container($this->container);
return $mediaContainer->delete_object($fileName);
}

/**
* Authenticave over Rackspace
*/
protected function authenticate()
{
if (!$this->authenticated) {
$this->rackspaceAuthentication->authenticate();
$this->authenticated = true;
}
}

}

0 comments on commit f0a9e5e

Please sign in to comment.