PHPackages                             ananiaslitz/matrix - 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. ananiaslitz/matrix

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

ananiaslitz/matrix
==================

A multi-tenant library for Hyperf APIs.

1.0.0(4mo ago)71MITPHPPHP ^8.1

Since Feb 21Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/Ananiaslitz/matrix)[ Packagist](https://packagist.org/packages/ananiaslitz/matrix)[ RSS](/packages/ananiaslitz-matrix/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Matrix - Hyperf Multi-Tenant Library
====================================

[](#matrix---hyperf-multi-tenant-library)

Matrix is a comprehensive multi-tenant library designed to seamlessly integrate multi-tenancy into your Hyperf applications. It provides an easy-to-use and flexible system to manage multiple tenants, ensuring data isolation, dynamic database connection management, and tenant identification based on request parameters.

### 🌟 Features

[](#-features)

- Dynamic Tenant Database Connections: Automatically switch database connections based on the identified tenant, ensuring that each tenant's data remains isolated and secure.
- Customizable Tenant Identification: Flexibly define how tenants are identified from incoming requests, whether by subdomain, path, headers, or other custom strategies.
- Extensible Architecture: Easily extend or override default behaviors with custom implementations, thanks to the library's use of Hyperf's dependency injection and configuration systems.
- Command for Publishing Migrations: Includes a command to publish necessary migrations to the application, making setup quick and straightforward.

### 🚀 Installation

[](#-installation)

To install Matrix, run the following command in the root of your Hyperf project:

```
composer require ananiaslitz/matrix
```

After installation, you should publish the default migrations provided by Matrix:

```
php bin/hyperf.php matrix:publish
```

This command copies necessary migration files to your project's `migrations` directory.

### Configuration

[](#configuration)

1. Publish Configuration (Optional): If you want to customize the tenant identification logic or use a custom TenantFinder, publish the Matrix configuration file:

```
php bin/hyperf.php vendor:publish ananiaslitz/matrix
```

This will copy the default configuration file to `config/autoload/matrix.php`.

2. Define **Tenant Finder**: In `config/autoload/matrix.php`, specify your custom **TenantFinder** implementation if necessary:

```
return [
    'tenant_finder' => App\Tenant\CustomTenantFinder::class,
];
```

3. **Middleware Registration**: Register the `TenantMiddleware` in your application's middleware stack, typically in `config/autoload/middlewares.php`:

```
return [
    'http' => [
        \Ananiaslitz\Matrix\Http\Middleware\TenantMiddleware::class,
    ],
];
```

### Usage

[](#usage)

To use Matrix in your application, simply proceed with your business logic as usual. The library handles tenant identification and database connection switching automatically based on your configuration.

Ensure that your tenant-specific models use the dynamic tenant connection, which Matrix configures based on the identified tenant:

```
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
use Ananiaslitz\Matrix\Model\Traits\UsesTenantConnection;

class YourTenantModel extends Model
{
    use UsesTenantConnection;
}
```

### Customizing Tenant Identification

[](#customizing-tenant-identification)

To customize how tenants are identified, implement your own `TenantFinderInterface` and specify it in the `config/autoload/matrix.php` configuration file. Your custom finder should return the tenant identifier based on the request, which Matrix will use to configure the database connection.

### Contributing

[](#contributing)

Contributions are welcome! Please feel free to submit pull requests or create issues for bugs, questions, and feature requests.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance76

Regular maintenance activity

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

133d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/963a9f4c77e080eaafe63352d0ec2e1dc101cb54b734c0a144223893793000b5?d=identicon)[Ananiaslitz](/maintainers/Ananiaslitz)

---

Top Contributors

[![Ananiaslitz](https://avatars.githubusercontent.com/u/96492331?v=4)](https://github.com/Ananiaslitz "Ananiaslitz (23 commits)")

---

Tags

swoolecoroutinemulti-tenanthyperf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ananiaslitz-matrix/health.svg)

```
[![Health](https://phpackages.com/badges/ananiaslitz-matrix/health.svg)](https://phpackages.com/packages/ananiaslitz-matrix)
```

PHPackages © 2026

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