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 Jamie Hannaford <jamie.hannaford@rackspace.com>
8: */
9:
10: namespace OpenCloud\ObjectStore\Resource;
11:
12: use OpenCloud\Common\Service\AbstractService;
13: use OpenCloud\Common\Exceptions;
14: use OpenCloud\ObjectStore\Constants\Header as HeaderConst;
15:
16: /**
17: * Abstract class holding shared functionality for containers.
18: */
19: abstract class AbstractContainer extends AbstractResource
20: {
21:
22: protected $metadataClass = 'OpenCloud\\ObjectStore\\Resource\\ContainerMetadata';
23:
24: /**
25: * The name of the container.
26: *
27: * The only restrictions on container names is that they cannot contain a
28: * forward slash (/) and must be less than 256 bytes in length. Please note
29: * that the length restriction applies to the name after it has been URL
30: * encoded. For example, a container named Course Docs would be URL encoded
31: * as Course%20Docs - which is 13 bytes in length rather than the expected 11.
32: *
33: * @var string
34: */
35: public $name;
36:
37: public function __construct(AbstractService $service, $data = null)
38: {
39: $this->service = $service;
40: $this->metadata = new $this->metadataClass;
41:
42: // Populate data if set
43: $this->populate($data);
44: }
45:
46: public function getTransId()
47: {
48: return $this->metadata->getProperty(HeaderConst::TRANS_ID);
49: }
50:
51: public function isCdnEnabled()
52: {
53: if ($this instanceof CDNContainer) {
54: return $this->metadata->getProperty(HeaderConst::ENABLED) == 'True';
55: } else {
56: return empty($this->cdn);
57: }
58: }
59:
60: public function hasLogRetention()
61: {
62: if ($this instanceof CDNContainer) {
63: return $this->metadata->getProperty(HeaderConst::LOG_RETENTION) == 'True';
64: } else {
65: return $this->metadata->propertyExists(HeaderConst::ACCESS_LOGS);
66: }
67: }
68:
69: public function primaryKeyField()
70: {
71: return 'name';
72: }
73:
74: public function getUrl($path = null, array $params = array())
75: {
76: if (strlen($this->getName()) == 0) {
77: throw new Exceptions\NoNameError('Container does not have a name');
78: }
79:
80: $url = $this->getService()->getUrl();
81: return $url->addPath($this->getName())->addPath($path)->setQuery($params);
82: }
83:
84: protected function createRefreshRequest()
85: {
86: return $this->getClient()->head($this->getUrl(), array('Accept' => '*/*'));
87: }
88:
89: }