2017 © Pedro Peláez
 

symfony-bundle curl-wrapper-bundle

Curl wrapper bundle

image

metaer/curl-wrapper-bundle

Curl wrapper bundle

  • Friday, January 12, 2018
  • by metaer
  • Repository
  • 1 Watchers
  • 1 Stars
  • 61 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 6 Open issues
  • 5 Versions
  • 9 % Grown

The README.md

Build Status, (*1)

Curl wrapper bundle

Curl Wrapper bundle for symfony framework
https://packagist.org/packages/metaer/curl-wrapper-bundle, (*2)

Installation

``` sh composer require metaer/curl-wrapper-bundle, (*3)


If you use Symfony 4+ with symfony flex - that's all</br> If you use Symfony 2 or 3 (without symfony flex), add to AppKernel.php: ``` php new \Metaer\CurlWrapperBundle\MetaerCurlWrapperBundle(),

Basic Usage

``` php $options = [ CURLOPT_URL => 'http://example.ex', CURLOPT_RETURNTRANSFER => true, ];, (*4)

$cw = $container->get('metaer_curl_wrapper.curl_wrapper');, (*5)

try { $result = $cw->getQueryResult($options); } catch (CurlWrapperException $e) { //handle exception }, (*6)


Basic usage with injection into your controller: --- ``` php MyController { /** * @var CurlWrapper */ private $curlWrapper; /** * MyController constructor. * @param CurlWrapper $curlWrapper */ public function __construct(CurlWrapper $curlWrapper) { $this->curlWrapper = $curlWrapper; } public function myAction() { $options = [ CURLOPT_URL => 'http://example.ex', CURLOPT_RETURNTRANSFER => true, ]; try { $this->curlWrapper->getQueryResult($options); } catch (CurlWrapperException $e) { //handle exception } return new Response('something'); } }

Basic usage with controllers action argument:

``` php MyController { public function myAction(CurlWrapper $curlWrapper) {
$options = [ CURLOPT_URL => 'http://example.ex', CURLOPT_RETURNTRANSFER => true, ];, (*7)

    try {
        $result = $curlWrapper->getQueryResult($options);
    } catch (CurlWrapperException $e) {
        //handle exception
    }

    return new Response('something');
}

}, (*8)


Basic Usage with autowire in another service: --- ``` php <?php namespace App\Service; use Metaer\CurlWrapperBundle\CurlWrapper; use Metaer\CurlWrapperBundle\CurlWrapperException; class MyService { /** * @var CurlWrapper */ private $curlWrapper; /** * MyService constructor. * @param CurlWrapper $curlWrapper */ public function __construct(CurlWrapper $curlWrapper) { $this->curlWrapper = $curlWrapper; } public function myMethod() { $options = [ CURLOPT_URL => 'http://example.ex', CURLOPT_RETURNTRANSFER => true, ]; try { $result = $this->curlWrapper->getQueryResult($options); } catch (CurlWrapperException $e) { //handle exception } } }

How simply change service behaviour or extend

Symfony-4 example ``` yaml, (*9)

config/packages/metaer_curl_wrapper.yaml

metaer_curl_wrapper: wrapper: custom_curl_wrapper, (*10)

``` yaml
# services.yaml
services:
    # your services
    #...

    custom_curl_wrapper:
        class: 'App\MyCurlWrapper'

``` php // src/MyCurlWrapper.php namespace App;, (*11)

use Metaer\CurlWrapperBundle\CurlWrapper;, (*12)

class MyCurlWrapper extends CurlWrapper { public function getQueryResult(array $curlOptions) { //your code here return 'something'; }, (*13)

public function myCustomMethod()
{
    //something else
}

}, (*14)


So, you do not need copy-paste full class code. Only methods which you want change.</br></br> Another way to do the same thing: ``` yaml # services.yaml services: # your services #... metaer_curl_wrapper.curl_wrapper: class: 'App\MyCurlWrapper'

Timeouts settings

$connectionTimeout = 8; //seconds
$serverResponseTimeout = 20; //seconds

$options = [
    CURLOPT_CONNECTTIMEOUT => $connectionTimeout,
    CURLOPT_TIMEOUT => $serverResponseTimeout,
];

$cw->getQueryResult($options);

See also

You can also use methods, (*15)

CurlWrapper::getResponseBody
CurlWrapper::getRequestBody
CurlWrapper::getRequestUrl

The Versions

12/01 2018

dev-master

9999999-dev https://github.com/metaer/curl-wrapper-bundle

Curl wrapper bundle

  Sources   Download

MIT

The Requires

 

by Pavel Popov

curl

12/01 2018

0.1.0

0.1.0.0 https://github.com/metaer/curl-wrapper-bundle

Curl wrapper bundle

  Sources   Download

MIT

The Requires

 

by Pavel Popov

curl

26/11 2017

1.0.2

1.0.2.0 https://github.com/metaer/curl-wrapper-bundle

Curl wrapper bundle

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Pavel Popov

curl

24/11 2017

1.0.0

1.0.0.0 https://github.com/metaer/curl-wrapper-bundle

Curl wrapper bundle

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Pavel Popov

curl

24/11 2017

1.0.1

1.0.1.0 https://github.com/metaer/curl-wrapper-bundle

Curl wrapper bundle

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Pavel Popov

curl