Overview

Namespaces

  • None
  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Exceptions
      • Log
      • Request
        • Response
    • Compute
    • Database
    • DNS
    • LoadBalancer
      • Resources
    • ObjectStore
      • Resource
    • Orchestration
    • Volume
  • PHP

Classes

  • AsyncResponse
  • Domain
  • Object
  • PtrRecord
  • Record
  • Service
  • Subdomain
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright Copyright 2013 Rackspace US, Inc. See COPYING for licensing information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
  7:  * @version   1.6.0
  8:  * @author    Glen Campbell <glen.campbell@rackspace.com>
  9:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
 10:  */
 11: 
 12: namespace OpenCloud\DNS;
 13: 
 14: use OpenCloud\Common\PersistentObject;
 15: use OpenCloud\Common\Lang;
 16: use OpenCloud\Common\Exceptions;
 17: 
 18: /**
 19:  * The DnsObject class is an extension of the PersistentObject class that
 20:  * permits the asynchronous responses used by Cloud DNS
 21:  */
 22: abstract class Object extends PersistentObject 
 23: {
 24: 
 25:     /**
 26:      * Create() returns an asynchronous response
 27:      *
 28:      * @param array $params array of key/value pairs
 29:      * @return AsyncResponse
 30:      */
 31:     public function create($params = array()) 
 32:     {
 33:         return new AsyncResponse($this->Service(), parent::create($params)->httpBody());
 34:     }
 35: 
 36:     /**
 37:      * Update() returns an asynchronous response
 38:      *
 39:      * @param array $params array of key/value pairs
 40:      * @return AsyncResponse
 41:      */
 42:     public function update($params = array()) 
 43:     {
 44:         return new AsyncResponse($this->Service(), parent::update($params)->httpBody());
 45:     }
 46: 
 47:     /**
 48:      * Delete() returns an asynchronous response
 49:      *
 50:      * @param array $params array of key/value pairs
 51:      * @return AsyncResponse
 52:      */
 53:     public function delete() 
 54:     {
 55:         return new AsyncResponse($this->Service(), parent::delete()->httpBody());
 56:     }
 57: 
 58:     /**
 59:      * creates the JSON for create
 60:      *
 61:      * @return stdClass
 62:      */
 63:     protected function createJson() 
 64:     {
 65:         if (!$this->getCreateKeys()) {
 66:             throw new Exceptions\CreateError(
 67:                 Lang::translate('Missing [createKeys]')
 68:             );
 69:         }
 70: 
 71:         $object = new \stdClass;
 72:         $object->{self::jsonCollectionName()} = array(
 73:             $this->getJson($this->getCreateKeys())
 74:         );
 75:         
 76:         return $object;
 77:     }
 78: 
 79:     /**
 80:      * creates the JSON for update
 81:      *
 82:      * @return stdClass
 83:      */
 84:     protected function updateJson($params = array()) 
 85:     {
 86:         if (!$this->getUpdateKeys()) {
 87:             throw new Exceptions\UpdateError(
 88:                 Lang::translate('Missing [updateKeys]')
 89:             );
 90:         }
 91:         return $this->getJson($this->getUpdateKeys());
 92:     }
 93: 
 94:     /**
 95:      * returns JSON based on $keys
 96:      *
 97:      * @param array $keys list of items to include
 98:      * @return stdClass
 99:      */
100:     private function getJson($keys) 
101:     {
102:         $object = new \stdClass;
103:         foreach($keys as $item) {
104:             if (!empty($this->$item)) {
105:                 $object->$item = $this->$item;
106:             }
107:         }
108:         return $object;
109:     }
110:     
111:     /**
112:      * Retrieve the keys which are required when the object is created.
113:      * 
114:      * @return array|false
115:      */
116:     public function getCreateKeys()
117:     {
118:         return (!empty($this->createKeys)) ? $this->createKeys : false;
119:     }
120:     
121:     /**
122:      * Retrieve the keys which are required when the object is updated.
123:      *  
124:      * @return array|false
125:      */
126:     public function getUpdateKeys()
127:     {
128:         return (!empty($this->updateKeys)) ? $this->updateKeys : false;
129:     }
130:     
131: }
132: 
PHP OpenCloud API API documentation generated by ApiGen 2.8.0