Skip to content

Commit 551b2c5

Browse files
authored
Merge pull request #14 from earlcherry/master
put headers and namescpaces
2 parents e9b82b5 + b3b84c1 commit 551b2c5

6 files changed

Lines changed: 202 additions & 228 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ $fileList = $container->listFiles($limit = 10000, $marker = null, $prefix = null
4646

4747
### Put File
4848
```php
49-
$res = $container->putFile(__FILE__, 'example.php');
49+
$res = $container->putFile(__FILE__, 'example.php',["Content-Type: text/html"]);
5050
```
5151

5252
### File info

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"version": "1.0.1",
2020
"autoload": {
2121
"psr-4": {
22-
"": "src/"
22+
"easmith\\selectel\\storage\\": "src"
2323
}
2424
}
2525
}

src/SCurl.php

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
namespace easmith\selectel\storage;
4+
25
/**
36
* Created 06.09.14 23:47 by PhpStorm.
47
*
@@ -8,10 +11,10 @@
811
* @package class_package
912
* @author Eugene Kuznetcov <easmith@mail.ru>
1013
*/
11-
1214
class SCurl {
1315

1416
static private $instance = null;
17+
1518
/**
1619
* Curl resource
1720
*
@@ -46,10 +49,8 @@ class SCurl {
4649
*
4750
* @return SCurl
4851
*/
49-
static function init($url)
50-
{
51-
if (self::$instance == null)
52-
{
52+
static function init($url) {
53+
if (self::$instance == null) {
5354
self::$instance = new SCurl($url);
5455
}
5556
return self::$instance->setUrl($url);
@@ -60,14 +61,12 @@ static function init($url)
6061
*
6162
* @param string $url
6263
*/
63-
private function __construct($url)
64-
{
64+
private function __construct($url) {
6565
$this->setUrl($url);
6666
$this->curlInit();
6767
}
6868

69-
private function curlInit()
70-
{
69+
private function curlInit() {
7170
$this->ch = curl_init($this->url);
7271
curl_setopt($this->ch, CURLOPT_ENCODING, 'gzip,deflate');
7372
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, false);
@@ -87,13 +86,14 @@ private function curlInit()
8786
*
8887
* @return SCurl
8988
*/
90-
public function setUrl($url)
91-
{
89+
public function setUrl($url) {
9290
$this->url = $url;
9391
return self::$instance;
9492
}
9593

96-
private function __clone() {}
94+
private function __clone() {
95+
96+
}
9797

9898
/**
9999
* Set method and request
@@ -102,8 +102,7 @@ private function __clone() {}
102102
*
103103
* @return SCurl
104104
*/
105-
public function request($method)
106-
{
105+
public function request($method) {
107106
$this->method($method);
108107
$this->params = array();
109108
curl_setopt($this->ch, CURLOPT_URL, $this->url);
@@ -128,38 +127,36 @@ public function request($method)
128127
*
129128
* @return SCurl
130129
*/
131-
private function method($method)
132-
{
130+
private function method($method) {
133131
switch ($method) {
134132
case "GET" : {
135-
$this->url .= "?" . http_build_query($this->params);
136-
curl_setopt($this->ch, CURLOPT_HTTPGET, true);
137-
break;
138-
}
133+
$this->url .= "?" . http_build_query($this->params);
134+
curl_setopt($this->ch, CURLOPT_HTTPGET, true);
135+
break;
136+
}
139137
case "HEAD" : {
140-
$this->url .= "?" . http_build_query($this->params);
141-
curl_setopt($this->ch, CURLOPT_NOBODY, true);
142-
break;
143-
}
138+
$this->url .= "?" . http_build_query($this->params);
139+
curl_setopt($this->ch, CURLOPT_NOBODY, true);
140+
break;
141+
}
144142
case "POST" : {
145-
curl_setopt($this->ch, CURLOPT_POST, true);
146-
curl_setopt($this->ch, CURLOPT_POSTFIELDS, http_build_query($this->params));
147-
break;
148-
}
143+
curl_setopt($this->ch, CURLOPT_POST, true);
144+
curl_setopt($this->ch, CURLOPT_POSTFIELDS, http_build_query($this->params));
145+
break;
146+
}
149147
case "PUT" : {
150-
curl_setopt($this->ch, CURLOPT_PUT, true);
151-
break;
152-
}
148+
curl_setopt($this->ch, CURLOPT_PUT, true);
149+
break;
150+
}
153151
default : {
154-
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method);
155-
break;
156-
}
152+
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method);
153+
break;
154+
}
157155
}
158156
return self::$instance;
159157
}
160158

161-
public function putFile($file)
162-
{
159+
public function putFile($file) {
163160
if (!file_exists($file))
164161
throw new SelectelStorageException("File '{$file}' does not exist");
165162
$fp = fopen($file, "r");
@@ -169,9 +166,8 @@ public function putFile($file)
169166
fclose($fp);
170167
return self::$instance;
171168
}
172-
173-
public function putFileContents($contents)
174-
{
169+
170+
public function putFileContents($contents) {
175171
$fp = fopen("php://temp", "r+");
176172
fputs($fp, $contents);
177173
rewind($fp);
@@ -189,8 +185,7 @@ public function putFileContents($contents)
189185
*
190186
* @return array
191187
*/
192-
private function parseHead($head)
193-
{
188+
private function parseHead($head) {
194189
$result = array();
195190
$code = explode("\r\n", $head);
196191
$result['HTTP-Code'] = intval(str_replace("HTTP/1.1", "", $code[0]));
@@ -208,8 +203,7 @@ private function parseHead($head)
208203
*
209204
* @return SCurl
210205
*/
211-
public function setHeaders($headers)
212-
{
206+
public function setHeaders($headers) {
213207
$headers = array_merge(array("Expect:"), $headers);
214208
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
215209
return self::$instance;
@@ -222,8 +216,7 @@ public function setHeaders($headers)
222216
*
223217
* @return SCurl
224218
*/
225-
public function setParams($params)
226-
{
219+
public function setParams($params) {
227220
$this->params = $params;
228221
return self::$instance;
229222
}
@@ -233,8 +226,7 @@ public function setParams($params)
233226
*
234227
* @return array
235228
*/
236-
public function getResult()
237-
{
229+
public function getResult() {
238230
return $this->result;
239231
}
240232

@@ -245,9 +237,9 @@ public function getResult()
245237
*
246238
* @return array
247239
*/
248-
public function getHeaders($header = null)
249-
{
250-
if (!is_null($header)) $this->result['header'][$header];
240+
public function getHeaders($header = null) {
241+
if (!is_null($header))
242+
$this->result['header'][$header];
251243
return $this->result['header'];
252244
}
253245

@@ -256,8 +248,7 @@ public function getHeaders($header = null)
256248
*
257249
* @return array
258250
*/
259-
public function getContent()
260-
{
251+
public function getContent() {
261252
return $this->result['content'];
262253
}
263254

@@ -268,10 +259,10 @@ public function getContent()
268259
*
269260
* @return array
270261
*/
271-
public function getInfo($info = null)
272-
{
273-
if (!is_null($info)) $this->result['info'][$info];
262+
public function getInfo($info = null) {
263+
if (!is_null($info))
264+
$this->result['info'][$info];
274265
return $this->result['info'];
275266
}
276267

277-
}
268+
}

0 commit comments

Comments
 (0)