wimski / curl
A simple wrapper for cURL to use with DI and OOP
1.0.0
2022-10-19 07:36 UTC
Requires
- php: ^8.1
- ext-curl: *
Requires (Dev)
- php-mock/php-mock-phpunit: ^2.6
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-19 11:48:35 UTC
README
cURL
A simple wrapper for cURL to use with DI and OOP.
Changelog
Install
composer require wimski/curl
Usage
use Wimski\Curl\CurlResourceFactory; $curlResourceFactory = new CurlResourceFactory(); $curlResource = $curlResourceFactory->make('https://some-webserver.com/resource-to-request'); $response = $curlResource ->setOption(CURLOPT_RETURNTRANSFER, true) ->execute(); $curlResource->close();
Ideally you would set up a singleton binding for the factory in your framework's container and use DI.
use Wimski\Curl\Contracts\CurlResourceFactoryInterface; class MyClass { public function __construct( protected CurlResourceFactoryInterface $curlResourceFactory, ) { } public function getData(): string { $curlResource = $this->curlResourceFactory->make('https://some-webserver.com/resource-to-request'); $response = $curlResource ->setOption(CURLOPT_RETURNTRANSFER, true) ->execute(); $curlResource->close(); return $response; } }