1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17
18 namespace OpenCloud\ObjectStore\Resource;
19
20 use OpenCloud\Common\Exceptions;
21 use OpenCloud\Common\Service\ServiceInterface;
22 use OpenCloud\ObjectStore\Constants\Header as HeaderConst;
23
24 25 26
27 abstract class AbstractContainer extends AbstractResource
28 {
29 protected $metadataClass = 'OpenCloud\\ObjectStore\\Resource\\ContainerMetadata';
30
31 32 33 34 35 36 37 38 39 40 41
42 public $name;
43
44 public function __construct(ServiceInterface $service, $data = null)
45 {
46 $this->service = $service;
47 $this->metadata = new $this->metadataClass;
48
49
50 $this->populate($data);
51 }
52
53 public function getTransId()
54 {
55 return $this->metadata->getProperty(HeaderConst::TRANS_ID);
56 }
57
58 abstract public function isCdnEnabled();
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
82 return $url->addPath((string) $this->getName())->addPath((string) $path)->setQuery($params);
83 }
84
85 protected function createRefreshRequest()
86 {
87 return $this->getClient()->head($this->getUrl(), array('Accept' => '*/*'));
88 }
89
90 91 92 93 94 95
96 public function setStaticIndexPage($page)
97 {
98 if ($this instanceof CDNContainer) {
99 $this->getLogger()->warning(
100 'This method cannot be called on the CDN object - please execute it on the normal Container'
101 );
102 }
103
104 $headers = array('X-Container-Meta-Web-Index' => $page);
105
106 return $this->getClient()->post($this->getUrl(), $headers)->send();
107 }
108
109 110 111 112 113 114
115 public function setStaticErrorPage($page)
116 {
117 if ($this instanceof CDNContainer) {
118 $this->getLogger()->warning(
119 'This method cannot be called on the CDN object - please execute it on the normal Container'
120 );
121 }
122
123 $headers = array('X-Container-Meta-Web-Error' => $page);
124
125 return $this->getClient()->post($this->getUrl(), $headers)->send();
126 }
127 }
128