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\ObjectStore;
19:
20: use OpenCloud\ObjectStore\Resource\CDNContainer;
21: use OpenCloud\ObjectStore\Resource\ContainerMetadata;
22:
23: /**
24: * This is the CDN version of the ObjectStore service.
25: */
26: class CDNService extends AbstractService
27: {
28: const DEFAULT_NAME = 'cloudFilesCDN';
29: const DEFAULT_TYPE = 'rax:object-cdn';
30:
31: /**
32: * List CDN-enabled containers.
33: *
34: * @param array $filter Array of filter options such as:
35: *
36: * * `limit`: number of results to limit the list to. Optional.
37: * * `marker`: name of container after which to start the list. Optional.
38: * * `end_marker`: name of container before which to end the list. Optional.
39: * @return \OpenCloud\Common\Collection\PaginatedIterator Iterator to list of CDN-enabled containers
40: */
41: public function listContainers(array $filter = array())
42: {
43: $filter['format'] = 'json';
44: return $this->resourceList('CDNContainer', $this->getUrl(null, $filter), $this);
45: }
46:
47: /**
48: * Return an existing CDN-enabled container.
49: *
50: * @param \stdClass $data Data to initialize container.
51: * @return CDNContainer CDN-enabled Container
52: */
53: public function cdnContainer($data)
54: {
55: $container = new CDNContainer($this, $data);
56:
57: if (is_object($data)) {
58: $metadata = new ContainerMetadata();
59: $metadata->setArray(array(
60: 'Streaming-Uri' => $data->cdn_streaming_uri,
61: 'Ios-Uri' => $data->cdn_ios_uri,
62: 'Ssl-Uri' => $data->cdn_ssl_uri,
63: 'Enabled' => $data->cdn_enabled,
64: 'Ttl' => $data->ttl,
65: 'Log-Retention' => $data->log_retention,
66: 'Uri' => $data->cdn_uri,
67: ));
68: $container->setMetadata($metadata);
69: }
70:
71: return $container;
72: }
73: }
74: