Skip to content

Commit 06b6228

Browse files
committed
Merge pull request #1 from ngmy/0.5.0
Change the version of the dependency, etc
2 parents 2bb4cd8 + 8a8603d commit 06b6228

15 files changed

+703
-165
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
],
1717
"require": {
1818
"php": ">=5.3.0",
19-
"illuminate/support": "4.1.*",
20-
"anlutro/curl": "dev-master"
19+
"illuminate/support": "~4.0",
20+
"anlutro/curl": "0.6.1"
2121
},
2222
"require-dev": {
2323
"orchestra/testbench": "2.1.*",

src/Ngmy/L4Dav/Facades/L4Dav.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Licensed under MIT License.
66
*
77
* @package L4Dav
8-
* @version 0.4.0
8+
* @version 0.5.0
99
* @author Ngmy <y.nagamiya@gmail.com>
1010
* @license http://opensource.org/licenses/MIT MIT License
1111
* @copyright (c) 2014, Ngmy <y.nagamiya@gmail.com>
@@ -32,4 +32,3 @@ protected static function getFacadeAccessor()
3232
}
3333

3434
}
35-

src/Ngmy/L4Dav/L4Dav.php

+48-35
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
* Licensed under MIT License.
66
*
77
* @package L4Dav
8-
* @version 0.4.0
8+
* @version 0.5.0
99
* @author Ngmy <y.nagamiya@gmail.com>
1010
* @license http://opensource.org/licenses/MIT MIT License
1111
* @copyright (c) 2014, Ngmy <y.nagamiya@gmail.com>
1212
* @link https://github.com/ngmy/l4-dav
1313
*/
1414

15+
use Ngmy\L4Dav\Service\Http\RequestInterface;
16+
1517
/**
1618
* A WebDAV client class.
1719
*
@@ -59,26 +61,32 @@ class L4Dav {
5961
*/
6062
protected $url;
6163

64+
protected $request;
65+
6266
/**
6367
* Create a new L4Dav class object.
6468
*
65-
* @param string $webDavUrl The URL of the WebDAV server.
69+
* @param Ngmy\L4Dav\Service\Http\RequestInterface $request
70+
* @param string $webDavUrl The URL of the WebDAV server.
71+
* @param integer $webDavPort The port of the WebDAV server.
6672
* @access public
67-
* @throws \InvalidArgumentException
73+
* @throws InvalidArgumentException
6874
* @return void
6975
*/
70-
public function __construct($webDavUrl)
76+
public function __construct(RequestInterface $request, $webDavUrl, $webDavPort = 80)
7177
{
7278
if (!preg_match('/([a-z]+):\/\/([a-zA-Z0-9\.]+)(:[0-9]+){0,1}(.*)/', $webDavUrl, $m)) {
7379
throw new \InvalidArgumentException('Invalid URL format ('.$webDavUrl.')');
7480
}
7581

7682
$this->schema = $m[1];
7783
$this->host = $m[2];
78-
$this->port = isset($m[3]) ? (int) ltrim($m[3], ':') : 80;
84+
$this->port = isset($m[3]) ? (int) ltrim($m[3], ':') : $webDavPort;
7985
$this->path = isset($m[4]) ? rtrim($m[4], '/').'/' : '/';
8086

8187
$this->url = $this->schema.'://'.$this->host.$this->path;
88+
89+
$this->request = $request;
8290
}
8391

8492
/**
@@ -99,7 +107,10 @@ public function get($srcPath, $destPath)
99107
CURLOPT_RETURNTRANSFER => true,
100108
);
101109

102-
$result = $this->executeWebRequest('GET', $this->url.$srcPath, array(), $options);
110+
$result = $this->request->method('GET')
111+
->url($this->url.$srcPath)
112+
->options($options)
113+
->send();
103114

104115
fclose($fh);
105116

@@ -126,7 +137,10 @@ public function put($srcPath, $destPath)
126137
CURLOPT_INFILESIZE => $filesize,
127138
);
128139

129-
$result = $this->executeWebRequest('PUT', $this->url.$destPath, array(), $options);
140+
$result = $this->request->method('PUT')
141+
->url($this->url.$destPath)
142+
->options($options)
143+
->send();
130144

131145
fclose($fh);
132146

@@ -144,7 +158,10 @@ public function delete($path)
144158
{
145159
$options = array(CURLOPT_PORT => $this->port);
146160

147-
return $this->executeWebRequest('DELETE',$this->url.$path, array(), $options);
161+
return $this->request->method('DELETE')
162+
->url($this->url.$path)
163+
->options($options)
164+
->send();
148165
}
149166

150167
/**
@@ -160,7 +177,11 @@ public function copy($srcPath, $destPath)
160177
$options = array(CURLOPT_PORT => $this->port);
161178
$headers = array('Destination' => $this->url.$destPath);
162179

163-
return $this->executeWebRequest('COPY', $this->url.$srcPath, $headers, $options);
180+
return $this->request->method('COPY')
181+
->url($this->url.$srcPath)
182+
->headers($headers)
183+
->options($options)
184+
->send();
164185
}
165186

166187
/**
@@ -176,7 +197,11 @@ public function move($srcPath, $destPath)
176197
$options = array(CURLOPT_PORT => $this->port);
177198
$headers = array('Destination' => $this->url.$destPath);
178199

179-
return $this->executeWebRequest('MOVE', $this->url.$srcPath, $headers, $options);
200+
return $this->request->method('MOVE')
201+
->url($this->url.$srcPath)
202+
->headers($headers)
203+
->options($options)
204+
->send();
180205
}
181206

182207
/**
@@ -190,7 +215,10 @@ public function mkdir($path)
190215
{
191216
$options = array(CURLOPT_PORT => $this->port);
192217

193-
return $this->executeWebRequest('MKCOL', $this->url.$path, array(), $options);
218+
return $this->request->method('MKCOL')
219+
->url($this->url.$path)
220+
->options($options)
221+
->send();
194222
}
195223

196224
/**
@@ -208,7 +236,10 @@ public function exists($path)
208236
CURLOPT_RETURNTRANSFER => true,
209237
);
210238

211-
$response = $this->executeWebRequest('GET', $this->url.$path, array(), $options);
239+
$response = $this->request->method('GET')
240+
->url($this->url.$path)
241+
->options($options)
242+
->send();
212243

213244
if ($response->getStatus() < 200 || $response->getStatus() > 300) {
214245
return false;
@@ -229,7 +260,11 @@ public function ls($path)
229260
$options = array(CURLOPT_PORT => $this->port);
230261
$headers = array('Depth' => 1);
231262

232-
$response = $this->executeWebRequest('PROPFIND', $this->url.$path, $headers, $options);
263+
$response = $this->request->method('PROPFIND')
264+
->url($this->url.$path)
265+
->headers($headers)
266+
->options($options)
267+
->send();
233268

234269
if ($response->getStatus() < 200 || $response->getStatus() > 300) {
235270
return array();
@@ -243,26 +278,4 @@ public function ls($path)
243278
}
244279
}
245280

246-
/**
247-
* Execute the request to the WebDAV server.
248-
*
249-
* @param string $method The HTTP method.
250-
* @param string $url The request URL.
251-
* @param array $headers The HTTP headers.
252-
* @param array $options The cURL options.
253-
* @access protected
254-
* @return \Ngmy\L4Dav\Response Returns a Response class object.
255-
*/
256-
protected function executeWebRequest($method, $url, $headers, $options)
257-
{
258-
$curl = new cURL;
259-
260-
$result = $curl->newRequest($method, $url)
261-
->setHeaders($headers)
262-
->setOptions($options)
263-
->send();
264-
265-
return $result;
266-
}
267-
268281
}

src/Ngmy/L4Dav/L4DavServiceProvider.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
* Licensed under MIT License.
66
*
77
* @package L4Dav
8-
* @version 0.4.0
8+
* @version 0.5.0
99
* @author Ngmy <y.nagamiya@gmail.com>
1010
* @license http://opensource.org/licenses/MIT MIT License
1111
* @copyright (c) 2014, Ngmy <y.nagamiya@gmail.com>
1212
* @link https://github.com/ngmy/l4-dav
1313
*/
1414

1515
use Illuminate\Support\ServiceProvider;
16+
use Ngmy\L4Dav\Library\cURL;
17+
use Ngmy\L4Dav\Service\Http\CurlRequest;
1618

1719
/**
1820
* A service provider class to bootstrap the L4Dav class in Laravel 4.
@@ -47,8 +49,16 @@ public function register()
4749
{
4850
$this->app['l4-dav'] = $this->app->share(function($app)
4951
{
50-
$webDavUrl = $app['config']['ngmy/l4-dav::url'];
51-
return new L4Dav($webDavUrl);
52+
$config = $app['config'];
53+
54+
$curl = new cURL;
55+
56+
$request = new CurlRequest($curl);
57+
58+
$webDavUrl = $config['ngmy/l4-dav::url'];
59+
$webDavPort = $config['ngmy/l4-dav::port'];
60+
61+
return new L4Dav($request, $webDavUrl, $webDavPort);
5262
});
5363
}
5464

src/Ngmy/L4Dav/cURL.php src/Ngmy/L4Dav/Library/cURL.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
<?php namespace Ngmy\L4Dav;
1+
<?php namespace Ngmy\L4Dav\Library;
22
/**
33
* Part of the L4Dav package.
44
*
55
* Licensed under MIT License.
66
*
77
* @package L4Dav
8-
* @version 0.4.0
8+
* @version 0.5.0
99
* @author Ngmy <y.nagamiya@gmail.com>
1010
* @license http://opensource.org/licenses/MIT MIT License
1111
* @copyright (c) 2014, Ngmy <y.nagamiya@gmail.com>
1212
* @link https://github.com/ngmy/l4-dav
1313
*/
1414

1515
/**
16-
* A wrapper class for the cURL class.
16+
* A wrapper class for the anlutro/curl.
1717
*
1818
* @package L4Dav
1919
*/
@@ -42,6 +42,6 @@ class cURL extends \anlutro\cURL\cURL {
4242
*
4343
* @var string
4444
*/
45-
protected $responseClass = '\Ngmy\L4Dav\Response';
45+
protected $responseClass = '\Ngmy\L4Dav\Service\Http\CurlResponse';
4646

4747
}

0 commit comments

Comments
 (0)