PHPackages                             frog/php-curl-sai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. frog/php-curl-sai

ActiveLibrary[HTTP &amp; Networking](/categories/http)

frog/php-curl-sai
=================

A SAI(Standalone interface) to enable stubbing of curl requests.

1.1.2(4y ago)2422↓83.3%1[1 issues](https://github.com/frogtechnologies/php-curl-sai/issues)MITPHPPHP ^7.3|^8.0

Since Feb 21Pushed 4y agoCompare

[ Source](https://github.com/frogtechnologies/php-curl-sai)[ Packagist](https://packagist.org/packages/frog/php-curl-sai)[ Docs](https://github.com/frogtechnologies/php-curl-sai)[ RSS](/packages/frog-php-curl-sai/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)DependenciesVersions (6)Used By (0)

Description
===========

[](#description)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e6f4ce826b771ec46dcffd1d56aa47b66d607f3fed2c3dfd599c35957002f0c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66726f672f7068702d6375726c2d7361692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/frog/php-curl-sai)[![Build Status](https://camo.githubusercontent.com/21616761c9fa9d08187d3ea174a2ee1b3aee3825283a8dc8fdcaae54f812dadc/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f66726f672f7068702d6375726c2d7361692f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/github/frogtechnologies/php-curl-sai)[![Total Downloads](https://camo.githubusercontent.com/148c2a37d3c4c2a83ba9b89ac76785699a9973df6f89851f4f350601413d2855/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66726f672f7068702d6375726c2d7361692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/frog/php-curl-sai)

This is a minimal package forked from [m-ender/php-SAI](https://github.com/m-ender/php-SAI) aimed at enabling a simplified approach to stubbing of curl requests in php projects. The main changes it underwent were:

- Removal of unnecessary code files such as multi curl
- Upgrading of curl options as the last update the package received was in 2012

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require frog/php-curl-sai:1.1.2
```

Usage
-----

[](#usage)

In the class that's responsible for making the request:

```
use FROG\PhpCurlSAI\SAI_Curl;
use FROG\PhpCurlSAI\SAI_CurlInterface;

 class SDKClass {
    // Define the variable to hold the cURL instance that will make a connection
    protected $cURL;

    /** Pass in the interface implemented by both the stub and actual class
     * to allow for detection of methods to be used by your IDE
    **/
    public function __construct(
        SAI_CurlInterface $cURL = null
    ) {
        // If no curl instance is provided, the one that makes the actual connection shall be used
        if ($cURL == null) $this->cURL = new SAI_Curl();
        else
            $this->cURL = $cURL;
    }

    public function get_data(
        string $access_token
    ){
        $auth_headers = [
            "Authorization: Bearer {$access_token}",
            "Content-Type: application/json",
        ];

        $options = [
            CURLOPT_URL => 'https://cool.url/data',
            CURLOPT_HTTPHEADER => $auth_headers,
            CURLOPT_SSL_VERIFYPEER  => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
        ];

        // Setup a cURL handle via the interface
        $ch = $this->cURL->curl_init();

        // Add curl options via the interface
        $this->cURL->curl_setopt_array($ch, $options);
        // Execute the reqeust via the interface
        $response = $this->cURL->curl_exec($ch);

        if ($response === false) {
            // Retrieve the error via the interface
            $result = $this->cURL->curl_error($ch);
        } else {
            // Decode the result if need be
            $result = json_decode($response);
        }

        // Close the handle via the interface
        $this->cURL->curl_close($ch);

        return $result;
    }

    public function authorize(
        string $email,
        string $password,
    ){
        $request_body = [
            'email' => 'doe@mail.com',
            'password' => "12345678",
        ];

        $options = [
            CURLOPT_URL => 'https://cool.url/token',
            CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
            CURLOPT_SSL_VERIFYPEER  => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => json_encode($request_body),
        ];

        // Setup a cURL handle via the interface
        $ch = $this->cURL->curl_init();

        // Add curl options via the interface
        $this->cURL->curl_setopt_array($ch, $options);
        // Execute the reqeust via the interface
        $response = $this->cURL->curl_exec($ch);

        if ($response === false) {
            // Retrieve the error via the interface
            $result = $this->cURL->curl_error($ch);
        } else {
            // Decode the result if need be
            $result = json_decode($response);
        }

        // Close the handle via the interface
        $this->cURL->curl_close($ch);

        return $result;
    }
 }
```

In the class/file that wants to perform a stub, e.g during tests:

```
use FROG\PhpCurlSAI\SAI_CurlStub;

public function stub_get_data() {
    // Create an instance of the stub class which implements SAI_CurlInterface
    $cURL = new SAI_CurlStub();
    $sdk = new SDKClass($cURL);

    $request_body = [
        'email' => 'doe@mail.com',
        'password' => "12345678",
    ];

    $options = [
        CURLOPT_URL => 'https://cool.url/token',
        CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
        CURLOPT_SSL_VERIFYPEER  => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => json_encode($request_body),
    ];

    // Set the response you want returned when the first cURL call is to be made
    $cURL->setResponse(
        '{"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c","token_type":"Bearer","expires_in":3600}',
        // Pass in the cURL options (Needed to get the desired output)
        $options,
    );

    $token_result = $sdk->authorize(
      'doe@mail.com',
      "12345678"
    );

    $auth_headers = [
        "Authorization: Bearer {$token_result->access_token}",
        "Content-Type: application/json",
    ];

    $options = [
        CURLOPT_URL => 'https://cool.url/data',
        CURLOPT_HTTPHEADER => $auth_headers,
        CURLOPT_SSL_VERIFYPEER  => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
    ];

    // Set the response you want returned when the second cURL call is to be made
    $cURL->setResponse(
        '{"ref":"ac980b8e-afe5-49b8-b348-d0af00e2f556","date":"2021-02-21 22:20:32","code":"-11","MessageDescription":"MESSAGE REFERENCE LONGER THAN ALLOWED LENGTH"}',
        // Pass in the cURL options (Needed to get the desired output)
        $options,
    );

    $result = $sdk->get_data($token_result->access_token);

}
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Miller Adulu](https://github.com/frog)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

PHP Package Boilerplate
-----------------------

[](#php-package-boilerplate)

This package was generated using the [PHP Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Total

5

Last Release

1663d ago

PHP version history (2 changes)1.0.0PHP ^7.3

1.1.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e9627541639d5e64562039587a54aa9a0d35fcd13a7595a119012b20daae690?d=identicon)[FROG](/maintainers/FROG)

---

Top Contributors

[![MillerAdulu](https://avatars.githubusercontent.com/u/21357409?v=4)](https://github.com/MillerAdulu "MillerAdulu (16 commits)")[![mogul](https://avatars.githubusercontent.com/u/47762?v=4)](https://github.com/mogul "mogul (2 commits)")

---

Tags

curlfrogphp-curl-sai

### Embed Badge

![Health badge](/badges/frog-php-curl-sai/health.svg)

```
[![Health](https://phpackages.com/badges/frog-php-curl-sai/health.svg)](https://phpackages.com/packages/frog-php-curl-sai)
```

###  Alternatives

[rmccue/requests

A HTTP library written in PHP, for human beings.

3.6k34.5M258](/packages/rmccue-requests)[kriswallsmith/buzz

Lightweight HTTP client

2.0k31.3M443](/packages/kriswallsmith-buzz)[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[mashape/unirest-php

Unirest PHP

1.3k9.7M161](/packages/mashape-unirest-php)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
