PHPackages                             ircmaxell/tari-php - 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. ircmaxell/tari-php

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

ircmaxell/tari-php
==================

A Middleware Proof-Of-Concept Library For PHP

781.2k3[1 PRs](https://github.com/ircmaxell/Tari-PHP/pulls)PHP

Since May 21Pushed 10y ago10 watchersCompare

[ Source](https://github.com/ircmaxell/Tari-PHP)[ Packagist](https://packagist.org/packages/ircmaxell/tari-php)[ RSS](/packages/ircmaxell-tari-php/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Tari-PHP
========

[](#tari-php)

A PSR-7 Middleware Interface proof-of-concept for PHP.

Requirements
============

[](#requirements)

- PHP 7.0

Yes, that's the only hard requirement

Usage As An End User
====================

[](#usage-as-an-end-user)

To use this runner, you need to pick a PSR-7 Library. We'll use Guzzle's.

First, install it: `composer require guzzle/psr7`

Now, we need a factory instance for the PSR-7 Library;

```
$factory = new Tari\Adapter\Guzzle\Factory;
```

Next, we boot up the "Server":

```
$server = new Tari\Server($factory);
```

Next, append whatever middleware we want to. In this case, let's add the error handler and the HSTS middleware:

```
$server->append(new Tari\ServerMiddleware\ErrorHandler);
$server->append(new Tari\ServerMiddleware\HSTS(300 /* Max-age in seconds */));
```

We can also add middleware as closures (Notice we don't need types):

```
$server->append(function($request, $frame) {
    $response = $frame->next($request);
    return $response->withHeader('X-Powered-By', 'Tari-PHP');
});
```

We also need a "default" action to take:

```
$default = function($request) use ($factory) {
    // Default to a 404 NOT FOUND response
    return $factory->createResponse("Not Found", 404);
};
```

Finally, we can run out stack:

```
$request = new Guzzle\Psr7\ServerRequest("http://www.example.com/foo", "GET");
$response = $server->run($request, $default);
```

And that's all there is to it...

Usage As A Library Builder (Server Mode)
========================================

[](#usage-as-a-library-builder-server-mode)

To use this middleware as a library author, simply implement the `Tari\MiddlewareInterface` interface. It's as easy as that:

```
use Tari\ServerMiddlewareInterface;
use Tari\ServerFrameInterface;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class Foo implements ServerMiddlewareInterface {
    public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface {
        // Do your modifications to the request here
        $response = $frame->next($request);
        // Do your modifications to the response here
        return $response;
    }
}
```

It's as simple as that.

Aborting a request
------------------

[](#aborting-a-request)

Sometimes, you don't want to continue with a request. If you detect that situation in your middleware, simply create a new response:

```
use Tari\ServerMiddlewareInterface;
use Tari\ServerFrameInterface;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class Foo implements ServerMiddlewareInterface {
    public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface {
        if ($this->isBadRequest($request)) {
            return $frame->factory()->createResponse("Bad Request", 400);
        }
        return $frame->next($request);
    }
}
```

Interfaces
==========

[](#interfaces)

Tari defines 3 consumable interfaces:

ServerMiddlewareInterface
-------------------------

[](#servermiddlewareinterface)

```
interface ServerMiddlewareInterface {
    public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface;
}
```

Used for Server request processing

ServerFrameInterface
--------------------

[](#serverframeinterface)

```
interface ServerFrameInterface {
    public function next(ServerRequestInterface $request): ResponseInterface;
    public function factory(): FactoryInterface;
}
```

This is used for processing server requests

FactoryInterface
----------------

[](#factoryinterface)

```
interface FactoryInterface {

    public function createRequest(
        UriInterface $uri = null,
        string $method = '',
        array $headers = [],
        $body = null
    ): RequestInterface;

    public function createServerRequest(
        UriInterface $uri = null,
        string $method = '',
        array $headers = [],
        $body = null
    ): ServerRequestInterface;

    public function createResponse(
        int $status = 200,
        array $headers = [],
        $body = null
    ): ResponseInterface;

    public function createStream($data = null): StreamInterface;

    public function createUri(string $uri = ''): UriInterface;

    public function createUploadedFile(
        $data,
        int $size,
        int $error,
        string $clientFile = '',
        string $clientMediaType = ''
    ): UploadedFileInterface;
}
```

There's a lot more going on here, but it's still extremely straight forward and simple.

Each method creates a PSR-7 object, and initializes it.

License
=======

[](#license)

MIT

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

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

### Community

Maintainers

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

---

Top Contributors

[![ircmaxell](https://avatars.githubusercontent.com/u/660654?v=4)](https://github.com/ircmaxell "ircmaxell (12 commits)")[![carnage](https://avatars.githubusercontent.com/u/846596?v=4)](https://github.com/carnage "carnage (1 commits)")[![kelunik](https://avatars.githubusercontent.com/u/2743004?v=4)](https://github.com/kelunik "kelunik (1 commits)")

### Embed Badge

![Health badge](/badges/ircmaxell-tari-php/health.svg)

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

###  Alternatives

[dcat-admin-extension/ueditor

百度在线编辑器

205.6k](/packages/dcat-admin-extension-ueditor)

PHPackages © 2026

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