File indexing completed on 2025-01-26 05:25:27

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Service_Rackspace
0017  * @subpackage Files
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  */
0021 
0022 // require_once 'Zend/Service/Rackspace/Files/Container.php';
0023 // require_once 'Zend/Service/Rackspace/Files.php';
0024 
0025 /**
0026  * List of servers retrived from the Rackspace web service
0027  *
0028  * @uses       ArrayAccess
0029  * @uses       Countable
0030  * @uses       Iterator
0031  * @uses       OutOfBoundsException
0032  * @uses       Zend_Service_Rackspace_Files_Container
0033  * @category   Zend
0034  * @package    Zend_Service_Rackspace
0035  * @subpackage Files
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Service_Rackspace_Files_ContainerList implements Countable, Iterator, ArrayAccess
0040 {
0041     /**
0042      * @var array Array of Zend_Service_Rackspace_Files_Container
0043      */
0044     protected $objects = array();
0045     /**
0046      * @var int Iterator key
0047      */
0048     protected $iteratorKey = 0;
0049     /**
0050      * @var RackspaceFiles
0051      */
0052     protected $service;
0053     /**
0054      * Constructor
0055      *
0056      * @param  array $list
0057      * @return boolean
0058      */
0059     public function __construct($service,$list = array())
0060     {
0061         if (!($service instanceof Zend_Service_Rackspace_Files ) || !is_array($list)) {
0062             // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0063             throw new Zend_Service_Rackspace_Files_Exception("You must pass a Zend_Service_Rackspace_Files_Exception object and an array");
0064         }
0065         $this->service= $service;
0066         $this->_constructFromArray($list);
0067     }
0068     /**
0069      * Transforms the Array to array of container
0070      *
0071      * @param  array $list
0072      * @return void
0073      */
0074     private function _constructFromArray(array $list)
0075     {
0076         foreach ($list as $container) {
0077             $this->_addObject(new Zend_Service_Rackspace_Files_Container($this->service,$container));
0078         }
0079     }
0080     /**
0081      * Add an object
0082      *
0083      * @param  Zend_Service_Rackspace_Files_Container $obj
0084      * @return Zend_Service_Rackspace_Files_ContainerList
0085      */
0086     protected function _addObject (Zend_Service_Rackspace_Files_Container $obj)
0087     {
0088         $this->objects[] = $obj;
0089         return $this;
0090     }
0091     /**
0092      * Return number of servers
0093      *
0094      * Implement Countable::count()
0095      *
0096      * @return int
0097      */
0098     public function count()
0099     {
0100         return count($this->objects);
0101     }
0102     /**
0103      * Return the current element
0104      *
0105      * Implement Iterator::current()
0106      *
0107      * @return Zend_Service_Rackspace_Files_Container
0108      */
0109     public function current()
0110     {
0111         return $this->objects[$this->iteratorKey];
0112     }
0113     /**
0114      * Return the key of the current element
0115      *
0116      * Implement Iterator::key()
0117      *
0118      * @return int
0119      */
0120     public function key()
0121     {
0122         return $this->iteratorKey;
0123     }
0124     /**
0125      * Move forward to next element
0126      *
0127      * Implement Iterator::next()
0128      *
0129      * @return void
0130      */
0131     public function next()
0132     {
0133         $this->iteratorKey += 1;
0134     }
0135     /**
0136      * Rewind the Iterator to the first element
0137      *
0138      * Implement Iterator::rewind()
0139      *
0140      * @return void
0141      */
0142     public function rewind()
0143     {
0144         $this->iteratorKey = 0;
0145     }
0146     /**
0147      * Check if there is a current element after calls to rewind() or next()
0148      *
0149      * Implement Iterator::valid()
0150      *
0151      * @return bool
0152      */
0153     public function valid()
0154     {
0155         $numItems = $this->count();
0156         if ($numItems > 0 && $this->iteratorKey < $numItems) {
0157             return true;
0158         } else {
0159             return false;
0160         }
0161     }
0162     /**
0163      * Whether the offset exists
0164      *
0165      * Implement ArrayAccess::offsetExists()
0166      *
0167      * @param   int     $offset
0168      * @return  bool
0169      */
0170     public function offsetExists($offset)
0171     {
0172         return ($offset < $this->count());
0173     }
0174     /**
0175      * Return value at given offset
0176      *
0177      * Implement ArrayAccess::offsetGet()
0178      *
0179      * @param   int     $offset
0180      * @throws  Zend_Service_Rackspace_Files_Exception
0181      * @return  Zend_Service_Rackspace_Files_Container
0182      */
0183     public function offsetGet($offset)
0184     {
0185         if ($this->offsetExists($offset)) {
0186             return $this->objects[$offset];
0187         } else {
0188             // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0189             throw new Zend_Service_Rackspace_Files_Exception('Illegal index');
0190         }
0191     }
0192 
0193     /**
0194      * Throws exception because all values are read-only
0195      *
0196      * Implement ArrayAccess::offsetSet()
0197      *
0198      * @param   int     $offset
0199      * @param   string  $value
0200      * @throws  Zend_Service_Rackspace_Files_Exception
0201      */
0202     public function offsetSet($offset, $value)
0203     {
0204         // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0205         throw new Zend_Service_Rackspace_Files_Exception('You are trying to set read-only property');
0206     }
0207 
0208     /**
0209      * Throws exception because all values are read-only
0210      *
0211      * Implement ArrayAccess::offsetUnset()
0212      *
0213      * @param   int     $offset
0214      * @throws  Zend_Service_Rackspace_Files_Exception
0215      */
0216     public function offsetUnset($offset)
0217     {
0218         // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0219         throw new Zend_Service_Rackspace_Files_Exception('You are trying to unset read-only property');
0220     }
0221 }