|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2012-2014 Rackspace US, Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +namespace OpenCloud\Database\Resource; |
| 19 | + |
| 20 | +use OpenCloud\Common\Lang; |
| 21 | +use OpenCloud\Common\Exceptions; |
| 22 | +use OpenCloud\Common\Resource\PersistentResource; |
| 23 | +use OpenCloud\Database\Service; |
| 24 | + |
| 25 | +/** |
| 26 | + * This class represents a Backup |
| 27 | + */ |
| 28 | +class Backup extends PersistentResource |
| 29 | +{ |
| 30 | + public $id; |
| 31 | + public $name; |
| 32 | + public $description; |
| 33 | + public $created; |
| 34 | + public $datastore; |
| 35 | + public $updated; |
| 36 | + public $instance; |
| 37 | + public $instanceId; |
| 38 | + public $locationRef; |
| 39 | + |
| 40 | + protected static $json_name = 'backup'; |
| 41 | + protected static $url_resource = 'backups'; |
| 42 | + |
| 43 | + protected $createKeys = array( |
| 44 | + 'name', |
| 45 | + 'instanceId', |
| 46 | + 'description' |
| 47 | + ); |
| 48 | + |
| 49 | + protected $associatedResources = array( |
| 50 | + 'instance' => 'Instance' |
| 51 | + ); |
| 52 | + |
| 53 | + protected $aliases = array( |
| 54 | + 'instance_id' => 'instanceId' |
| 55 | + ); |
| 56 | + |
| 57 | + public function __construct(Service $service, $info = null) |
| 58 | + { |
| 59 | + $this->instance = new \stdClass; |
| 60 | + return parent::__construct($service, $info); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Returns the JSON object for creating the backup |
| 65 | + */ |
| 66 | + protected function createJson() |
| 67 | + { |
| 68 | + if (!isset($this->instanceId)) { |
| 69 | + throw new Exceptions\BackupInstanceError( |
| 70 | + Lang::translate('The `instanceId` attribute is required and must be a string') |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + if (!isset($this->name)) { |
| 75 | + throw new Exceptions\BackupNameError( |
| 76 | + Lang::translate('Backup name is required') |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + $out = [ |
| 81 | + 'backup' => [ |
| 82 | + 'name' => $this->name, |
| 83 | + 'instance' => $this->instanceId |
| 84 | + ] |
| 85 | + ]; |
| 86 | + |
| 87 | + if (isset($this->description)) { |
| 88 | + $out['backup']['description'] = $this->description; |
| 89 | + } |
| 90 | + return (object) $out; |
| 91 | + } |
| 92 | +} |
0 commit comments