Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"homepage": "https://developers.facebook.com/",
"require": {
"php": ">=8.0",
"ext-curl": "*",
"guzzlehttp/guzzle": "^6.5 || ^7.0"
},
"require-dev": {
Expand Down
8 changes: 2 additions & 6 deletions src/FacebookAds/Http/Adapter/Curl/AbstractCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __clone() {
}

public function __destruct() {
if (is_resource($this->handle)) {
if ($this->handle instanceof \CurlHandle) {
curl_close($this->handle);
}
}
Expand All @@ -54,11 +54,7 @@ public function __destruct() {
* @return CurlInterface
*/
public static function createOptimalVersion() {
if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
return new Curl55();
} else {
return new Curl();
}
return new Curl();
}

/**
Expand Down
34 changes: 8 additions & 26 deletions src/FacebookAds/Http/Adapter/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,59 +28,41 @@

class Curl extends AbstractCurl {

/**
* @throws \RuntimeException
*/
public function __construct() {
parent::__construct();
if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
throw new \RuntimeException("Unsupported Curl version");
}
}

/**
* @param string $string
* @return string
* @return bool|string
*/
public function escape($string) {
return rawurlencode($string);
return curl_escape($this->handle, $string);
}

/**
* @param int $bitmask
* @return int
*/
public function pause($bitmask) {
return 0;
return curl_pause($this->handle, $bitmask);
}

/**
* FIXME should introduce v2.10 breaking change:
* implement abstract support for FileParameter in AdapterInterface
*
* @param string|FileParameter $filepath
* @return string
* @return \CURLFile
*/
public function preparePostFileField($filepath) {
$mime_type = $name = '';
if ($filepath instanceof FileParameter) {
$mime_type = $filepath->getMimeType() !== null
? sprintf(';type=%s', $filepath->getMimeType())
: '';
$name = $filepath->getName() !== null
? sprintf(';filename=%s', $filepath->getName())
: '';
$mime_type = $filepath->getMimeType() ?: '';
$name = $filepath->getName() ?: '';
$filepath = $filepath->getPath();
}
return sprintf('@%s%s%s', $filepath, $mime_type, $name);
return new \CURLFile($filepath, $mime_type, $name);
}

/**
* @return void
*/
public function reset() {
$this->handle && curl_close($this->handle);
$this->handle = curl_init();
$this->handle && curl_reset($this->handle);
}

/**
Expand Down
96 changes: 0 additions & 96 deletions src/FacebookAds/Http/Adapter/Curl/Curl55.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/FacebookAds/Http/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
namespace FacebookAds\Http\Adapter;

use FacebookAds\Exception\Exception;
use FacebookAds\Http\Adapter\Curl\AbstractCurl;
use FacebookAds\Http\Adapter\Curl\Curl;
use FacebookAds\Http\Adapter\Curl\CurlInterface;
use FacebookAds\Http\Client;
Expand All @@ -51,7 +50,7 @@ class CurlAdapter extends AbstractAdapter {
*/
public function __construct(Client $client, ?CurlInterface $curl = null) {
parent::__construct($client);
$this->curl = $curl ?: AbstractCurl::createOptimalVersion();
$this->curl = $curl ?: new Curl();
$this->curl->init();
}

Expand Down
Loading