PHPackages                             sal/php-seven - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sal/php-seven

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sal/php-seven
=============

PHP ISO/OSI layer 7 adapters library.

v5.7.0(4mo ago)1642MITPHPPHP ^8.2CI passing

Since Feb 6Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/zeroSal/php-seven)[ Packagist](https://packagist.org/packages/sal/php-seven)[ RSS](/packages/sal-php-seven/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (21)Used By (0)

[![PHP Pipeline](https://github.com/zeroSal/php-seven/actions/workflows/actions.yaml/badge.svg?branch=main)](https://github.com/zeroSal/php-seven/actions/workflows/actions.yaml)[![codecov](https://camo.githubusercontent.com/42e12cfcdaa73a856e976e28c9f14caa77abca424d93a2a46d647867aa3df273/68747470733a2f2f636f6465636f762e696f2f67682f7a65726f53616c2f7068702d736576656e2f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/zeroSal/php-seven)

php-seven
=========

[](#php-seven)

PHP `ISO/OSI` layer 7 protocols adapters library.

[![seven](https://private-user-images.githubusercontent.com/38191926/475977787-a2655528-ed04-41e7-b4bb-87b490700888.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzM4MDQyMjIsIm5iZiI6MTc3MzgwMzkyMiwicGF0aCI6Ii8zODE5MTkyNi80NzU5Nzc3ODctYTI2NTU1MjgtZWQwNC00MWU3LWI0YmItODdiNDkwNzAwODg4LnBuZz9YLU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SGVhZGVycz1ob3N0In0.EfZt5Nz3mhJNbLCMvKEKcSWH5BhFuT1kpqsKQxu-I-o)[Icon by smalllikeart - Flaticon](https://www.flaticon.com/free-icons/seven)

Why this library?
-----------------

[](#why-this-library)

This library speeds up developing of clients via common layer 7 communication protocols, providing `ready-to-use` and `dependency-injection-friendly` adapters.

Protocols
---------

[](#protocols)

Below the exaustive list of supported protocols.

- `HTTP(s)` authenticated via `Basic` and `Bearer`
- `SSH` authenticated via `IdentityFile` (asymmetric key pair)

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

[](#installation)

```
composer require sal/php-seven
```

Configuration
-------------

[](#configuration)

Adapters can be configured via a `yaml` file.

### Example (Symfony)

[](#example-symfony)

First of all, edit the `service.yaml` file as follows:

```
# services.yaml
services:
    ssh_adapter_config_loader:
        class: Sal\Seven\Loader\SshAdapterConfigLoader
        arguments:
            $path: '%kernel.project_dir%/config/php_seven/ssh.yaml'

    ssh_adapter:
        class: Sal\Seven\Adapter\Ssh\SshAdapter
        arguments:
            $configLoader: "@ssh_adapter_config_loader"
```

Then, create the `php_seven/ssh.yaml` file as follows:

```
# ssh.yaml
options:
    # - "ControlMaster=auto"
    # - "ControlPath=/tmp/php-seven-ssh-%C"
    # - "StrictHostKeyChecking=no"
    # - "ControlPersist=15m"
    # - "UserKnownHostsFile=/dev/null"
```

Usage
-----

[](#usage)

Below some examples of usage.

### HTTP Client

[](#http-client)

```
class MyAwesomeClient
{
    public function __construct() {
        // Require the instance to dependency injection
        private HttpAdapterInterface $http;
    } (
        // Set a custom timeout to HTTP requests
        $this->http->setTimeout(20);
        // Avoid TLS certificate validation
        $this->http->setVerify(false);
        // Add custom headers
        $this->http->addHeader(HttpHeaderFactory::accept(ContentType::JSON));
    );

    // Login (Bearer)
    public function login(string $server, string $username, string $password): void
    {
        // Set the base URI
        $this->http->setBaseUri("https://{$server}");

        // Perform HTTP post
        $response = $this->http->post(
            '/login', [
                // Add Form HTTP parameters
                new HttpParameter('username', $username),
                new HttpParameter('password', $password),
            ]
        );

        if (401 === $response->getStatusCode()) {
            throw new RuntimeException('Invalid credentials.');
        }

        // Retrieve the Bearer token from the response
        $body = json_decode($response->getBody() ?? '', true);
        if (!isset($body['token'])) {
            throw new RuntimeException('The server has not started the session.');
        }

        $token = $body['token'];
        // Set the token to further uses
        $this->http->setAuthorization(new HttpBearerAuthentication($token));
    }

    // Logout the adapter
    public function logout(): void
    {
        $this->http->setAuthorization(null);
    }

    // Use the logged in adapter
    public function addUser(string $email): void
    {
        $response = $this->http->post(
            '/add-user', [
                new HttpParameter('email', $email),
            ]
        );

        // Use the isSuccessful() method to check if the status code is < 400.
        if (!$response->isSuccessful()) {
            throw new RuntimeException("Response code: {$response->getStatusCode()}");
        }
    }
}
```

### SSH Client

[](#ssh-client)

```
class MyAwesomeClient
{
    public function __construct() {
        // Require the instance to dependency injection
        private SshAdapterInterface $ssh;

        // Require the instance of the logger to dependency injection (optional)
        private LoggerInterface $logger
    } (
        // Set a custom timeout to SSH connections
        $this->ssh->setTimeout(20);

        // Set the host
        $this->ssh->setHost('127.0.0.1');

        // Set the user
        $this->ssh->setUser('root');

        // Set the logger (optional)
        $this->ssh->setLogger($this->logger);

        // Add an identity file
        $this->addIdentityFile('~/.ssh/id_rsa');
    );

    public function shutdown(): void
    {
        try {
            // Run a command, saving the result in a variable
            $result = $this->ssh->runCommand(['shutdown', '-h', 'now']);
        } catch (ProcessTimedOutException $e) {
            // Catch the timeout exception
            $this->logger->error($e->getMessage());
        } catch (RuntimeException $e) {
            // Catch other exceptions
            $this->logger->error($e->getMessage());
        }

        // Use the isSuccessful() method to check if the status code is 0
        if (!$result->isSuccessful()) {
            $this->logger->error($result->getReturnCode());
            $this->logger->error($result->getOutput());

            return;
        }

        $this->logger->info($result->getReturnCode());
        $this->logger->info($result->getOutput());
    }
}
```

Contribution
============

[](#contribution)

Contributions are always welcomed (both issues opening and pull requests).

Improve the code
----------------

[](#improve-the-code)

Fork the project, perform your improvements and open a pull request. **Note**: pull requests **MUST** include related unit tests and related documentation if needed. All pull requests **MUST** be linked to an issue.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance77

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.5% 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 ~19 days

Recently: every ~11 days

Total

19

Last Release

124d ago

Major Versions

v1.3.0 → v2.0.02025-07-28

v2.1.1 → v3.0.02025-08-08

v3.0.0 → v4.0.02025-08-12

v4.0.0 → v5.0.02025-09-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce4b708b0c5374c186365b966211340539d29fb10a2008d739dab304491029d9?d=identicon)[sal](/maintainers/sal)

---

Top Contributors

[![zeroSal-le](https://avatars.githubusercontent.com/u/259530781?v=4)](https://github.com/zeroSal-le "zeroSal-le (26 commits)")[![zeroSal](https://avatars.githubusercontent.com/u/38191926?v=4)](https://github.com/zeroSal "zeroSal (20 commits)")

---

Tags

clientlayer7php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sal-php-seven/health.svg)

```
[![Health](https://phpackages.com/badges/sal-php-seven/health.svg)](https://phpackages.com/packages/sal-php-seven)
```

###  Alternatives

[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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