Skip to content

Commit ac09e40

Browse files
committed
close #105
1 parent d7e3676 commit ac09e40

File tree

9 files changed

+114
-83
lines changed

9 files changed

+114
-83
lines changed

lib/OpenCloud/AbstractClass/ObjectStore.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Glen Campbell <[email protected]>
3030
*/
31-
abstract class ObjectStore extends Base
31+
abstract class ObjectStore extends Base
3232
{
3333

3434
const ACCOUNT_META_PREFIX = 'X-Account-';
@@ -41,7 +41,7 @@ abstract class ObjectStore extends Base
4141
/**
4242
* Initializes the metadata component
4343
*/
44-
public function __construct()
44+
public function __construct()
4545
{
4646
$this->metadata = new Metadata;
4747
}
@@ -53,7 +53,7 @@ public function __construct()
5353
* @param \OpenCloud\HttpResponse
5454
* @return void
5555
*/
56-
public function GetMetadata($response)
56+
public function GetMetadata($response)
5757
{
5858
$this->metadata = new Metadata;
5959
$prefix = $this->Prefix();
@@ -68,7 +68,7 @@ public function GetMetadata($response)
6868
*
6969
* @return array;
7070
*/
71-
public function MetadataHeaders()
71+
public function MetadataHeaders()
7272
{
7373
$headers = array();
7474

@@ -93,7 +93,7 @@ public function MetadataHeaders()
9393
* @api
9494
* @throws NameError if attribute 'name' is not defined
9595
*/
96-
public function Name()
96+
public function Name()
9797
{
9898
if (property_exists($this, 'name')) {
9999
return $this->name;
@@ -102,17 +102,17 @@ public function Name()
102102
}
103103
}
104104

105-
public static function JsonName()
105+
public static function JsonName()
106106
{
107107
return null;
108108
}
109109

110-
public static function JsonCollectionName()
110+
public static function JsonCollectionName()
111111
{
112112
return null;
113113
}
114114

115-
public static function JsonCollectionElement()
115+
public static function JsonCollectionElement()
116116
{
117117
return null;
118118
}
@@ -123,13 +123,13 @@ public static function JsonCollectionElement()
123123
* @param string $type The type of object; derived from `get_class()` if not
124124
* specified.
125125
*/
126-
private function Prefix($type = null)
126+
private function Prefix($type = null)
127127
{
128128
if (!isset($type)) {
129129
$parts = preg_split('/\\\/', get_class($this));
130130
$type = $parts[count($parts)-1];
131131
}
132-
132+
133133
switch($type) {
134134
case 'Account':
135135
return self::ACCOUNT_META_PREFIX;
@@ -144,7 +144,9 @@ private function Prefix($type = null)
144144
return self::OBJECT_META_PREFIX;
145145
break;
146146
default:
147-
throw new MetadataPrefixError(sprintf(Lang::translate('Unrecognized metadata type [%s]'), $type));
147+
throw new MetadataPrefixError(
148+
sprintf(Lang::translate(
149+
'Unrecognized metadata type [%s]'), $type));
148150
break;
149151
}
150152
}

lib/OpenCloud/Base/Request/Curl.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @api
2020
* @author Glen Campbell <[email protected]>
2121
*/
22-
class Curl extends Base implements HttpRequestInterface
22+
class Curl extends Base implements HttpRequestInterface
2323
{
2424

2525
private $url;
@@ -38,7 +38,7 @@ class Curl extends Base implements HttpRequestInterface
3838
* @param string $method the HTTP method (default "GET")
3939
* @param array $options optional hashed array of options => value pairs
4040
*/
41-
public function __construct($url, $method = 'GET', array $options = array())
41+
public function __construct($url, $method = 'GET', array $options = array())
4242
{
4343
$this->url = $url;
4444
$this->method = $method;
@@ -100,7 +100,7 @@ public function __construct($url, $method = 'GET', array $options = array())
100100
* @param const $name - a CURL named constant; e.g. CURLOPT_TIMEOUT
101101
* @param mixed $value - the value for the option
102102
*/
103-
public function SetOption($name, $value)
103+
public function SetOption($name, $value)
104104
{
105105
return curl_setopt($this->handle, $name, $value);
106106
}
@@ -115,7 +115,7 @@ public function SetOption($name, $value)
115115
* @param integer $value The connection timeout in seconds.
116116
* Use 0 to wait indefinitely (NOT recommended)
117117
*/
118-
public function SetConnectTimeout($value)
118+
public function SetConnectTimeout($value)
119119
{
120120
$this->SetOption(CURLOPT_CONNECTTIMEOUT, $value);
121121
}
@@ -130,7 +130,7 @@ public function SetConnectTimeout($value)
130130
* @param integer $value - the number of seconds to wait before timing out
131131
* the HTTP request.
132132
*/
133-
public function SetHttpTimeout($value)
133+
public function SetHttpTimeout($value)
134134
{
135135
$this->SetOption(CURLOPT_TIMEOUT, $value);
136136
}
@@ -141,7 +141,7 @@ public function SetHttpTimeout($value)
141141
* If you set this to a non-zero value, then it will repeat the request
142142
* up to that number.
143143
*/
144-
public function SetRetries($value)
144+
public function SetRetries($value)
145145
{
146146
$this->retries = $value;
147147
}
@@ -154,7 +154,7 @@ public function SetRetries($value)
154154
*
155155
* @param array $arr an associative array of headers
156156
*/
157-
public function setheaders($array)
157+
public function setheaders($array)
158158
{
159159
if (!is_array($array)) {
160160
throw new HttpException(Lang::translate('Value passed to CurlRequest::setheaders() must be array'));
@@ -174,7 +174,7 @@ public function setheaders($array)
174174
* @param string $name The name of the header
175175
* @param mixed $value The value of the header
176176
*/
177-
public function SetHeader($name, $value)
177+
public function SetHeader($name, $value)
178178
{
179179
$this->headers[$name] = $value;
180180
}
@@ -189,7 +189,7 @@ public function SetHeader($name, $value)
189189
* @return OpenCloud\HttpResponse
190190
* @throws OpenCloud\HttpError
191191
*/
192-
public function Execute()
192+
public function Execute()
193193
{
194194
// set all the headers
195195
$headarr = array();
@@ -202,9 +202,8 @@ public function Execute()
202202

203203
// set up to retry if necessary
204204
$try_counter = 0;
205-
206-
do {
207205

206+
do {
208207
$data = curl_exec($this->handle);
209208
if (curl_errno($this->handle) && ($try_counter<$this->retries)) {
210209
$this->debug(Lang::translate('Curl error [%d]; retrying [%s]'), curl_errno($this->handle), $this->url);
@@ -225,7 +224,7 @@ public function Execute()
225224
case 3:
226225
throw new HttpUrlError(sprintf(Lang::translate('Malformed URL [%s]'), $this->url));
227226
break;
228-
case 28:
227+
case 28:
229228
// timeout
230229
throw new HttpTimeoutError(Lang::translate('Operation timed out; check RAXSDK_TIMEOUT value'));
231230
break;
@@ -246,39 +245,39 @@ public function Execute()
246245
/**
247246
* returns an array of information about the request
248247
*/
249-
public function info()
248+
public function info()
250249
{
251250
return curl_getinfo($this->handle);
252251
}
253252

254253
/**
255254
* returns the most recent CURL error number
256255
*/
257-
public function errno()
256+
public function errno()
258257
{
259258
return curl_errno($this->handle);
260259
}
261260

262261
/**
263262
* returns the most recent CURL error string
264263
*/
265-
public function error()
264+
public function error()
266265
{
267266
return curl_error($this->handle);
268267
}
269268

270269
/**
271270
* Closes the HTTP request
272271
*/
273-
public function close()
272+
public function close()
274273
{
275274
return curl_close($this->handle);
276275
}
277276

278277
/**
279278
* Returns the headers as an array
280279
*/
281-
public function ReturnHeaders()
280+
public function ReturnHeaders()
282281
{
283282
return $this->returnheaders;
284283
}
@@ -289,7 +288,7 @@ public function ReturnHeaders()
289288
* @param mixed $ch a CURL handle
290289
* @param string $header the header string in its entirety
291290
*/
292-
public function _get_header_cb($ch, $header)
291+
public function _get_header_cb($ch, $header)
293292
{
294293
$this->returnheaders[] = $header;
295294
return strlen($header);

lib/OpenCloud/ObjectStore/CDNContainer.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ public function ObjectList($params = array())
219219
$url .= '?' . $qstring;
220220
}
221221

222-
return $this->Service()->Collection('\OpenCloud\ObjectStore\DataObject', $url, $this);
222+
return $this->Service()->Collection(
223+
'\OpenCloud\ObjectStore\DataObject', $url, $this);
223224
}
224225

225226
/**
@@ -250,7 +251,8 @@ public function Service()
250251
*/
251252
protected function Refresh()
252253
{
253-
$response = $this->Service()->Request($this->Url(), 'HEAD', array('Accept' => '*/*'));
254+
$response = $this->Service()->Request(
255+
$this->Url(), 'HEAD', array('Accept' => '*/*'));
254256

255257
// validate the response code
256258
if ($this->name != 'TEST') {
@@ -285,19 +287,23 @@ protected function Refresh()
285287
private function is_valid_name($name)
286288
{
287289
if (!$name) {
288-
throw new Exceptions\ContainerNameError(Lang::translate('Container name cannot be blank'));
290+
throw new Exceptions\ContainerNameError(
291+
Lang::translate('Container name cannot be blank'));
289292
}
290293

291294
if ($name == '0') {
292-
throw new Exceptions\ContainerNameError(Lang::translate('"0" is not a valid container name'));
295+
throw new Exceptions\ContainerNameError(
296+
Lang::translate('"0" is not a valid container name'));
293297
}
294298

295299
if (strpos($name, '/') !== false) {
296-
throw new Exceptions\ContainerNameError(Lang::translate('Container name cannot contain "/"'));
300+
throw new Exceptions\ContainerNameError(
301+
Lang::translate('Container name cannot contain "/"'));
297302
}
298303

299304
if (strlen($name) > Service::MAX_CONTAINER_NAME_LEN) {
300-
throw new Exceptions\ContainerNameError(Lang::translate('Container name is too long'));
305+
throw new Exceptions\ContainerNameError(
306+
Lang::translate('Container name is too long'));
301307
}
302308

303309
return true;

lib/OpenCloud/ObjectStore/Container.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ public function StaticSiteErrorPage($name)
168168
public function CDN()
169169
{
170170
if (!$cdn = $this->_cdn) {
171-
throw new Exceptions\CdnNotAvailableError(Lang::translate('CDN service is not available'));
171+
throw new Exceptions\CdnNotAvailableError(
172+
Lang::translate('CDN service is not available'));
172173
}
173174
return $cdn;
174175
}
@@ -205,6 +206,9 @@ public function PublicURL()
205206
*/
206207
public function CDNinfo($prop = null)
207208
{
209+
if (get_class($this->Service())=='OpenCloud\ObjectStore\ObjectStoreCDN')
210+
return $this->metadata;
211+
208212
// return NULL if the CDN container is not enabled
209213
if (!isset($this->CDN()->metadata->Enabled)
210214
|| !$this->CDN()->metadata->Enabled
@@ -264,7 +268,10 @@ protected function Refresh()
264268
parent::Refresh();
265269

266270
// find the CDN object
267-
$cdn = $this->Service()->CDN();
271+
if (get_class($this->Service()) ==
272+
'OpenCloud\ObjectStore\ObjectStoreCDN')
273+
return;
274+
$cdn = $this->Service()->CDN();
268275
if ($cdn !== null) {
269276
try {
270277
$this->_cdn = new CDNContainer(

0 commit comments

Comments
 (0)