Commit 385d80db authored by shajiaiming's avatar shajiaiming

引用curl

parent dc60edee
......@@ -8,7 +8,7 @@
namespace common\service\exchange;
use common\helpers\Curl;
use linslin\yii2\curl\Curl;
use Yii;
class Bitfinex extends Exchange implements ExchangeInterface
......@@ -32,7 +32,8 @@ class Bitfinex extends Exchange implements ExchangeInterface
public function setSupportedSymbol()
{
$result = $this->ch->get('https://api.bitfinex.com/v1/symbols', false);
$curl = new Curl();
$result = $curl->get('https://api.bitfinex.com/v1/symbols');
if ($result) {
foreach ($result as $item) {
$this->redis->sadd($this->supported_symbol, 't' . strtoupper($item));
......@@ -44,7 +45,8 @@ class Bitfinex extends Exchange implements ExchangeInterface
{
$symbols = $this->redis->smembers($this->supported_symbol);
$query = '?symbols=' . implode(',', $symbols);
$res = $this->ch->get('https://api.bitfinex.com/v2/tickers' . $query, false);
$curl = new Curl();
$res = $curl->get('https://api.bitfinex.com/v2/tickers' . $query);
if(false == $res){
return;
}
......
......@@ -9,7 +9,7 @@
namespace common\service\exchange;
use Yii;
use linslin\yii2\curl\Curl;
class Bittrex extends Exchange implements ExchangeInterface
{
......@@ -24,7 +24,8 @@ class Bittrex extends Exchange implements ExchangeInterface
public function setSupportedSymbol()
{
$api = 'https://bittrex.com/api/v1.1/public/getmarkets';
$rev = $this->ch->get($api, false);
$curl = new Curl();
$rev = $curl->get($api);
if ($rev && $rev['success']) {
$lists = $rev['result'];
foreach ($lists as $item) {
......@@ -36,7 +37,8 @@ class Bittrex extends Exchange implements ExchangeInterface
public function setQuotation()
{
$api = 'https://bittrex.com/api/v1.1/public/getmarketsummaries';
$rev = $this->ch->get($api, false);
$curl = new Curl();
$rev = $curl->get($api, false);
if ($rev && $rev['success']) {
$lists = $rev['result'];
foreach ($lists as $item) {
......
......@@ -8,6 +8,8 @@
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Bty extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_bty';
......@@ -44,8 +46,9 @@ class Bty extends Exchange implements ExchangeInterface
public function setQuotation()
{
$platforms = ['HKJB', 'BB360'];
$curl = new Curl();
foreach($platforms as $platform) {
$content = $this->ch->get($this->base_url . $platform, false);
$content = $curl->get($this->base_url . $platform);
if (is_array($content) && isset($content['code']) && $content['code'] == 200) {
$data = $content['data']['USDT'];
foreach ($data as $item) {
......
......@@ -8,7 +8,7 @@
namespace common\service\exchange;
use common\helpers\Curl;
use linslin\yii2\curl\Curl;
use Yii;
class Hadax extends HuoBi
......@@ -19,8 +19,9 @@ class Hadax extends HuoBi
public function setSupportedSymbol()
{
$curl = new Curl();
$api = $this->base_url . '/v1/hadax/common/symbols';
$res = $this->ch->get($api, false);//json
$res = $curl->get($api);//json
if ($res && $res['status'] == 'ok') {
$data = $res['data'];
foreach ($data as $item) {
......
......@@ -9,7 +9,7 @@
namespace common\service\exchange;
use Yii;
use common\helpers\Curl;
use linslin\yii2\curl\Curl;
class HuoBi extends Exchange implements ExchangeInterface
{
......@@ -25,7 +25,8 @@ class HuoBi extends Exchange implements ExchangeInterface
public function setSupportedSymbol()
{
$api = $this->base_url . '/v1/common/symbols';
$res = $this->ch->get($api, false);//json
$curl = new Curl();
$res = $curl->get($api);//json
if ($res && $res['status'] == 'ok') {
$data = $res['data'];
foreach ($data as $item) {
......@@ -38,7 +39,8 @@ class HuoBi extends Exchange implements ExchangeInterface
public function setQuotation()
{
$api = $this->base_url . '/market/tickers';
$res = $this->ch->get($api, false);
$curl = new Curl();
$res = $curl->get($api, false);
if ($res && $res['status'] == 'ok') {
$datas = $res['data'];
foreach ($datas as $item) {
......
......@@ -8,6 +8,8 @@
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Token7 extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_token7';
......@@ -52,36 +54,8 @@ class Token7 extends Exchange implements ExchangeInterface
*/
public function setQuotation()
{
$content = $this->ch->get($this->base_url, false);
$content = [
"date" => "2019-03-27 14:28:08",
"ticker" => [
[
"symbol"=>"GM_HA",
"vol"=>"759301.65",
"high"=>"2.608",
"last"=>"2.607",
"low"=>"2.607",
"sell"=>"2.615",
"buy"=>"2.613",
"yesterdayPrice"=>"2.609",
"change"=>"-0.077",
"lastExchangPrice"=>"2.608"
],
[
"symbol"=>"BSTC_HA",
"vol"=>"321550.59",
"high"=>"0.029",
"last"=>"0.029",
"low"=>"0.029",
"sell"=>"0.029",
"buy"=>"0.028",
"yesterdayPrice"=>"0.027",
"change"=>"7.407",
"lastExchangPrice"=>"0.029"]
]
];
$curl = new Curl();
$content = $curl->get($this->base_url);
if (is_array($content) && isset($content['date']) && isset($content['ticker'])) {
$data = $content['ticker'];
foreach ($data as $item) {
......
......@@ -8,6 +8,8 @@
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
/**
* Class Zb
* api document:https://www.zb.com/i/developer/restApi#market
......@@ -26,7 +28,8 @@ class Zb extends Exchange implements ExchangeInterface
public function setSupportedSymbol()
{
$api = "http://api.zb.com/data/v1/markets";
$rev = $this->ch->get($api, false);
$curl = new Curl();
$rev = $curl->get($api);
if ($rev) {
$keys = array_keys($rev);
foreach ($keys as $key) {
......@@ -38,7 +41,8 @@ class Zb extends Exchange implements ExchangeInterface
public function setQuotation()
{
$api = 'http://api.zb.com/data/v1/allTicker';
$rev = $this->ch->get($api, false);
$curl = new Curl();
$rev = $curl->get($api);
if ($rev) {
foreach ($rev as $key => $item) {
$this->redis->hmset($this->quotation_prefix . $key, 'low', $item['low'], 'high', $item['high'], 'last',
......
......@@ -20,7 +20,8 @@
"kartik-v/yii2-date-range": "*",
"kartik-v/yii2-widget-fileinput": "*",
"yiisoft/yii2-redis": "~2.0.0",
"yiisoft/yii2-queue": "~2.0"
"yiisoft/yii2-queue": "~2.0",
"linslin/yii2-curl": "*"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
......
This diff is collapsed.
......@@ -279,7 +279,7 @@ class ClassLoader
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
......@@ -377,7 +377,7 @@ class ClassLoader
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\';
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
......
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Composer
Upstream-Contact: Jordi Boggiano <j.boggiano@seld.be>
Source: https://github.com/composer/composer
Files: *
Copyright: 2016, Nils Adermann <naderman@naderman.de>
2016, Jordi Boggiano <j.boggiano@seld.be>
License: Expat
Copyright (c) Nils Adermann, Jordi Boggiano
Files: src/Composer/Util/TlsHelper.php
Copyright: 2016, Nils Adermann <naderman@naderman.de>
2016, Jordi Boggiano <j.boggiano@seld.be>
2013, Evan Coury <me@evancoury.com>
License: Expat and BSD-2-Clause
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
License: BSD-2-Clause
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
License: Expat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
......@@ -10,7 +10,7 @@ return array(
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'180092cfc969a12e06f2132a203a3184' => $vendorDir . '/codeception/verify/src/Codeception/function.php',
'6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
'180092cfc969a12e06f2132a203a3184' => $vendorDir . '/codeception/verify/src/Codeception/function.php',
);
......@@ -25,6 +25,7 @@ return array(
'yii\\bootstrap\\' => array($vendorDir . '/yiisoft/yii2-bootstrap/src'),
'yii\\' => array($vendorDir . '/yiisoft/yii2'),
'phpDocumentor\\Reflection\\' => array($vendorDir . '/phpdocumentor/reflection-common/src', $vendorDir . '/phpdocumentor/reflection-docblock/src', $vendorDir . '/phpdocumentor/type-resolver/src'),
'linslin\\yii2\\curl\\' => array($vendorDir . '/linslin/yii2-curl'),
'kartik\\widgets\\' => array($vendorDir . '/kartik-v/yii2-widgets'),
'kartik\\typeahead\\' => array($vendorDir . '/kartik-v/yii2-widget-typeahead'),
'kartik\\touchspin\\' => array($vendorDir . '/kartik-v/yii2-widget-touchspin'),
......
......@@ -11,9 +11,9 @@ class ComposerStaticInit33057934f3e7eaaa1ce2d53797277936
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php',
'180092cfc969a12e06f2132a203a3184' => __DIR__ . '/..' . '/codeception/verify/src/Codeception/function.php',
'6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php',
'180092cfc969a12e06f2132a203a3184' => __DIR__ . '/..' . '/codeception/verify/src/Codeception/function.php',
);
public static $prefixLengthsPsr4 = array (
......@@ -42,6 +42,10 @@ class ComposerStaticInit33057934f3e7eaaa1ce2d53797277936
array (
'phpDocumentor\\Reflection\\' => 25,
),
'l' =>
array (
'linslin\\yii2\\curl\\' => 18,
),
'k' =>
array (
'kartik\\widgets\\' => 15,
......@@ -203,6 +207,10 @@ class ComposerStaticInit33057934f3e7eaaa1ce2d53797277936
1 => __DIR__ . '/..' . '/phpdocumentor/reflection-docblock/src',
2 => __DIR__ . '/..' . '/phpdocumentor/type-resolver/src',
),
'linslin\\yii2\\curl\\' =>
array (
0 => __DIR__ . '/..' . '/linslin/yii2-curl',
),
'kartik\\widgets\\' =>
array (
0 => __DIR__ . '/..' . '/kartik-v/yii2-widgets',
......
......@@ -72,8 +72,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twbs/bootstrap/zipball/0b9c4a4007c44201dce9a6cc1a38407005c26c86",
"reference": "0b9c4a4007c44201dce9a6cc1a38407005c26c86",
"shasum": null
"reference": "0b9c4a4007c44201dce9a6cc1a38407005c26c86"
},
"require": {
"bower-asset/jquery": ">=1.9.1,<4.0"
......@@ -96,8 +95,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/14873e5775964275d13621cbe2b52e4448af3707",
"reference": "14873e5775964275d13621cbe2b52e4448af3707",
"shasum": null
"reference": "14873e5775964275d13621cbe2b52e4448af3707"
},
"require": {
"bower-asset/jquery": ">=1.7"
......@@ -120,8 +118,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jquery/jquery-dist/zipball/77d2a51d0520d2ee44173afdf4e40a9201f5964e",
"reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e",
"shasum": null
"reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e"
},
"type": "bower-asset",
"installation-source": "dist",
......@@ -141,8 +138,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3",
"reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3",
"shasum": null
"reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3"
},
"type": "bower-asset",
"installation-source": "dist"
......@@ -159,8 +155,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twitter/typeahead.js/zipball/588440f66559714280628a4f9799f0c4eb880a4a",
"reference": "588440f66559714280628a4f9799f0c4eb880a4a",
"shasum": null
"reference": "588440f66559714280628a4f9799f0c4eb880a4a"
},
"require": {
"bower-asset/jquery": ">=1.7"
......@@ -180,8 +175,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/aef7b953107264f00234902a3880eb50dafc48be",
"reference": "aef7b953107264f00234902a3880eb50dafc48be",
"shasum": null
"reference": "aef7b953107264f00234902a3880eb50dafc48be"
},
"require": {
"bower-asset/jquery": ">=1.8"
......@@ -2238,6 +2232,60 @@
]
},
{
"name": "linslin/yii2-curl",
"version": "1.3.0",
"version_normalized": "1.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/linslin/Yii2-Curl.git",
"reference": "734c40b520729c79af2937283864f8c999e86879"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/linslin/Yii2-Curl/zipball/734c40b520729c79af2937283864f8c999e86879",
"reference": "734c40b520729c79af2937283864f8c999e86879",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"yiisoft/yii2": "*"
},
"require-dev": {
"codeception/base": "^2.2.3",
"codeception/specify": "~0.4.3",
"codeception/verify": "~0.3.1",
"codeclimate/php-test-reporter": "dev-master",
"guzzlehttp/guzzle": ">=4.1.4 <7.0",
"mcustiel/phiremock-codeception-extension": "1.2.4"
},
"time": "2019-02-25T10:56:34+00:00",
"type": "yii2-extension",
"installation-source": "dist",
"autoload": {
"psr-4": {
"linslin\\yii2\\curl\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nils Gajsek",
"email": "info@linslin.org"
}
],
"description": "Easy and nice cURL extension with RESTful support for Yii2",
"keywords": [
" curl",
"extension",
"restful",
"yii2"
]
},
{
"name": "myclabs/deep-copy",
"version": "1.8.1",
"version_normalized": "1.8.1.0",
......@@ -3053,7 +3101,8 @@
"keywords": [
"mock",
"xunit"
]
],
"abandoned": true
},
{
"name": "psr/http-message",
......
vendor/
\ No newline at end of file
language: php
php:
- '7.1.3'
branches:
only:
- master
- develop
install:
- composer install
script:
- vendor/bin/codecept run --coverage-xml ./../../build/logs/clover.xml
addons:
code_climate:
repo_token: 24b886eb6df6abd48cb812de2c20b9311d0444f30043bdf4d254116e5225ed84
after_success:
- vendor/bin/test-reporter
\ No newline at end of file
This diff is collapsed.
yii2-curl extension
===================
[![Latest Stable Version](https://poser.pugx.org/linslin/yii2-curl/v/stable)](https://packagist.org/packages/linslin/yii2-curl)
[![Latest Master Build](https://api.travis-ci.org/linslin/Yii2-Curl.svg?branch=master)](https://travis-ci.org/linslin/Yii2-Curl/builds)
[![Test Coverage](https://codeclimate.com/github/linslin/Yii2-Curl/badges/coverage.svg)](https://codeclimate.com/github/linslin/Yii2-Curl/coverage)
[![Total Downloads](https://poser.pugx.org/linslin/yii2-curl/downloads)](https://packagist.org/packages/linslin/yii2-curl)
[![License](https://poser.pugx.org/linslin/yii2-curl/license)](https://packagist.org/packages/linslin/yii2-curl)
Easy working cURL extension for Yii2, including RESTful support:
- POST
- GET
- HEAD
- PUT
- PATCH
- DELETE
Requirements
------------
- Yii2
- PHP >=7.1.3
- ext-curl, ext-json, and php-curl installed
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
```bash
php composer.phar require --prefer-dist linslin/yii2-curl "*"
```
Usage
-----
Once the extension is installed, simply use it in your code. The following example shows you how to handling a simple GET Request.
```php
use linslin\yii2\curl;
$curl = new curl\Curl();
//get http://example.com/
$response = $curl->get('http://example.com/');
if ($curl->errorCode === null) {
echo $response;
} else {
// List of curl error codes here https://curl.haxx.se/libcurl/c/libcurl-errors.html
switch ($curl->errorCode) {
case 6:
//host unknown example
break;
}
}
```
```php
// GET request with GET params
// http://example.com/?key=value&scondKey=secondValue
$curl = new curl\Curl();
$response = $curl->setGetParams([
'key' => 'value',
'secondKey' => 'secondValue'
])
->get('http://example.com/');
```
```php
// POST URL form-urlencoded
$curl = new curl\Curl();
$response = $curl->setPostParams([
'key' => 'value',
'secondKey' => 'secondValue'
])
->post('http://example.com/');
```
```php
// POST RAW JSON
$curl = new curl\Curl();
$response = $curl->setRawPostData(
json_encode[
'key' => 'value',
'secondKey' => 'secondValue'
])
->post('http://example.com/');
```
```php
// POST RAW JSON and auto decode JSON respawn by setting raw = true.
// This is usefull if you expect an JSON response and want to autoparse it.
$curl = new curl\Curl();
$response = $curl->setRawPostData(
json_encode[
'key' => 'value',
'secondKey' => 'secondValue'
])
->post('http://example.com/', true);
// JSON decoded response by parsing raw = true in to ->post().
var_dump($response);
```
```php
// POST RAW XML
$curl = new curl\Curl();
$response = $curl->setRawPostData('<?xml version="1.0" encoding="UTF-8"?><someNode>Test</someNode>')
->post('http://example.com/');
```
```php
// POST with special headers
$curl = new curl\Curl();
$response = $curl->setPostParams([
'key' => 'value',
'secondKey' => 'secondValue'
])
->setHeaders([
'Custom-Header' => 'user-b'
])
->post('http://example.com/');
```
```php
// POST JSON with body string & special headers
$curl = new curl\Curl();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$response = $curl->setRequestBody(json_encode($params))
->setHeaders([
'Content-Type' => 'application/json',
'Content-Length' => strlen(json_encode($params))
])
->post('http://example.com/');
```
```php
// Avanced POST request with curl options & error handling
$curl = new curl\Curl();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$response = $curl->setRequestBody(json_encode($params))
->setOption(CURLOPT_ENCODING, 'gzip')
->post('http://example.com/');
// List of status codes here http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
switch ($curl->responseCode) {
case 'timeout':
//timeout error logic here
break;
case 200:
//success logic here
break;
case 404:
//404 Error logic here
break;
}
//list response headers
var_dump($curl->responseHeaders);
```
Testing
------------
- Run codeception tests with `vendor/bin/codecept run` in repository root dir.
On windows run `vendor\bin\codecept.bat run`.
Changelog
------------
##### Release 1.3.0 - Changelog
- Fixed HTTP-Method parsing on PATCH request.
- Updated DocBlocks + code refactoring.
- Removed deprecated PHP Version support. Minimum PHP Version is now 7.1.3.
Please use version "linslin/yii2-curl 1.2.1" - https://github.com/linslin/Yii2-Curl/releases/tag/1.2.1 if you need PHP 5.4+ support.
##### Release 1.2.2 - Changelog
- Added some new cURL examples into readme.md.
##### Release 1.2.1 - Changelog
- Added `setRawPostData([mixed]) [this]` which allows you to post any data format.
##### Release 1.2.0 - Changelog
- Added `unsetHeader([string header]) [this]` helper which allows you to unset one specific header.
- Added `setHeader([string header, string value]) [this]` helper which allows you to set one specific header.
- Added `getRequestHeaders() [array]` helper which returns all request headers as an array.
- Added `getRequestHeader([string headerKey]) [string|null]` helper which returns a specific request header as an string.
- Added new test cases for `getRequestHeaders()` and `getRequestHeader()`.
- Readme adjustments.
##### Release 1.1.3 - Changelog
- Fixed issue with patch request.
- Fully added functionalTests for 100% coverage.
##### Release 1.1.2 - Changelog
- Fixed https://github.com/linslin/Yii2-Curl/issues/59
- Fixed https://github.com/linslin/Yii2-Curl/issues/57
##### Release 1.1.1 - Changelog
- Fixed wrong parameter parsing into `_httpRequest()` (thanks to yemexx1)
- Added JSON decode functions tests (thanks to yemexx1)
##### Release 1.1.0 - Changelog
- Added `setHeaders() [array]` helper.
- Added `setPostParams() [array]` helper.
- Added `setGetParams() [array]` helper.
- Added `setRequestBody() [string]` helper.
- Added `getUrl()` helper.
- Added API attribute `errorText [string|null]` - holds a string describing the given error code - https://github.com/linslin/Yii2-Curl/issues/49.
- Added functionTests to ensure stability.
- Allow PHP class goodness - https://github.com/linslin/Yii2-Curl/issues/52.
- Fixed header explode - https://github.com/linslin/Yii2-Curl/pull/51.
##### Release 1.0.11 - Changelog
- Added API attribute `responseHeaders [array|null]` which returns an array of all response headers.
- Changed `_defaultOptions[CURLOPT_HEADER]` to `true`.
- Profile debugging is only active if constant `YII_DEBUG` is `true`.
##### Release 1.0.10 - Changelog
- Fixed PHP notice https://github.com/linslin/Yii2-Curl/issues/39.
##### Release 1.0.9 - Changelog
- Added API attribute `responseCode [string|null]` which holds the HTTP response code.
- Added API attribute `responseCharset [string|null]` which holds the response charset.
- Added API attribute `responseLength [integer|null]` which holds the response length.
- Added API attribute `errorCode` which holds the a integer code error like described here: https://curl.haxx.se/libcurl/c/libcurl-errors.html.
- Fixed Issue https://github.com/linslin/Yii2-Curl/issues//36.
- Fixed Issue https://github.com/linslin/Yii2-Curl/issues//37 and removed exception throwing on curl fail. This allow the user to handle the error while using attribute `errorCode`.
##### Release 1.0.8 - Changelog
- Added API method `setOptions([array])` which allows to setup multiple options at once.
- Fixed Issue https://github.com/linslin/Yii2-Curl/issues/30.
##### Release 1.0.7 - Changelog
- Fixed `getInfo([, int $opt = 0 ])` exception were cURL wasn't initialized before calling `getInfo($opt)`.
##### Release 1.0.6 - Changelog
- Added `getInfo([, int $opt = 0 ])` method to retrieve http://php.net/manual/de/function.curl-getinfo.php data.
##### Release 1.0.5 - Changelog
- Made `body` callback not depending on HTTP-Status codes anymore. You can retrieve `body` data on any HTTP-Status now.
- Fixed Issue https://github.com/linslin/Yii2-Curl/issues/19 where override default settings break options.
- Added timeout response handling. `$curl->responseCode = 'timeout'`
##### Release 1.0.4 - Changelog
- `CURLOPT_RETURNTRANSFER` is now set to true on default - https://github.com/linslin/Yii2-Curl/issues/18
- Readme.md adjustments.
##### Release 1.0.3 - Changelog
- Fixed override of user options. https://github.com/linslin/Yii2-Curl/pull/7
- Nice formatted PHP-examples.
- Moved `parent::init();` behavior into unitTest Controller.
##### Release 1.0.2 - Changelog
- Added custom params support
- Added custom status code support
- Added POST-Param support and a readme example
- Removed "body" support at request functions. Please use "CURLOPT_POSTFIELDS" to setup a body now.
- Readme modifications
##### Release 1.0.1 - Changelog
- Removed widget support
- Edited some spellings + added more examples into readme.md
##### Release 1.0 - Changelog
- Official stable release
\ No newline at end of file
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
coverage:
enabled: true
include:
- Curl.php
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
- Codeception\Extension\Phiremock
config:
Codeception\Extension\Phiremock:
listen: 127.0.0.1:18080 # defaults to 0.0.0.0:8086
bin_path: vendor/bin # defaults to codeception_dir/../vendor/bin
debug: true # defaults to false
startDelay: 1 # default to 0
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
{
"name": "linslin/yii2-curl",
"description": "Easy and nice cURL extension with RESTful support for Yii2",
"type": "yii2-extension",
"keywords": ["yii2","extension"," curl", "RESTful"],
"license": "MIT",
"authors": [
{
"name": "Nils Gajsek",
"email": "info@linslin.org"
}
],
"require": {
"ext-json": "*",
"ext-curl": "*",
"yiisoft/yii2": "*"
},
"require-dev": {
"codeception/base": "^2.2.3",
"codeception/verify": "~0.3.1",
"codeception/specify": "~0.4.3",
"guzzlehttp/guzzle": ">=4.1.4 <7.0",
"mcustiel/phiremock-codeception-extension": "1.2.4",
"codeclimate/php-test-reporter": "dev-master"
},
"autoload": {
"psr-4": {
"linslin\\yii2\\curl\\": ""
}
}
}
<?php
/**
* Minimal Yii2 setup for test environment
*/
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
\ No newline at end of file
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
}
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Functional extends \Codeception\Module
{
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
}
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
<?php //[STAMP] c3f973d7d565ef23c473f5d8c511c70d
namespace _generated;
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile
trait AcceptanceTesterActions
{
/**
* @return \Codeception\Scenario
*/
abstract protected function getScenario();
}
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
class_name: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
<?php
// Here you can initialize variables that will be available to your tests
# Codeception Test Suite Configuration
#
# Suite for functional (integration) tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- \Helper\Functional
- Asserts
- Phiremock:
host: 127.0.0.1
port: 18080
<?php
// Here you can initialize variables that will be available to your tests
This diff is collapsed.
# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.
class_name: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit
\ No newline at end of file
<?php
/**
* Class CurlTest
*/
class CurlTest extends \Codeception\Test\Unit
{
// ################################################### Class methods ###############################################
/**
* No sense test
*/
public function testInit()
{
$curl = new linslin\yii2\curl\Curl();
expect($curl instanceof linslin\yii2\curl\Curl)->equals(true);
}
}
<?php
// Here you can initialize variables that will be available to your tests
......@@ -291,4 +291,13 @@ return array (
'@yii/queue/sqs' => $vendorDir . '/yiisoft/yii2-queue/src/drivers/sqs',
),
),
'linslin/yii2-curl' =>
array (
'name' => 'linslin/yii2-curl',
'version' => '1.3.0.0',
'alias' =>
array (
'@linslin/yii2/curl' => $vendorDir . '/linslin/yii2-curl',
),
),
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment