2017 © Pedro Peláez
 

yii2-extension yii2-curl-ext

Easy and nice cURL extension with RESTful support for Yii2

image

z010107/yii2-curl-ext

Easy and nice cURL extension with RESTful support for Yii2

  • Monday, April 18, 2016
  • by z010107
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 82 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

yii2-curl-ext extension

Cool working curl extension for Yii2, including RESTful support:, (*1)

  • POST
  • GET
  • HEAD
  • PUT
  • DELETE

Requirements

  • Yii2
  • PHP 5.4+
  • Curl and php-curl installed

Installation

The preferred way to install this extension is through composer., (*2)

php composer.phar require --prefer-dist z010107/yii2-curl-ext "*"

Usage

Once the extension is installed, simply use it in your code. The following example shows you how to handling a simple GET Request., (*3)

<?php
/**
 * Yii2 test controller
 *
 * @category  Web-yii2-example
 * @package   yii2-curl-example
 * @author    Nils Gajsek <info@linslin.org>
 * @author    Krasilnikov Andrey <z010107@gmail.com>
 * @copyright 2013-2015 Nils Gajsek<info@linslin.org>
 * @license   http://opensource.org/licenses/MIT MIT Public
 * @version   1.0.7
 * @link      http://www.linslin.org
 *
 */

namespace app\controllers;

use yii\web\Controller;
use linslin\yii2\curl;

class TestController extends Controller
{

    /**
     * Yii action controller
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }


    /**
     * cURL GET example
     */
    public function actionGetExample()
    {
        //Init curl
        $curl = new curl\Curl();

        //get http://example.com/
        $response = $curl->get('http://example.com/');

        //get http://example.com/ and get response headers
        $response = $curl->get('http://example.com/');
        $headers = $curl->getHeaders();
    }


    /**
     * cURL POST example with post body params.
     */
    public function actionPostExample()
    {
        //Init curl
        $curl = new curl\Curl();

        //post http://example.com/
        $response = $curl->setOption(
                CURLOPT_POSTFIELDS, 
                http_build_query(array(
                    'myPostField' => 'value'
                )
            ))
            ->post('http://example.com/');
    }


    /**
     * cURL multiple POST example one after one
     */
    public function actionMultipleRequest()
    {
        //Init curl
        $curl = new curl\Curl();


        //post http://example.com/
        $response = $curl->setOption(
            CURLOPT_POSTFIELDS, 
            http_build_query(array(
                'myPostField' => 'value'
                )
            ))
            ->post('http://example.com/');


        //post http://example.com/, reset request before
        $response = $curl->reset()
            ->setOption(
                CURLOPT_POSTFIELDS, 
                http_build_query(array(
                    'myPostField' => 'value'
                )
            ))
            ->post('http://example.com/');



    }


    /**
     * cURL advanced GET example with HTTP status codes
     */
    public function actionGetAdvancedExample()
    {
        //Init curl
        $curl = new curl\Curl();

        //get http://example.com/
        $response = $curl->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;
        }
    }


    /**
     * cURL timeout chaining/handling
     */
    public function actionHandleTimeoutExample()
    {
        //Init curl
        $curl = new curl\Curl();

        //get http://www.google.com:81/ -> timeout
        $response = $curl->post('http://www.google.com:81/');

        // 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;
        }
    }
}

Changelog

Release 1.1.0 - Changelog
  • Fixed getHeaders() pretty return array
Release 1.0.8 - Changelog
  • Added getHeaders() method to retrieve response headers
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

The Versions

18/04 2016

dev-master

9999999-dev

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

by Andrey Krasilnikov

extension yii2 restful curl

18/04 2016

1.1.0

1.1.0.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

by Andrey Krasilnikov

extension yii2 restful curl

18/04 2016

1.0.9

1.0.9.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

by Andrey Krasilnikov

extension yii2 restful curl

18/04 2016

1.0.8

1.0.8.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

by Andrey Krasilnikov

extension yii2 restful curl

21/12 2015

dev-develop

dev-develop

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

extension yii2 restful curl

21/12 2015

1.0.7

1.0.7.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

extension yii2 restful curl

21/12 2015

1.0.6

1.0.6.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

extension yii2 restful curl

27/10 2015

1.0.5

1.0.5.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

extension yii2 restful curl

07/05 2015

1.0.4

1.0.4.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

MIT

The Requires

 

extension yii2 restful curl

09/02 2015

1.0.3

1.0.3.0

Cool working cURL extension with RESTful support for Yii

  Sources   Download

MIT

The Requires

 

extension yii2 restful curl

27/12 2014

1.0.2

1.0.2.0

Cool working cURL extension with RESTful support for Yii

  Sources   Download

MIT

The Requires

 

extension yii2 restful curl

13/11 2014

1.0.1

1.0.1.0

Cool working cURL extension with RESTful support for Yii

  Sources   Download

MIT

The Requires

 

extension yii2 restful curl