/** * @param mixed $info The data structure that is populating the object. * @param bool $setObjects If set to TRUE, then this method will try to populate associated resources as objects * rather than anonymous data types. So, a Server being populated might stock a Network * object instead of a stdClass object. * @throws Exceptions\InvalidArgumentError */ public function populate($info, $setObjects = true) { if (is_string($info) || is_integer($info)) { $this->setProperty($this->primaryKeyField(), $info); $this->refresh($info); } elseif (is_object($info) || is_array($info)) { foreach ($info as $key => $value) { if ($key == 'metadata' || $key == 'meta') { // Try retrieving existing value if (null === ($metadata = $this->getProperty($key))) { // If none exists, create new object $metadata = new Metadata(); } // Set values for metadata $metadata->setArray($value); // Set object property $this->setProperty($key, $metadata); } elseif (!empty($this->associatedResources[$key]) && $setObjects === true) { // Associated resource try { $resource = $this->getService()->resource($this->associatedResources[$key], $value); $resource->setParent($this); $this->setProperty($key, $resource); } catch (Exception\ServiceException $e) { } } elseif (!empty($this->associatedCollections[$key]) && $setObjects === true) { // Associated collection try { $className = $this->associatedCollections[$key]; $options = $this->makeResourceIteratorOptions($className); $iterator = ResourceIterator::factory($this, $options, $value); $this->setProperty($key, $iterator); } catch (Exception\ServiceException $e) { } } elseif (!empty($this->aliases[$key])) { // Sometimes we might want to preserve camelCase // or covert `rax-bandwidth:bandwidth` to `raxBandwidth` $this->setProperty($this->aliases[$key], $value); } else { // Normal key/value pair $this->setProperty($key, $value); } } } elseif (null !== $info) { throw new Exceptions\InvalidArgumentError(sprintf(Lang::translate('Argument for [%s] must be string or object'), get_class())); } }
/** * List over all the tenants for this cloud account. * * @return \OpenCloud\Common\Collection\ResourceIterator */ public function getTenants() { $url = $this->getUrl(); $url->addPath('tenants'); $response = $this->getClient()->get($url)->send(); if ($body = Formatter::decode($response)) { return ResourceIterator::factory($this, array('resourceClass' => 'Tenant', 'key.collection' => 'tenants'), $body->tenants); } }