PHPackages                             medianet-dev/p-connector - 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. [API Development](/categories/api)
4. /
5. medianet-dev/p-connector

ActiveLibrary[API Development](/categories/api)

medianet-dev/p-connector
========================

Link projects together with restful apis

2.0.0(7mo ago)22.0k↓50%5[7 issues](https://github.com/Medianet-Tunisia/p-connector/issues)MITPHPPHP ^7.2.5|^7.3|^8.0|^8.1|^8.2|^8.3CI passing

Since Oct 25Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/Medianet-Tunisia/p-connector)[ Packagist](https://packagist.org/packages/medianet-dev/p-connector)[ Docs](https://github.com/medianet-dev/p-connector)[ RSS](/packages/medianet-dev-p-connector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (41)Used By (0)

[![](https://user-images.githubusercontent.com/10948245/97109260-837eca80-16d2-11eb-95ad-a6c89cb400fd.PNG)](# "PConnector")

[![](https://camo.githubusercontent.com/f9a28a5a36f392e8ecfdc98a741b53368a403a6ff3367f466cc08ebdbba5099e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d656469616e65742d6465762f702d636f6e6e6563746f722e737667)](https://packagist.org/packages/medianet-dev/p-connector "Latest Version on Packagist")[![](https://camo.githubusercontent.com/8ed6b7255a0d99209e23fd930e17da694567abdd3e36278b21ade32d1f567969/68747470733a2f2f7777772e7472617669732d63692e636f6d2f4d656469616e65742d54756e697369612f702d636f6e6e6563746f722e7376673f6272616e63683d6d6173746572)](https://www.travis-ci.com/Medianet-Tunisia/p-connector "Build Status")[![StyleCI](https://camo.githubusercontent.com/ad75d58b81f370dec0ac297b4302213a42b220dfb276f8deda57f19442d5b338/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3330373134303136362f736869656c643f7374796c653d666c6174266272616e63683d6d6173746572)](https://github.styleci.io/repos/307140166?branch=master "StyleCI")[![](https://camo.githubusercontent.com/172d767b2060864d722fbb469c1f635d94f4d8640d13672aaf900354892c4140/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f4d656469616e65742d54756e697369612f702d636f6e6e6563746f722e7376673f623d6d6173746572)](https://scrutinizer-ci.com/g/Medianet-Tunisia/p-connector "Quality Score")[![](https://camo.githubusercontent.com/d8219cfa5d6e661fdb4aedd29003ba996de07fc2ad0028ea7260277a12f78b73/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d656469616e65742d6465762f702d636f6e6e6563746f722e737667)](https://packagist.org/packages/medianet-dev/p-connector "Total Downloads")

**PConnector** is a package that makes linking projects together much easier than performing a manual *Guzzle* or *Curl* requests. You only need to set some basic settings of your gateway(s) and that's it.

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

[](#installation)

You can install the package via composer:

```
composer require medianet-dev/p-connector
```

Then migrate the package table by running:

```
php artisan migrate
```

Usage
-----

[](#usage)

Here we will pass through some examples of doing some basic and advanced Api calls .

### Configuring your gateway(s)

[](#configuring-your-gateways)

Before start playing with the package you need to setup a profile for your gateway, and to do so, you need to publish the configuration file by running:

```
php artisan vendor:publish --provider="MedianetDev\PConnector\PConnectorServiceProvider"
```

After publishing the configuration, go to `p-connector.php` config file and setup you first profile setting:

```
# file: p-connector.php

/*
|--------------------------------------------------------------------------
| List of the available profiles with it's configurations
|--------------------------------------------------------------------------
*/
'profiles' => [
    'demo' => [
        'protocol' => 'https',
        'host' => 'my-json-server.typicode.com',
        'port' => 443,
        'prefix' => 'typicode/demo',
    ],
],
```

> Note that you can set **more than one** profile.

And that's it for basic configuration, other available settings are described in the configuration file itself.

### Some usage examples

[](#some-usage-examples)

```
// Import the PConnector facade to get available methods hints
use MedianetDev\PConnector\Facade\PConnector;

// Or use tha alias without available methods hints
# use PConnector;

// Method 1:
$demo = PConnector::get('posts/1');
echo ''.$demo->title.'';

// Method 2:
# $demo = PConnector::send('posts/1', [], 'GET');
# echo ''.$demo->title.'';
```

We don't have to tell the **PConnector** witch profile to use if we set the `default_profile` parameter, but if we have more than on profile and we want to switch between them, we can use the `profile()` function like so:

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::profile('demo')->get('posts/1');
$demo2 = PConnector::profile('demo_2')->get('users/1');
```

> **IMPORTANT**: The profile function will apply a specific profile configuration and **erase** any other setting, so if you want to switch the profile call the `profile()` function before any other function.

#### Configuration:

[](#configuration)

Some setting can be set as a profile setting, you will find those setting with **\[AAPS\]** annotation to distinguish them (AAPS: Also A Profile Setting). To set settings for a profile, you have to put them inside the appropriate profile array. Also, note if a setting is defined inside a profile and as global in the same time, the profile one will be used.

#### Http Methods:

[](#http-methods)

```
send(string $path = '', array $data = [], string $method = 'GET')
post(string $path = '', array $data = [])
get(string $path = '', array $data = [])
put(string $path = '', array $data = [])
patch(string $path = '', array $data = [])
delete(string $path = '', array $data = [])
```

#### Authentication:

[](#authentication)

PConnector supports sending request with authentication, and to do so you need to configuration the authentication settings for the desired profile or for all the profiles.

```
# file: p-connector.php

'auth' => [ // [AAPS]
    // Whether to use authentication by default or not (you can make an exception with withAuth() and withoutAuth() methods)
    'authenticate_by_default' => false,
    // How to authenticate (Accepted values are: api_key, basic, bearer)
    'auth_method' => 'bearer',
    // If the api_key method is use then you SHOULD provide an api_key key
    // 'api_key' => 'X-AUTH-TOKEN',
    // The path of the login
    'login_path' => 'login',
    // The http method used to login
    'login_http_method' => 'POST',
    'credentials' => [
        'username' => 'username',
        'password' => 'password',
    ],
    // The expected http code response when login in
    'success_login_code' => [200],
    // When should we re-authenticate
    're_auth_on_codes' => [401],
    // Where to find the token in the response (you can youse the dot syntax EX: 'data.user.auth.token')
    'token_path' => 'token',
],
```

You can configure the authentication settings for the desired profile by adding the auth array in the profile config.

```
'profiles' => [
    'demo' => [
        ...,
        'auth' => [ // Add this section for custom auth settings
            // Authentication settings specific to this profile
        ],
    ],
],
```

If for some reason you don't want to include authentication while sending some request, you can tell the PConnector like so:

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::profile('demo')->withoutAuth()->get('posts/1');
# $demo = PConnector::withoutAuth()->get('users/1');
```

> Remember that the profile function will apply a specific profile configuration and **erase** any other setting (in our case the `withoutAuth()` function), that why we use the `profile()` before `withoutAuth()`.

#### Request

[](#request)

```
# file: p-connector.php

// Request settings
'request' => [ // [AAPS]
    // The default request headers
    'headers' => ['Accept' => 'application/json'],
    // Whether to send the language through the header by default or not
    'enable_localization' => true,
    // Handle http errors or not
    'http_errors' => false,
    // Http connect timeout value
    'connect_timeout' => 3,
    // Http timeout value
    'timeout' => 3,
    // The data type; json, form-data, ...
    'post_data' => 'json',

    // Verify the SSL certificate or not
    'verify' => true,
],
```

##### Localization

[](#localization)

Send **Accept-Language** header when needed:

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::lang('ar')->get('posts/1');
```

Or configure the **PConnector** to send it automatically via the configuration file.

##### Quickly change the current url

[](#quickly-change-the-current-url)

```
PConnector::url('https://jsonplaceholder.typicode.com')->get('todos')
```

Or you can use tha alias setUrl() method

##### This is the list of getters available for the request:

[](#this-is-the-list-of-getters-available-for-the-request)

- getRequestUrl()
- getRequestMethod()
- getRequestData()

#### Response

[](#response)

You can configure how do you want to save the response body:

- As a string
- As an object
- As an array

```
# file: p-connector.php

'decode_response' => 'object', // [AAPS]
```

And if you want to change that for a specific response:

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::objectResponse()->get('posts/1');
$demo = PConnector::htmlResponse()->get('posts/1');
$demo = PConnector::arrayResponse()->get('posts/1');
```

The received response body can be retrieved using `getResponseBody()` after sending the request.

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::get('posts/1')->getResponseBody();
```

This is the list of getters available for the response:

- getResponseBody()
- getResponseStatusCode()
- getResponseHeaders()

If you decode the response body as an object, you can use `getAttribute('attribute_name')` or `->attribute_name` to retrieve a specific attribute, or even you can go more deep and do `getAttribute('object.object.attribute_name', 'fallback value')`, as an example:

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::get('posts/1')->getAttribute('title');
$demo = PConnector::get('posts/1')->title;
$demo = PConnector::get('posts/1')->getAttribute('author.name', 'Unknown author');
```

Response status code checks:

- `function responseCodeIs(int $code): bool`
- `function responseCodeNot(int $code): bool`
- `function responseCodeIn(array $codes): bool`
- `function responseCodeNotIn(array $codes): bool`
- `function responseOK(): bool`
- `function responseNOK(): bool`

> Example:

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::get('posts/1');
if ($demo->responseCodeNot(200)) {
    echo 'This is not what I was expecting from Demo!';
} else {
    echo ''.$demo->title.'';
}

$demo = PConnector::post('posts', ['title' => 'My title']);
 if ($demo->responseCodeNotIn([200, 201])) {
    echo 'This is not what I was expecting from Demo!';
} else {
    echo 'Post created, Hola!';
}
```

#### Logging

[](#logging)

```
# file: p-connector.php

// Log requests & responses to log files or not (you can make an exception with withLog() and withoutLog() methods)
'log' => false, // [AAPS]
```

Example 1:

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::get('posts/1')->dump();

if ($demo->responseCodeNot(200)) {
    $demo->log();
} else {
    echo ''.$demo->title.'';
}
```

Example 2:

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::withLog()->get('posts/1');
```

#### Debugging

[](#debugging)

You can debug the **PConnector** object using the `dump()` or the `dd()` method.

```
use MedianetDev\PConnector\Facade\PConnector;

$demo = PConnector::get('posts/1')->dump();
$demo = PConnector::get('posts/1')->dd();
```

### 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)

- [Soufiene Slimi](https://github.com/soufiene-slimi)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance42

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~60 days

Recently: every ~152 days

Total

31

Last Release

230d ago

Major Versions

1.7.7 → 2.0.02025-10-01

PHP version history (3 changes)1.0.0PHP ^7.2.5

1.4.0PHP ^7.2.5|^7.3|^8.0

2.0.0PHP ^7.2.5|^7.3|^8.0|^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/38753b0be71842a95f9d64620c2de4aa5090ae079110e51840c8324fc7a5849b?d=identicon)[MaherMehri](/maintainers/MaherMehri)

![](https://www.gravatar.com/avatar/cffbb1ed6675952424988b8e077a0aa52d239528b561923f89e4164215ea3dfa?d=identicon)[soufiene-slimi](/maintainers/soufiene-slimi)

![](https://www.gravatar.com/avatar/2eb9bdda1104ed71dc2dcad92dac5a10e3cee1866b73968e74b98cdb70392e2d?d=identicon)[medianet-dev](/maintainers/medianet-dev)

![](https://www.gravatar.com/avatar/82f3e9f3252c687e1a38e41413c9439ff4993ecee0cd02a192bbc127921d9dcb?d=identicon)[adelstiti](/maintainers/adelstiti)

---

Top Contributors

[![soufiene-slimi](https://avatars.githubusercontent.com/u/10948245?v=4)](https://github.com/soufiene-slimi "soufiene-slimi (29 commits)")[![adelstiti](https://avatars.githubusercontent.com/u/40324627?v=4)](https://github.com/adelstiti "adelstiti (21 commits)")[![medianet-dev](https://avatars.githubusercontent.com/u/57226389?v=4)](https://github.com/medianet-dev "medianet-dev (15 commits)")[![MaherMehri](https://avatars.githubusercontent.com/u/30412331?v=4)](https://github.com/MaherMehri "MaherMehri (7 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (2 commits)")[![adeladelst](https://avatars.githubusercontent.com/u/111419938?v=4)](https://github.com/adeladelst "adeladelst (2 commits)")[![arwa-lemaalem-medianet](https://avatars.githubusercontent.com/u/129725946?v=4)](https://github.com/arwa-lemaalem-medianet "arwa-lemaalem-medianet (1 commits)")[![nerminealayeb7](https://avatars.githubusercontent.com/u/80265834?v=4)](https://github.com/nerminealayeb7 "nerminealayeb7 (1 commits)")

---

Tags

medianet-devp-connector

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/medianet-dev-p-connector/health.svg)

```
[![Health](https://phpackages.com/badges/medianet-dev-p-connector/health.svg)](https://phpackages.com/packages/medianet-dev-p-connector)
```

###  Alternatives

[skagarwal/google-places-api

Google Places Api

1913.0M8](/packages/skagarwal-google-places-api)[dcblogdev/laravel-microsoft-graph

A Laravel Microsoft Graph API (Office365) package

168285.5k1](/packages/dcblogdev-laravel-microsoft-graph)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[grantholle/powerschool-api

A Laravel package to make interacting with PowerSchool less painful.

1715.6k1](/packages/grantholle-powerschool-api)

PHPackages © 2026

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