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;
19
20 use OpenCloud\Common\Service\NovaService;
21 use OpenCloud\Database\Resource\Instance;
22 use OpenCloud\Database\Resource\Configuration;
23 use OpenCloud\Database\Resource\Datastore;
24
25 /**
26 * The Rackspace Database service
27 */
28 class Service extends NovaService
29 {
30 const DEFAULT_TYPE = 'rax:database';
31 const DEFAULT_NAME = 'cloudDatabases';
32
33 /**
34 * Returns an Instance
35 *
36 * @param string $id the ID of the instance to retrieve
37 * @return \OpenCloud\Database\Resource\Instance
38 */
39 public function instance($id = null)
40 {
41 return $this->resource('Instance', $id);
42 }
43
44 /**
45 * Returns a Collection of Instance objects
46 *
47 * @param array $params
48 * @return \OpenCloud\Common\Collection\PaginatedIterator
49 */
50 public function instanceList($params = array())
51 {
52 $url = clone $this->getUrl();
53 $url->addPath(Instance::resourceName())->setQuery($params);
54
55 return $this->resourceList('Instance', $url);
56 }
57
58 /**
59 * Returns a Configuration
60 *
61 * @param string $id the ID of the configuration to retrieve
62 * @return \OpenCloud\Database\Resource\Configuration
63 */
64 public function configuration($id = null)
65 {
66 return $this->resource('Configuration', $id);
67 }
68
69 /**
70 * Returns a Collection of Configuration objects
71 *
72 * @param array $params
73 * @return \OpenCloud\Common\Collection\PaginatedIterator
74 */
75 public function configurationList($params = array())
76 {
77 $url = clone $this->getUrl();
78 $url->addPath(Configuration::resourceName())->setQuery($params);
79
80 return $this->resourceList('Configuration', $url);
81 }
82
83 /**
84 * Returns a Datastore
85 *
86 * @param string $id the ID of the datastore to retrieve
87 * @return \OpenCloud\Database\Resource\Datastore
88 */
89 public function datastore($id = null)
90 {
91 return $this->resource('Datastore', $id);
92 }
93
94 /**
95 * Returns a Collection of Datastore objects
96 *
97 * @param array $params
98 * @return \OpenCloud\Common\Collection\PaginatedIterator
99 */
100 public function datastoreList($params = array())
101 {
102 $url = clone $this->getUrl();
103 $url->addPath(Datastore::resourceName())->setQuery($params);
104
105 return $this->resourceList('Datastore', $url);
106 }
107 }
108