Skip to content

Commit

Permalink
Review of code for Zend\Service\Rackspace
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and weierophinney committed Jul 20, 2011
1 parent 9c12ad2 commit 5eddebb
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 322 deletions.
179 changes: 87 additions & 92 deletions library/Zend/Service/Rackspace/Files.php

Large diffs are not rendered by default.

199 changes: 104 additions & 95 deletions library/Zend/Service/Rackspace/Files/Container.php

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions library/Zend/Service/Rackspace/Files/ContainerList.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ class ContainerList implements \Countable, \Iterator, \ArrayAccess
/**
* @var array Array of Zend\Service\GoGrid\Object
*/
protected $_objects = array();
protected $objects = array();
/**
* @var int Iterator key
*/
protected $_iteratorKey = 0;
protected $iteratorKey = 0;
/**
* @var RackspaceFiles
*/
protected $_service;
protected $service;
/**
* __construct()
* Constructor
*
* @param array $list
* @return boolean
Expand All @@ -69,7 +69,7 @@ public function __construct(RackspaceFiles $service,$list = array())
if (!($service instanceof RackspaceFiles) || !is_array($list)) {
throw new InvalidArgumentException("You must pass a RackspaceFiles object and an array");
}
$this->_service= $service;
$this->service= $service;
$this->_constructFromArray($list);
}
/**
Expand All @@ -81,7 +81,7 @@ public function __construct(RackspaceFiles $service,$list = array())
private function _constructFromArray(array $list)
{
foreach ($list as $container) {
$this->_addObject(new Container($this->_service,$container));
$this->_addObject(new Container($this->service,$container));
}
}
/**
Expand All @@ -92,7 +92,7 @@ private function _constructFromArray(array $list)
*/
protected function _addObject (Container $obj)
{
$this->_objects[] = $obj;
$this->objects[] = $obj;
return $this;
}
/**
Expand All @@ -104,7 +104,7 @@ protected function _addObject (Container $obj)
*/
public function count()
{
return count($this->_objects);
return count($this->objects);
}
/**
* Return the current element
Expand All @@ -115,7 +115,7 @@ public function count()
*/
public function current()
{
return $this->_objects[$this->_iteratorKey];
return $this->objects[$this->iteratorKey];
}
/**
* Return the key of the current element
Expand All @@ -126,7 +126,7 @@ public function current()
*/
public function key()
{
return $this->_iteratorKey;
return $this->iteratorKey;
}
/**
* Move forward to next element
Expand All @@ -137,7 +137,7 @@ public function key()
*/
public function next()
{
$this->_iteratorKey += 1;
$this->iteratorKey += 1;
}
/**
* Rewind the Iterator to the first element
Expand All @@ -148,7 +148,7 @@ public function next()
*/
public function rewind()
{
$this->_iteratorKey = 0;
$this->iteratorKey = 0;
}
/**
* Check if there is a current element after calls to rewind() or next()
Expand All @@ -160,7 +160,7 @@ public function rewind()
public function valid()
{
$numItems = $this->count();
if ($numItems > 0 && $this->_iteratorKey < $numItems) {
if ($numItems > 0 && $this->iteratorKey < $numItems) {
return true;
} else {
return false;
Expand Down Expand Up @@ -190,7 +190,7 @@ public function offsetExists($offset)
public function offsetGet($offset)
{
if ($this->offsetExists($offset)) {
return $this->_objects[$offset];
return $this->objects[$offset];
} else {
throw new OutOfBoundsException('Illegal index');
}
Expand Down
132 changes: 78 additions & 54 deletions library/Zend/Service/Rackspace/Files/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,68 @@

class Object
{
/**
* The service that has created the object
*
* @var Zend\Service\Rackspace\Files
*/
protected $service;
/**
* Name of the object
*
* @var string
*/
protected $_name;
protected $name;
/**
* MD5 value of the object's content
*
* @var string
*/
protected $_hash;
protected $hash;
/**
* Size in bytes of the object's content
*
* @var integer
*/
protected $_size;
protected $size;
/**
* Content type of the object's content
*
* @var <type>
* @var string
*/
protected $_contentType;
protected $contentType;
/**
* Date of the last modified of the object
*
* @var string
*/
protected $_lastModified;
protected $lastModified;
/**
* Object content
*
* @var string
*/
protected $_file;
protected $file;
/**
* Name of the container where the object is stored
*
* @var string
*/
protected $_container;
protected $container;
/**
* If it's true means we called the getMetadata API
*
* @var boolean
*/
private $_getMetadata = false;
protected $getMetadata = false;
/**
* Metadata
*
* @var array
*/
protected $metadata= array();
/**
* __construct()
* Constructor
*
* You must pass the RackspaceFiles object of the caller and an associative
* array with the keys "name", "container", "hash", "bytes", "content_type",
Expand Down Expand Up @@ -114,72 +126,79 @@ public function __construct(RackspaceFiles $service,$data)
if (!array_key_exists('last_modified', $data)) {
throw new InvalidArgumentException("You must pass the last modified data of the object in the array (last_modified)");
}
$this->_name= $data['name'];
$this->_container= $data['container'];
$this->_hash= $data['hash'];
$this->_size= $data['bytes'];
$this->_contentType= $data['content_type'];
$this->_lastModified= $data['last_modified'];
$this->name= $data['name'];
$this->container= $data['container'];
$this->hash= $data['hash'];
$this->size= $data['bytes'];
$this->contentType= $data['content_type'];
$this->lastModified= $data['last_modified'];
if (!empty($data['file'])) {
$this->_file= $data['file'];
$this->file= $data['file'];
}
$this->_service= $service;
$this->service= $service;
}
/**
* Get name
*
* @return string
*/
public function getName() {
return $this->_name;
public function getName()
{
return $this->name;
}
/**
* Get the name of the container
*
* @return string
*/
public function getContainer() {
return $this->_container;
public function getContainer()
{
return $this->container;
}
/**
* Get the MD5 of the object's content
*
* @return string
*/
public function getHash() {
return $this->_hash;
public function getHash()
{
return $this->hash;
}
/**
* Get the size of the object's content
*
* @return integer
*/
public function getSize() {
return $this->_size;
public function getSize()
{
return $this->size;
}
/**
* Get the content type of the object's content
*
* @return string
*/
public function getContentType() {
return $this->_contentType;
public function getContentType()
{
return $this->contentType;
}
/**
* Get the data of the last modified of the object
*
* @return string
*/
public function getLastModified() {
return $this->_lastModified;
public function getLastModified()
{
return $this->lastModified;
}
/**
* Get the content of the object
*
* @return string
*/
public function getFile() {
return $this->_file;
public function getFile()
{
return $this->file;
}
/**
* Get the metadata of the object
Expand All @@ -188,24 +207,25 @@ public function getFile() {
* @param string $key
* @return string|array
*/
public function getMetadata($key=null) {
if (empty($this->_metadata) && (!$this->_getMetadata)) {
$result= $this->_service->getMetadataObject($this->_container,$this->_name);
public function getMetadata($key=null)
{
if (empty($this->metadata) && (!$this->getMetadata)) {
$result= $this->service->getMetadataObject($this->container,$this->name);
if (!empty($result)) {
$this->_hash= $data['hash'];
$this->_size= $data['bytes'];
$this->_contentType= $data['content_type'];
$this->_lastModified= $data['last_modified'];
$this->hash= $data['hash'];
$this->size= $data['bytes'];
$this->contentType= $data['content_type'];
$this->lastModified= $data['last_modified'];
if (!empty($result['metadata'])) {
$this->_metadata= $result['metadata'];
$this->metadata= $result['metadata'];
}
}
$this->_getMetadata= true;
$this->getMetadata= true;
}
if (!empty($this->_metadata[$key])) {
return $this->_metadata[$key];
if (!empty($this->metadata[$key])) {
return $this->metadata[$key];
}
return $this->_metadata;
return $this->metadata;
}
/**
* Set the metadata value
Expand All @@ -214,8 +234,9 @@ public function getMetadata($key=null) {
* @param array $metadata
* @return boolean
*/
public function setMetadata($metadata) {
return $this->_service->setMetadataObject($this->_container,$this->_name,$metadata);
public function setMetadata($metadata)
{
return $this->service->setMetadataObject($this->container,$this->name,$metadata);
}
/**
* Copy the object to another container
Expand All @@ -228,19 +249,21 @@ public function setMetadata($metadata) {
* @param string $content_type
* @return boolean
*/
public function copyTo($container_dest,$name_dest,$metadata=array(),$content_type=null) {
return $this->_service->copyObject($this->_container,$this->_name,$container_dest,$name_dest,$metadata,$content_type);
public function copyTo($container_dest,$name_dest,$metadata=array(),$content_type=null)
{
return $this->service->copyObject($this->container,$this->name,$container_dest,$name_dest,$metadata,$content_type);
}
/**
* Get the CDN URL of the object
*
* @return string
*/
public function getCdnUrl() {
$result= $this->_service->getInfoCdn($this->_container);
public function getCdnUrl()
{
$result= $this->service->getInfoCdn($this->container);
if ($result!==false) {
if ($result['cdn_enabled']) {
return $result['cdn_uri'].'/'.$this->_name;
return $result['cdn_uri'].'/'.$this->name;
}
}
return false;
Expand All @@ -250,11 +273,12 @@ public function getCdnUrl() {
*
* @return string
*/
public function getCdnUrlSsl() {
$result= $this->_service->getInfoCdn($this->_container);
public function getCdnUrlSsl()
{
$result= $this->service->getInfoCdn($this->container);
if ($result!==false) {
if ($result['cdn_enabled']) {
return $result['cdn_uri_ssl'].'/'.$this->_name;
return $result['cdn_uri_ssl'].'/'.$this->name;
}
}
return false;
Expand Down
Loading

0 comments on commit 5eddebb

Please sign in to comment.