Overview

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Identity
      • Log
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Resource
    • LoadBalancer
      • Resource
    • ObjectStore
      • Constants
      • Exception
      • Resource
      • Upload
    • Orchestration
    • Queues
      • Exception
      • Resource
    • Volume
      • Resource
  • PHP

Classes

  • AbstractResource
  • Agent
  • AgentConnection
  • AgentHost
  • AgentHostInfo
  • AgentTarget
  • AgentToken
  • Alarm
  • Changelog
  • Check
  • CheckType
  • Entity
  • Metric
  • Notification
  • NotificationHistory
  • NotificationPlan
  • NotificationType
  • ReadonlyResource
  • View
  • Zone
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0
  7:  * @author    Glen Campbell <glen.campbell@rackspace.com>
  8:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
  9:  */
 10: 
 11: namespace OpenCloud\CloudMonitoring\Resource;
 12: 
 13: use OpenCloud\Common\Exceptions;
 14: use OpenCloud\Common\PersistentObject;
 15: use OpenCloud\Common\Http\Message\Formatter;
 16: 
 17: abstract class AbstractResource extends PersistentObject
 18: {
 19:     public function createJson()
 20:     {
 21:         foreach (static::$requiredKeys as $requiredKey) {
 22:             if (!$this->getProperty($requiredKey)) {
 23:                 throw new Exceptions\CreateError(sprintf(
 24:                     "%s is required to create a new %s", $requiredKey, get_class()
 25:                 ));
 26:             }
 27:         }
 28: 
 29:         $object = new \stdClass;
 30:         
 31:         foreach (static::$emptyObject as $key) {
 32:             if ($property = $this->getProperty($key)) {
 33:                 $object->$key = $property;
 34:             }
 35:         }
 36:         
 37:         return $object;
 38:     }
 39: 
 40:     protected function updateJson($params = array())
 41:     {
 42:         $object = (object) $params;       
 43:         
 44:         foreach (static::$requiredKeys as $requiredKey) {
 45:             if (!$this->getProperty($requiredKey)) {
 46:                 throw new Exceptions\UpdateError(sprintf(
 47:                     "%s is required to update a %s", $requiredKey, get_class($this)
 48:                 ));
 49:             }
 50:         }
 51: 
 52:         return $object;
 53:     }
 54: 
 55:     /**
 56:      * Retrieves a collection of resource objects.
 57:      * 
 58:      * @access public
 59:      * @return void
 60:      */
 61:     public function listAll()
 62:     {
 63:         return $this->getService()->collection(get_class($this), $this->url());
 64:     }
 65: 
 66:     /**
 67:      * Test the validity of certain parameters for the resource.
 68:      * 
 69:      * @access public
 70:      * @param array $params (default: array())
 71:      * @param bool $debug (default: false)
 72:      * @return void
 73:      */
 74:     public function testParams($params = array(), $debug = false)
 75:     {
 76:         $json = json_encode((object) $params);
 77: 
 78:         // send the request
 79:         $response = $this->getService()
 80:             ->getClient()
 81:             ->post($this->testUrl($debug), array(), $json)
 82:             ->send();
 83: 
 84:         return Formatter::decode($response);
 85:     }
 86: 
 87:     /**
 88:      * Test the validity of an existing resource.
 89:      * 
 90:      * @access public
 91:      * @param bool $debug (default: false)
 92:      * @return void
 93:      */
 94:     public function test($debug = false)
 95:     {
 96:         $json = json_encode($this->updateJson());
 97:         $this->checkJsonError();
 98: 
 99:         $response = $this->getClient()
100:             ->post($this->testExistingUrl($debug), array(), $json)
101:             ->send();
102: 
103:         return Formatter::decode($response);
104:     }
105:    
106: }
PHP OpenCloud API API documentation generated by ApiGen 2.8.0