File indexing completed on 2024-06-16 05:29:54

0001 <?php
0002 /**
0003  * @category   Zend
0004  * @package    Zend_Cloud
0005  * @subpackage Infrastructure
0006  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0007  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0008  */
0009 
0010 /**
0011  * Instance of an infrastructure service
0012  * 
0013  * @package    Zend_Cloud
0014  * @subpackage Infrastructure
0015  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0016  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0017  */
0018 class Zend_Cloud_Infrastructure_Image 
0019 {
0020     const IMAGE_ID           = 'imageId';
0021     const IMAGE_OWNERID      = 'ownerId';
0022     const IMAGE_NAME         = 'name';
0023     const IMAGE_DESCRIPTION  = 'description';
0024     const IMAGE_PLATFORM     = 'platform';
0025     const IMAGE_ARCHITECTURE = 'architecture';
0026     const ARCH_32BIT         = 'i386';
0027     const ARCH_64BIT         = 'x86_64';
0028     const IMAGE_WINDOWS      = 'windows';
0029     const IMAGE_LINUX        = 'linux';
0030 
0031     /**
0032      * Image's attributes
0033      * 
0034      * @var array
0035      */
0036     protected $attributes = array();
0037 
0038     /**
0039      * The Image adapter (if exists)
0040      * 
0041      * @var object
0042      */
0043     protected $adapter;
0044 
0045     /**
0046      * Required attributes
0047      * 
0048      * @var array
0049      */
0050     protected $attributeRequired = array(
0051         self::IMAGE_ID, 
0052         self::IMAGE_DESCRIPTION, 
0053         self::IMAGE_PLATFORM, 
0054         self::IMAGE_ARCHITECTURE,
0055     );
0056 
0057     /**
0058      * Constructor
0059      * 
0060      * @param array $data
0061      * @param object $adapter 
0062      */
0063     public function __construct($data, $adapter = null) 
0064     {
0065         if (is_object($data)) {
0066             if (method_exists($data, 'toArray')) {
0067                 $data= $data->toArray();
0068             } elseif ($data instanceof Traversable) {
0069                 $data = iterator_to_array($data);
0070             }
0071         }
0072         
0073         if (empty($data) || !is_array($data)) {
0074             // require_once 'Zend/Cloud/Infrastructure/Exception.php';
0075             throw new Zend_Cloud_Infrastructure_Exception('You must pass an array of parameters');
0076         }
0077 
0078         foreach ($this->attributeRequired as $key) {
0079             if (empty($data[$key])) {
0080                 // require_once 'Zend/Cloud/Infrastructure/Exception.php';
0081                 throw new Zend_Cloud_Infrastructure_Exception(sprintf(
0082                     'The param "%s" is a required parameter for class %s',
0083                     $key,
0084                     __CLASS__
0085                 ));
0086             }
0087         }
0088 
0089         $this->attributes = $data;
0090         $this->adapter    = $adapter;
0091     }
0092 
0093     /**
0094      * Get Attribute with a specific key
0095      *
0096      * @param array $data
0097      * @return misc|boolean
0098      */
0099     public function getAttribute($key) 
0100     {
0101         if (!empty($this->attributes[$key])) {
0102             return $this->attributes[$key];
0103         }
0104         return false;
0105     }
0106 
0107     /**
0108      * Get all the attributes
0109      * 
0110      * @return array
0111      */
0112     public function getAttributes()
0113     {
0114         return $this->attributes;
0115     }
0116 
0117     /**
0118      * Get the image ID
0119      * 
0120      * @return string
0121      */
0122     public function getId()
0123     {
0124         return $this->attributes[self::IMAGE_ID];
0125     }
0126 
0127     /**
0128      * Get the Owner ID
0129      * 
0130      * @return string
0131      */
0132     public function getOwnerId()
0133     {
0134         return $this->attributes[self::IMAGE_OWNERID];
0135     }
0136 
0137     /**
0138      * Get the name
0139      * 
0140      * @return string 
0141      */
0142     public function getName()
0143     {
0144         return $this->attributes[self::IMAGE_NAME];
0145     }
0146 
0147     /**
0148      * Get the description
0149      * 
0150      * @return string 
0151      */
0152     public function getDescription()
0153     {
0154         return $this->attributes[self::IMAGE_DESCRIPTION];
0155     }
0156 
0157     /**
0158      * Get the platform
0159      * 
0160      * @return string 
0161      */
0162     public function getPlatform()
0163     {
0164         return $this->attributes[self::IMAGE_PLATFORM];
0165     }
0166 
0167     /**
0168      * Get the architecture
0169      * 
0170      * @return string 
0171      */
0172     public function getArchitecture()
0173     {
0174         return $this->attributes[self::IMAGE_ARCHITECTURE];
0175     }
0176 }