Skip to content

Commit b90cd2c

Browse files
authored
Prepare v3 release (#10)
1 parent 4679635 commit b90cd2c

11 files changed

+54
-59
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
## [3.0.0]
89
### Added
910
- php 7 type hints.
1011
- This changelog
1112

1213
### Removed
14+
- Initialization in constructors. Now `init()` has to be called explicitly.
1315
- php 5 support.
1416
- php 7.1 support.
1517

@@ -69,7 +71,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6971
### Added
7072
- Initial version.
7173

72-
[Unreleased]: https://github.com/phpcurl/curlwrapper/compare/2.1.0...HEAD
74+
[Unreleased]: https://github.com/phpcurl/curlwrapper/compare/3.0.0...HEAD
75+
[3.0.0]: https://github.com/phpcurl/curlwrapper/compare/2.1.0...3.0.0
7376
[2.1.0]: https://github.com/phpcurl/curlwrapper/compare/2.0.1...2.1.0
7477
[2.0.1]: https://github.com/phpcurl/curlwrapper/compare/2.0.0...2.0.1
7578
[2.0.0]: https://github.com/phpcurl/curlwrapper/compare/1.0.0...2.0.0

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
[![Travis Build](https://travis-ci.org/phpcurl/curlwrapper.svg?branch=master)](https://travis-ci.org/phpcurl/curlwrapper)
55
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/f6dd716c-7729-46f2-903f-12a53e427841.svg)](https://insight.sensiolabs.com/projects/f6dd716c-7729-46f2-903f-12a53e427841)
66

7-
8-
The simplest OOP-style wrapper for the standard php curl functions.
9-
The main purpose is to make code that uses curl calls testable. We do it by injecting the Curl object as a dependency instead of calling curl functions directly.
7+
The simplest OOP-style wrapper for the standard php curl functions with no external dependencies.
8+
The main purpose is to make code that uses curl calls testable.
9+
We do it by injecting the Curl object as a dependency instead of calling curl functions directly.
1010

1111

1212
Hard-coded dependencies. Not testable.
@@ -52,7 +52,7 @@ Via [composer](https://getcomposer.org):
5252

5353
| Classic | OOP |
5454
| --- | --- |
55-
| `$h = curl_init($url)` | `$curl = new Curl($url)` or `$curl->init($url)` |
55+
| `$h = curl_init($url)` | `$curl = new Curl(); $curl->init($url)` |
5656
| `curl_close($h)` | `unset($curl)` |
5757
| `$e = curl_errno($h)` | `$e = $curl->errno()` |
5858
| `$e = curl_error($h)` | `$e = $curl->error()` |
@@ -71,7 +71,7 @@ Via [composer](https://getcomposer.org):
7171

7272
| Classic | OOP |
7373
| --- | --- |
74-
| `curl_multi_init()` | `$cm = new CurlMulti()` |
74+
| `curl_multi_init()` | `$cm = new CurlMulti(); $cm->init()` |
7575
| `curl_multi_close($h)` | `unset($cm)` |
7676
| `$i = curl_multi_add_handle($mh, $ch)` | `$i = $cm->add($curl)` |
7777
| `$i = curl_multi_remove_handle($mh, $ch)` | `$i = $cm->remove($curl)` |
@@ -85,6 +85,6 @@ Via [composer](https://getcomposer.org):
8585

8686
| Classic | OOP |
8787
| --- | --- |
88-
| `curl_share_init()` | `$cs = new CurlShare()` |
88+
| `curl_share_init()` | `$cs = new CurlShare(); $cs->init()` |
8989
| `curl_share_close($h)` | `unset($cs)` |
9090
| `$r = curl_multi_setopt($h, $opt, $val)` | `$r = $cs->setOpt($opt, $val)` |

src/Curl.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
namespace PHPCurl\CurlWrapper;
34

45
class Curl implements CurlInterface
@@ -8,14 +9,6 @@ class Curl implements CurlInterface
89
*/
910
private $handle;
1011

11-
/**
12-
* @param string $url URL
13-
*/
14-
public function __construct(string $url = null)
15-
{
16-
$this->init($url);
17-
}
18-
1912
/**
2013
* @inheritdoc
2114
*/
@@ -86,23 +79,23 @@ public function version(int $age = CURLVERSION_NOW): array
8679
/**
8780
* @inheritdoc
8881
*/
89-
public function strError(int $errornum): string
82+
public function strError(int $errornum): ?string
9083
{
9184
return curl_strerror($errornum);
9285
}
9386

9487
/**
9588
* @inheritdoc
9689
*/
97-
public function escape(string $str): string
90+
public function escape(string $str)
9891
{
9992
return curl_escape($this->handle, $str);
10093
}
10194

10295
/**
10396
* @inheritdoc
10497
*/
105-
public function unescape(string $str): string
98+
public function unescape(string $str)
10699
{
107100
return curl_unescape($this->handle, $str);
108101
}

src/CurlInterface.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
namespace PHPCurl\CurlWrapper;
34

45
interface CurlInterface
@@ -43,8 +44,8 @@ public function getInfo(int $opt = 0);
4344
/**
4445
* @see curl_setopt()
4546
*
46-
* @param int $option Option code
47-
* @param mixed $value Option value
47+
* @param int $option Option code
48+
* @param mixed $value Option value
4849
* @return boolean
4950
*/
5051
public function setOpt(int $option, $value): bool;
@@ -71,23 +72,23 @@ public function version(int $age = CURLVERSION_NOW): array;
7172
* @param int $errornum
7273
* @return string
7374
*/
74-
public function strError(int $errornum): string;
75+
public function strError(int $errornum): ?string;
7576

7677
/**
7778
* @see curl_escape()
7879
*
7980
* @param string $str
80-
* @return string
81+
* @return string|false
8182
*/
82-
public function escape(string $str): string;
83+
public function escape(string $str);
8384

8485
/**
8586
* @see curl_unescape()
8687
*
8788
* @param string $str
88-
* @return string
89+
* @return string|false
8990
*/
90-
public function unescape(string $str): string;
91+
public function unescape(string $str);
9192

9293
/**
9394
* @see curl_reset()

src/CurlMulti.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace PHPCurl\CurlWrapper;
44

@@ -9,11 +9,6 @@ class CurlMulti implements CurlMultiInterface
99
*/
1010
private $handle;
1111

12-
public function __construct()
13-
{
14-
$this->init();
15-
}
16-
1712
/**
1813
* @inheritdoc
1914
*/
@@ -57,15 +52,15 @@ public function getContent(CurlInterface $curl): ?string
5752
/**
5853
* @inheritdoc
5954
*/
60-
public function infoRead(int &$msgs = null): array
55+
public function infoRead(int &$msgs = null)
6156
{
6257
return curl_multi_info_read($this->handle, $msgs);
6358
}
6459

6560
/**
6661
* @inheritdoc
6762
*/
68-
public function remove(CurlInterface $curl): int
63+
public function remove(CurlInterface $curl)
6964
{
7065
return curl_multi_remove_handle($this->handle, $curl->getHandle());
7166
}
@@ -81,7 +76,7 @@ public function select(float $timeout = 1.0): int
8176
/**
8277
* @inheritdoc
8378
*/
84-
public function strError(int $errornum): string
79+
public function strError(int $errornum): ?string
8580
{
8681
return curl_multi_strerror($errornum);
8782
}

src/CurlMultiInterface.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
namespace PHPCurl\CurlWrapper;
34

45
interface CurlMultiInterface
@@ -40,17 +41,17 @@ public function getContent(CurlInterface $curl): ?string;
4041
* @see curl_multi_info_read()
4142
*
4243
* @param int $msgs
43-
* @return array
44+
* @return array|false
4445
*/
45-
public function infoRead(int &$msgs = null): array;
46+
public function infoRead(int &$msgs = null);
4647

4748
/**
4849
* @see curl_multi_remove_handle()
4950
*
5051
* @param CurlInterface $curl Handle to remove
51-
* @return int
52+
* @return int|false
5253
*/
53-
public function remove(CurlInterface $curl): int;
54+
public function remove(CurlInterface $curl);
5455

5556
/**
5657
* @see curl_multi_select()
@@ -66,7 +67,7 @@ public function select(float $timeout = 1.0): int;
6667
* @param int $errornum
6768
* @return string
6869
*/
69-
public function strError(int $errornum): string;
70+
public function strError(int $errornum): ?string;
7071

7172
/**
7273
* @see curl_multi_setopt

src/CurlShare.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
namespace PHPCurl\CurlWrapper;
34

45
class CurlShare implements CurlShareInterface
@@ -8,11 +9,6 @@ class CurlShare implements CurlShareInterface
89
*/
910
private $handle;
1011

11-
public function __construct()
12-
{
13-
$this->init();
14-
}
15-
1612
/**
1713
* @inheritdoc
1814
*/

src/CurlShareInterface.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
namespace PHPCurl\CurlWrapper;
34

45
interface CurlShareInterface
@@ -11,7 +12,7 @@ interface CurlShareInterface
1112
public function init();
1213

1314
/**
14-
* @see curl_share_setopt
15+
* @see curl_share_setopt()
1516
*
1617
* @param int $opt
1718
* @param mixed $val

test/CurlMultiTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace PHPCurl\CurlWrapper;
44

@@ -36,7 +36,7 @@ function curl_multi_strerror($c)
3636

3737
function curl_multi_select($h, $t)
3838
{
39-
return $h === 'foo' ? $t : 0.0;
39+
return 42;
4040
}
4141

4242
function curl_multi_close($h)
@@ -68,16 +68,16 @@ public function testAll()
6868
->will($this->returnValue('bar'));
6969

7070
$cm = new CurlMulti();
71+
$cm->init();
7172
$this->assertEquals('foo', $cm->getHandle());
7273
$this->assertTrue($cm->setOpt(0, 'val'));
7374
$this->assertEquals(1, $cm->add($c));
7475
$this->assertEquals(1, $cm->remove($c));
7576
$this->assertEquals('bar', $cm->getContent($c));
76-
$this->assertEquals(1, $cm->select());
77-
$this->assertEquals(2, $cm->select(2.3));
77+
$this->assertEquals(42, $cm->select());
78+
$this->assertEquals(42, $cm->select(2.3));
7879
$this->assertEquals(['foo' => 42], $cm->infoRead($msgs));
7980
$this->assertEquals(42, $msgs);
80-
$running = 0;
8181
$this->assertEquals(1, $cm->exec($running));
8282
$this->assertEquals(24, $running);
8383
$this->assertEquals('strerror_1', $cm->strError(1));

test/CurlShareTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
namespace PHPCurl\CurlWrapper;
34

45
use PHPUnit\Framework\TestCase;
@@ -25,6 +26,7 @@ class CurlShareTest extends TestCase
2526
public function testAll()
2627
{
2728
$c = new CurlShare();
29+
$c->init();
2830
$this->assertTrue($c->setOpt(0, 'val'));
2931
unset($c);
3032
$this->assertEquals('close_foo', array_pop(self::$log));

test/CurlTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
namespace PHPCurl\CurlWrapper;
34

45
use PHPUnit\Framework\TestCase;
@@ -96,7 +97,8 @@ class CurlTest extends TestCase
9697

9798
public function testAll()
9899
{
99-
$c = new Curl('http://example.com');
100+
$c = new Curl();
101+
$c->init('http://example.com');
100102
$this->assertEquals('my_handle', $c->getHandle());
101103
$this->assertEquals([123], $c->version());
102104
$this->assertEquals('my_strerror', $c->strError(5));
@@ -182,7 +184,8 @@ public function testAll()
182184

183185
public function testClone()
184186
{
185-
$c = new Curl('http://example.com');
187+
$c = new Curl();
188+
$c->init('http://example.com');
186189
$clone = clone($c);
187190
$this->assertEquals('my_handle_copy', $clone->getHandle());
188191
}

0 commit comments

Comments
 (0)