Skip to content

Commit

Permalink
Prepare v3 release (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath authored Nov 2, 2018
1 parent 4679635 commit b90cd2c
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 59 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [3.0.0]
### Added
- php 7 type hints.
- This changelog

### Removed
- Initialization in constructors. Now `init()` has to be called explicitly.
- php 5 support.
- php 7.1 support.

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

[Unreleased]: https://github.com/phpcurl/curlwrapper/compare/2.1.0...HEAD
[Unreleased]: https://github.com/phpcurl/curlwrapper/compare/3.0.0...HEAD
[3.0.0]: https://github.com/phpcurl/curlwrapper/compare/2.1.0...3.0.0
[2.1.0]: https://github.com/phpcurl/curlwrapper/compare/2.0.1...2.1.0
[2.0.1]: https://github.com/phpcurl/curlwrapper/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/phpcurl/curlwrapper/compare/1.0.0...2.0.0
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[![Travis Build](https://travis-ci.org/phpcurl/curlwrapper.svg?branch=master)](https://travis-ci.org/phpcurl/curlwrapper)
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/f6dd716c-7729-46f2-903f-12a53e427841.svg)](https://insight.sensiolabs.com/projects/f6dd716c-7729-46f2-903f-12a53e427841)


The simplest OOP-style wrapper for the standard php curl functions.
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.
The simplest OOP-style wrapper for the standard php curl functions with no external dependencies.
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.


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

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

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

| Classic | OOP |
| --- | --- |
| `curl_share_init()` | `$cs = new CurlShare()` |
| `curl_share_init()` | `$cs = new CurlShare(); $cs->init()` |
| `curl_share_close($h)` | `unset($cs)` |
| `$r = curl_multi_setopt($h, $opt, $val)` | `$r = $cs->setOpt($opt, $val)` |
17 changes: 5 additions & 12 deletions src/Curl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

class Curl implements CurlInterface
Expand All @@ -8,14 +9,6 @@ class Curl implements CurlInterface
*/
private $handle;

/**
* @param string $url URL
*/
public function __construct(string $url = null)
{
$this->init($url);
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -86,23 +79,23 @@ public function version(int $age = CURLVERSION_NOW): array
/**
* @inheritdoc
*/
public function strError(int $errornum): string
public function strError(int $errornum): ?string
{
return curl_strerror($errornum);
}

/**
* @inheritdoc
*/
public function escape(string $str): string
public function escape(string $str)
{
return curl_escape($this->handle, $str);
}

/**
* @inheritdoc
*/
public function unescape(string $str): string
public function unescape(string $str)
{
return curl_unescape($this->handle, $str);
}
Expand Down
17 changes: 9 additions & 8 deletions src/CurlInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

interface CurlInterface
Expand Down Expand Up @@ -43,8 +44,8 @@ public function getInfo(int $opt = 0);
/**
* @see curl_setopt()
*
* @param int $option Option code
* @param mixed $value Option value
* @param int $option Option code
* @param mixed $value Option value
* @return boolean
*/
public function setOpt(int $option, $value): bool;
Expand All @@ -71,23 +72,23 @@ public function version(int $age = CURLVERSION_NOW): array;
* @param int $errornum
* @return string
*/
public function strError(int $errornum): string;
public function strError(int $errornum): ?string;

/**
* @see curl_escape()
*
* @param string $str
* @return string
* @return string|false
*/
public function escape(string $str): string;
public function escape(string $str);

/**
* @see curl_unescape()
*
* @param string $str
* @return string
* @return string|false
*/
public function unescape(string $str): string;
public function unescape(string $str);

/**
* @see curl_reset()
Expand Down
13 changes: 4 additions & 9 deletions src/CurlMulti.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

Expand All @@ -9,11 +9,6 @@ class CurlMulti implements CurlMultiInterface
*/
private $handle;

public function __construct()
{
$this->init();
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -57,15 +52,15 @@ public function getContent(CurlInterface $curl): ?string
/**
* @inheritdoc
*/
public function infoRead(int &$msgs = null): array
public function infoRead(int &$msgs = null)
{
return curl_multi_info_read($this->handle, $msgs);
}

/**
* @inheritdoc
*/
public function remove(CurlInterface $curl): int
public function remove(CurlInterface $curl)
{
return curl_multi_remove_handle($this->handle, $curl->getHandle());
}
Expand All @@ -81,7 +76,7 @@ public function select(float $timeout = 1.0): int
/**
* @inheritdoc
*/
public function strError(int $errornum): string
public function strError(int $errornum): ?string
{
return curl_multi_strerror($errornum);
}
Expand Down
13 changes: 7 additions & 6 deletions src/CurlMultiInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

interface CurlMultiInterface
Expand Down Expand Up @@ -40,17 +41,17 @@ public function getContent(CurlInterface $curl): ?string;
* @see curl_multi_info_read()
*
* @param int $msgs
* @return array
* @return array|false
*/
public function infoRead(int &$msgs = null): array;
public function infoRead(int &$msgs = null);

/**
* @see curl_multi_remove_handle()
*
* @param CurlInterface $curl Handle to remove
* @return int
* @return int|false
*/
public function remove(CurlInterface $curl): int;
public function remove(CurlInterface $curl);

/**
* @see curl_multi_select()
Expand All @@ -66,7 +67,7 @@ public function select(float $timeout = 1.0): int;
* @param int $errornum
* @return string
*/
public function strError(int $errornum): string;
public function strError(int $errornum): ?string;

/**
* @see curl_multi_setopt
Expand Down
8 changes: 2 additions & 6 deletions src/CurlShare.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

class CurlShare implements CurlShareInterface
Expand All @@ -8,11 +9,6 @@ class CurlShare implements CurlShareInterface
*/
private $handle;

public function __construct()
{
$this->init();
}

/**
* @inheritdoc
*/
Expand Down
5 changes: 3 additions & 2 deletions src/CurlShareInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

interface CurlShareInterface
Expand All @@ -11,7 +12,7 @@ interface CurlShareInterface
public function init();

/**
* @see curl_share_setopt
* @see curl_share_setopt()
*
* @param int $opt
* @param mixed $val
Expand Down
10 changes: 5 additions & 5 deletions test/CurlMultiTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

Expand Down Expand Up @@ -36,7 +36,7 @@ function curl_multi_strerror($c)

function curl_multi_select($h, $t)
{
return $h === 'foo' ? $t : 0.0;
return 42;
}

function curl_multi_close($h)
Expand Down Expand Up @@ -68,16 +68,16 @@ public function testAll()
->will($this->returnValue('bar'));

$cm = new CurlMulti();
$cm->init();
$this->assertEquals('foo', $cm->getHandle());
$this->assertTrue($cm->setOpt(0, 'val'));
$this->assertEquals(1, $cm->add($c));
$this->assertEquals(1, $cm->remove($c));
$this->assertEquals('bar', $cm->getContent($c));
$this->assertEquals(1, $cm->select());
$this->assertEquals(2, $cm->select(2.3));
$this->assertEquals(42, $cm->select());
$this->assertEquals(42, $cm->select(2.3));
$this->assertEquals(['foo' => 42], $cm->infoRead($msgs));
$this->assertEquals(42, $msgs);
$running = 0;
$this->assertEquals(1, $cm->exec($running));
$this->assertEquals(24, $running);
$this->assertEquals('strerror_1', $cm->strError(1));
Expand Down
4 changes: 3 additions & 1 deletion test/CurlShareTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

use PHPUnit\Framework\TestCase;
Expand All @@ -25,6 +26,7 @@ class CurlShareTest extends TestCase
public function testAll()
{
$c = new CurlShare();
$c->init();
$this->assertTrue($c->setOpt(0, 'val'));
unset($c);
$this->assertEquals('close_foo', array_pop(self::$log));
Expand Down
9 changes: 6 additions & 3 deletions test/CurlTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php declare(strict_types=1);

namespace PHPCurl\CurlWrapper;

use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -96,7 +97,8 @@ class CurlTest extends TestCase

public function testAll()
{
$c = new Curl('http://example.com');
$c = new Curl();
$c->init('http://example.com');
$this->assertEquals('my_handle', $c->getHandle());
$this->assertEquals([123], $c->version());
$this->assertEquals('my_strerror', $c->strError(5));
Expand Down Expand Up @@ -182,7 +184,8 @@ public function testAll()

public function testClone()
{
$c = new Curl('http://example.com');
$c = new Curl();
$c->init('http://example.com');
$clone = clone($c);
$this->assertEquals('my_handle_copy', $clone->getHandle());
}
Expand Down

0 comments on commit b90cd2c

Please sign in to comment.