PHPackages                             thejawker/chainable - 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. thejawker/chainable

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

thejawker/chainable
===================

Exposes a Class that makes method chaining fluent and easy.

0.0.5(8y ago)2597MITPHPPHP &gt;=7.0.0

Since Sep 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/thejawker/Chainable)[ Packagist](https://packagist.org/packages/thejawker/chainable)[ Docs](https://github.com/thejawker/laravel-route-module-macro)[ RSS](/packages/thejawker-chainable/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

Fluent Chaining for Legacy code
===============================

[](#fluent-chaining-for-legacy-code)

Are you tired of using packages that require you to write code like the following:

```
$someClass = new SomeClass();
$someClass->someMethod();
$someClass->someOtherMethod();

// Now you can just write it like this.
new Chain(SomeClass::class)
    ->someMethod()
    ->someOtherMethod();

// Or even easier
ch(SomeClass::class)
    ->someMethod()
    ->someOtherMethod();
```

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

[](#installation)

Require the package from Composer:

```
composer require thejawker/chainable
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

You can use the Chain in two easy different ways, depending on your liking or necessity.

```
// Through passing the Class's classname.
$someClass = new Chain(SomeClass::class);

// Or through passing the actual instance
$someClass = new Chain(new SomeClass($withParams))
```

### Getting Properties

[](#getting-properties)

Getting properties is just the same, these won't return `$this`.

```
$property = new Chain(SomeClass::class)->property;
```

### Escaping Chaining

[](#escaping-chaining)

Often methods do need to return an actual value, otherwise we can stop programming all together. Chain will allow you to easily turn off the chaining behaviour. This can be done very easily.

```
$someClass = new Chain(SomeClass::class)->someMethod()
$property = $someClass->escape()->getValue() // will return the original value
```

You can also unescape to get the Chainable functionality back. To be honest I can't find a use case for this yet, but hey! You never know!

```
$someClass = new Chain(SomeClass::class)->someMethod();
$sameInstance = $someClass->escape();
$sameInstance->unescape()->otherMethod();
```

### Get The Original Instance

[](#get-the-original-instance)

Sometimes it is needed to return the original instance because some code might be checking if it is an `instanceof` a class. You can easily chain the `->instance()` method on there and you get the original instance back, not a clone, the actual thing. Note: you can't go back from here.

```
public function calculate()
{
    return new Chain(new LegacyClass)
        ->someMethod()
        ->setSome('stuff')
        ->maybeMore()
        ->instance();
}
```

### Wanna Go Pro?

[](#wanna-go-pro)

I've also included a convenient shortcut for those who think instantiating a `Chain` is too much work. The following will yield exactly the same result but then just with much more ease.

```
ch(LegacyClass::class)
    ->also()
    ->works('yay!')
    ->fuckYess();
```

Testing
-------

[](#testing)

I've included some tests, feel free to send me pull-requests if you see room for improvement.

```
composer test
```

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Every ~19 days

Total

5

Last Release

3074d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6703837?v=4)[Bram Veerman](/maintainers/thejawker)[@thejawker](https://github.com/thejawker)

---

Top Contributors

[![thejawker](https://avatars.githubusercontent.com/u/6703837?v=4)](https://github.com/thejawker "thejawker (3 commits)")

---

Tags

fluentchainingOOPthejawker

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thejawker-chainable/health.svg)

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

###  Alternatives

[samrap/acf-fluent

A fluent interface for the Advanced Custom Fields WordPress plugin

28656.0k4](/packages/samrap-acf-fluent)[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38425.4k](/packages/bocharsky-bw-arrayzy)

PHPackages © 2026

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