2017 © Pedro Peláez
 

yii2-extension yii2-curl

Easy and nice cURL extension with RESTful support for Yii2

image

skeeks/yii2-curl

Easy and nice cURL extension with RESTful support for Yii2

  • Monday, May 8, 2017
  • by skeeks-semenov
  • Repository
  • 1 Watchers
  • 3 Stars
  • 7,044 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

yii2-curl extension

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

  • POST
  • GET
  • HEAD
  • PUT
  • DELETE
  • PATCH
  • OPTIONS

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 skeeks/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., (*3)

<?php
/**
 * Yii2 test controller
 *
 * @category  Web-yii2-example
 * @package   yii2-curl-example
 * @license   http://opensource.org/licenses/MIT MIT Public
 *
 */

namespace app\controllers;

use yii\web\Controller;
use skeeks\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/');
    }


    /**
     * 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 200:
                //success logic here
                break;

            case 404:
                //404 Error logic here
                break;
        }
    }
}

The Versions

08/05 2017

dev-master

9999999-dev

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Semenov Alexander

extension yii2 restful curl

08/05 2017

1.1.0

1.1.0.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Semenov Alexander

extension yii2 restful curl

25/06 2015

1.0.1

1.0.1.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Semenov Alexander

extension yii2 restful curl

25/06 2015

1.0.2

1.0.2.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Semenov Alexander

extension yii2 restful curl

24/06 2015

1.0.0

1.0.0.0

Easy and nice cURL extension with RESTful support for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Semenov Alexander

extension yii2 restful curl