Skip to content

Commit

Permalink
Classes renamed according to yii2 convention.
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Aug 18, 2015
1 parent fd77900 commit 1e2f4fb
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 88 deletions.
18 changes: 9 additions & 9 deletions Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Client extends Component
/**
* @var Transport|array|string|callable HTTP message transport.
*/
private $_transport = 'yii\httpclient\TransportStream';
private $_transport = 'yii\httpclient\StreamTransport';


/**
Expand Down Expand Up @@ -115,16 +115,16 @@ public function getTransport()
public function getFormatter($format)
{
static $defaultFormatters = [
self::FORMAT_JSON => 'yii\httpclient\FormatterJson',
self::FORMAT_JSON => 'yii\httpclient\JsonFormatter',
self::FORMAT_URLENCODED => [
'class' => 'yii\httpclient\FormatterUrlEncoded',
'class' => 'yii\httpclient\UrlEncodedFormatter',
'encodingType' => PHP_QUERY_RFC1738
],
self::FORMAT_RAW_URLENCODED => [
'class' => 'yii\httpclient\FormatterUrlEncoded',
'class' => 'yii\httpclient\UrlEncodedFormatter',
'encodingType' => PHP_QUERY_RFC3986
],
self::FORMAT_XML => 'yii\httpclient\FormatterXML',
self::FORMAT_XML => 'yii\httpclient\XMLFormatter',
];

if (!isset($this->formatters[$format])) {
Expand All @@ -150,10 +150,10 @@ public function getFormatter($format)
public function getParser($format)
{
static $defaultParsers = [
self::FORMAT_JSON => 'yii\httpclient\ParserJson',
self::FORMAT_URLENCODED => 'yii\httpclient\ParserUrlEncoded',
self::FORMAT_RAW_URLENCODED => 'yii\httpclient\ParserUrlEncoded',
self::FORMAT_XML => 'yii\httpclient\ParserXml',
self::FORMAT_JSON => 'yii\httpclient\JsonParser',
self::FORMAT_URLENCODED => 'yii\httpclient\UrlEncodedParser',
self::FORMAT_RAW_URLENCODED => 'yii\httpclient\UrlEncodedParser',
self::FORMAT_XML => 'yii\httpclient\XmlParser',

This comment has been minimized.

Copy link
@cebe

cebe Aug 18, 2015

Member

XmlParser vs. XMLFormatter, should be consistent. Framework uses Xml so that should be used here too.

This comment has been minimized.

Copy link
@klimov-paul

klimov-paul Aug 19, 2015

Author Member

Fixed: eaec296

];

if (!isset($this->parsers[$format])) {
Expand Down
4 changes: 2 additions & 2 deletions TransportCurl.php → CurlTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Yii;

/**
* TransportCurl sends HTTP messages using [Client URL Library (cURL)](http://php.net/manual/en/book.curl.php)
* CurlTransport sends HTTP messages using [Client URL Library (cURL)](http://php.net/manual/en/book.curl.php)
*
* Note: this transport requires PHP 'curl' extension installed.
*
Expand All @@ -20,7 +20,7 @@
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class TransportCurl extends Transport
class CurlTransport extends Transport
{
/**
* @inheritdoc
Expand Down
4 changes: 2 additions & 2 deletions FormatterJson.php → JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
use yii\helpers\Json;

/**
* FormatterJson formats HTTP message as JSON.
* JsonFormatter formats HTTP message as JSON.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class FormatterJson extends Object implements FormatterInterface
class JsonFormatter extends Object implements FormatterInterface
{
/**
* @var integer the encoding options.For more details please refer to
Expand Down
4 changes: 2 additions & 2 deletions ParserJson.php → JsonParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
use yii\helpers\Json;

/**
* ParserJson parses HTTP message content as JSON.
* JsonParser parses HTTP message content as JSON.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class ParserJson extends Object implements ParserInterface
class JsonParser extends Object implements ParserInterface
{
/**
* @inheritdoc
Expand Down
4 changes: 2 additions & 2 deletions TransportStream.php → StreamTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
use Yii;

/**
* TransportStream sends HTTP messages using [Streams](http://php.net/manual/en/book.stream.php)
* StreamTransport sends HTTP messages using [Streams](http://php.net/manual/en/book.stream.php)
*
* For this transport, you may setup request options using [Context Options](http://php.net/manual/en/context.php)
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class TransportStream extends Transport
class StreamTransport extends Transport
{
/**
* @inheritdoc
Expand Down
4 changes: 2 additions & 2 deletions FormatterUrlEncoded.php → UrlEncodedFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use yii\base\Object;

/**
* FormatterUrlEncoded formats HTTP message as 'application/x-www-form-urlencoded'.
* UrlEncodedFormatter formats HTTP message as 'application/x-www-form-urlencoded'.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class FormatterUrlEncoded extends Object implements FormatterInterface
class UrlEncodedFormatter extends Object implements FormatterInterface
{
/**
* @var integer URL encoding type.
Expand Down
4 changes: 2 additions & 2 deletions ParserUrlEncoded.php → UrlEncodedParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use yii\base\Object;

/**
* ParserUrlEncoded parses HTTP message content as 'application/x-www-form-urlencoded'.
* UrlEncodedParser parses HTTP message content as 'application/x-www-form-urlencoded'.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class ParserUrlEncoded extends Object implements ParserInterface
class UrlEncodedParser extends Object implements ParserInterface
{
/**
* @inheritdoc
Expand Down
4 changes: 2 additions & 2 deletions FormatterXml.php → XmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use yii\helpers\StringHelper;

/**
* FormatterXml formats HTTP message as XML.
* XmlFormatter formats HTTP message as XML.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class FormatterXml extends Object implements FormatterInterface
class XmlFormatter extends Object implements FormatterInterface
{
/**
* @var string the Content-Type header for the response
Expand Down
4 changes: 2 additions & 2 deletions ParserXml.php → XmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use yii\base\Object;

/**
* ParserXml parses HTTP message content as XML.
* XmlParser parses HTTP message content as XML.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class ParserXml extends Object implements ParserInterface
class XmlParser extends Object implements ParserInterface
{
/**
* @inheritdoc
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/usage-logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ return [
[
'class' => 'yii\log\FileTarget',
'logFile' => '@runtime/logs/http-request.log',
'categories' => ['yii\httpclient\Transport*'],
'categories' => ['yii\httpclient\*'],
],
// ...
],
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/usage-request-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ $response = $client->createRequest()
options for request.

You may as well pass options, which are specific for particular request transport. Usually it comes to this
in case of using [[\yii\httpclient\TransportCurl]]. For example: you may want to specify separated timeout
in case of using [[\yii\httpclient\CurlTransport]]. For example: you may want to specify separated timeout
for connection and receiving data, which supported by PHP cURL library. You can do this in following way:

```php
use yii\httpclient\Client;

$client = new Client([
'transport' => 'yii\httpclient\TransportCurl' // only cURL supports the options we need
'transport' => 'yii\httpclient\CurlTransport' // only cURL supports the options we need
]);

$response = $client->createRequest()
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/usage-transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Transports
[[\yii\httpclient\Client]] provides several different ways to actually send an HTTP message - several transports.
Predefined transports are:

- [[\yii\httpclient\TransportStream]] - sends HTTP messages using [Streams](http://php.net/manual/en/book.stream.php).
- [[\yii\httpclient\StreamTransport]] - sends HTTP messages using [Streams](http://php.net/manual/en/book.stream.php).
This transport is used by default. It does not require any additional PHP extensions or libraries installed,
but does not support advanced features like batch sending.
- [[\yii\httpclient\TransportCurl]] - sends HTTP messages using [Client URL Library (cURL)](http://php.net/manual/en/book.curl.php)
- [[\yii\httpclient\CurlTransport]] - sends HTTP messages using [Client URL Library (cURL)](http://php.net/manual/en/book.curl.php)
This transport requires PHP 'curl' extension to be installed, but provides support for advanced features, like
batch sending.

Expand All @@ -17,7 +17,7 @@ You may configure the transport to be used by particular client using [[\yii\htt
use yii\httpclient\Client;

$client = new Client([
'transport' => 'yii\httpclient\TransportCurl'
'transport' => 'yii\httpclient\CurlTransport'
]);
```

Expand Down
60 changes: 30 additions & 30 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
namespace yiiunit\extensions\httpclient;

use yii\httpclient\Client;
use yii\httpclient\FormatterJson;
use yii\httpclient\FormatterUrlEncoded;
use yii\httpclient\FormatterXml;
use yii\httpclient\ParserJson;
use yii\httpclient\ParserUrlEncoded;
use yii\httpclient\ParserXml;
use yii\httpclient\JsonFormatter;
use yii\httpclient\UrlEncodedFormatter;
use yii\httpclient\XmlFormatter;
use yii\httpclient\JsonParser;
use yii\httpclient\UrlEncodedParser;
use yii\httpclient\XmlParser;
use yii\httpclient\Request;
use yii\httpclient\Response;
use yii\httpclient\Transport;
use yii\httpclient\TransportCurl;
use yii\httpclient\CurlTransport;

class ClientTest extends TestCase
{
public function testSetupFormatters()
{
$client = new Client();
$client->formatters = [
'testString' => FormatterUrlEncoded::className(),
'testString' => UrlEncodedFormatter::className(),
'testConfig' => [
'class' => FormatterUrlEncoded::className(),
'class' => UrlEncodedFormatter::className(),
'encodingType' => PHP_QUERY_RFC3986
],
];

$formatter = $client->getFormatter('testString');
$this->assertTrue($formatter instanceof FormatterUrlEncoded);
$this->assertTrue($formatter instanceof UrlEncodedFormatter);

$formatter = $client->getFormatter('testConfig');
$this->assertTrue($formatter instanceof FormatterUrlEncoded);
$this->assertTrue($formatter instanceof UrlEncodedFormatter);
$this->assertEquals(PHP_QUERY_RFC3986, $formatter->encodingType);
}

Expand All @@ -42,10 +42,10 @@ public function testSetupFormatters()
public function dataProviderDefaultFormatters()
{
return [
[Client::FORMAT_JSON, FormatterJson::className()],
[Client::FORMAT_URLENCODED, FormatterUrlEncoded::className()],
[Client::FORMAT_RAW_URLENCODED, FormatterUrlEncoded::className()],
[Client::FORMAT_XML, FormatterXml::className()],
[Client::FORMAT_JSON, JsonFormatter::className()],
[Client::FORMAT_URLENCODED, UrlEncodedFormatter::className()],
[Client::FORMAT_RAW_URLENCODED, UrlEncodedFormatter::className()],
[Client::FORMAT_XML, XmlFormatter::className()],
];
}

Expand All @@ -71,27 +71,27 @@ public function testOverrideDefaultFormatter()
{
$client = new Client();
$client->formatters = [
Client::FORMAT_JSON => FormatterUrlEncoded::className(),
Client::FORMAT_JSON => UrlEncodedFormatter::className(),
];
$formatter = $client->getFormatter(Client::FORMAT_JSON);
$this->assertTrue($formatter instanceof FormatterUrlEncoded);
$this->assertTrue($formatter instanceof UrlEncodedFormatter);
}

public function testSetupParsers()
{
$client = new Client();
$client->parsers = [
'testString' => ParserUrlEncoded::className(),
'testString' => UrlEncodedParser::className(),
'testConfig' => [
'class' => ParserUrlEncoded::className(),
'class' => UrlEncodedParser::className(),
],
];

$parser = $client->getParser('testString');
$this->assertTrue($parser instanceof ParserUrlEncoded);
$this->assertTrue($parser instanceof UrlEncodedParser);

$parser = $client->getParser('testConfig');
$this->assertTrue($parser instanceof ParserUrlEncoded);
$this->assertTrue($parser instanceof UrlEncodedParser);
}

/**
Expand All @@ -101,10 +101,10 @@ public function testSetupParsers()
public function dataProviderDefaultParsers()
{
return [
[Client::FORMAT_JSON, ParserJson::className()],
[Client::FORMAT_URLENCODED, ParserUrlEncoded::className()],
[Client::FORMAT_RAW_URLENCODED, ParserUrlEncoded::className()],
[Client::FORMAT_XML, ParserXml::className()],
[Client::FORMAT_JSON, JsonParser::className()],
[Client::FORMAT_URLENCODED, UrlEncodedParser::className()],
[Client::FORMAT_RAW_URLENCODED, UrlEncodedParser::className()],
[Client::FORMAT_XML, XmlParser::className()],
];
}

Expand All @@ -130,24 +130,24 @@ public function testOverrideDefaultParser()
{
$client = new Client();
$client->parsers = [
Client::FORMAT_JSON => ParserUrlEncoded::className(),
Client::FORMAT_JSON => UrlEncodedParser::className(),
];

$parser = $client->getParser(Client::FORMAT_JSON);
$this->assertTrue($parser instanceof ParserUrlEncoded);
$this->assertTrue($parser instanceof UrlEncodedParser);
}

public function testSetupTransport()
{
$client = new Client();

$transport = new TransportCurl();
$transport = new CurlTransport();
$client->setTransport($transport);
$this->assertSame($transport, $client->getTransport());

$client->setTransport(TransportCurl::className());
$client->setTransport(CurlTransport::className());
$transport = $client->getTransport();
$this->assertTrue($transport instanceof TransportCurl);
$this->assertTrue($transport instanceof CurlTransport);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/TransportCurlTest.php → tests/CurlTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace yiiunit\extensions\httpclient;

use yii\httpclient\TransportCurl;
use yii\httpclient\CurlTransport;

/**
* @group curl
*/
class TransportCurlTest extends TransportTestCase
class CurlTransportTest extends TransportTestCase
{
/**
* @inheritdoc
*/
protected function transport()
{
return TransportCurl::className();
return CurlTransport::className();
}
}
Loading

0 comments on commit 1e2f4fb

Please sign in to comment.