wernerdweight/curler-bundle

Symfony bundle wrapper for wernerdweight/curler.

1.1.0 2019-12-08 21:43 UTC

README

This bundle wraps Curler into Symfony Bundle.

Build Status Latest Stable Version Total Downloads License

Installation

  1. Download using composer
composer require wernerdweight/curler-bundle
  1. Enable the bundle

Enable the bundle in your kernel:

    <?php
    // config/bundles.php
    return [
        // ...
        WernerDweight\CurlerBundle\CurlerBundle::class => ['all' => true],
    ];
  1. Use in your project
use WernerDweight\Curler\Curler;
use WernerDweight\Curler\Request;

class MyService
{
    /** Curler */
    private $curler;
     
    /**
     * @param Curler $curler
     */
    public function __construct(Curler $curler)
    {
        $this->curler = $curler;
    }
    
    public function myAction(): void
    {
        $request = (new Request())
            ->setEndpoint('https://some-website.tld')
            ->setMethod('POST')
            ->setPayload(['key' => 'value'])
            ->setHeaders(['Accept: text/html', 'Accept-Encoding: gzip'])
            ->setAuthentication('user', 'password')
        ;
        $response = $this->curler->request($request);
        echo $response->text();  // '<html>...</html>'
        var_dump($response->getMetaData()); // array of response metadata (content-type, status...)
    }
}

License

This bundle is under the MIT license. See the complete license in the root directiory of the bundle.