PHPackages                             sepiariver/binliner-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. sepiariver/binliner-php

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

sepiariver/binliner-php
=======================

A Binary Sequence Validator for PHP

1.0.0-pl(4y ago)05MITPHPPHP &gt;=7.4

Since Mar 4Pushed 4y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

binliner-php
============

[](#binliner-php)

Binary Sequence Validator for PHP

About
-----

[](#about)

### What is it?

[](#what-is-it)

Binliner is like a factory for [state machines](https://en.wikipedia.org/wiki/Finite-state_machine). Given the parameter `$config['size']`, an instance is endowed with a finite number of possible states, which may be configured as valid, to the exclusion of all other states, using the `$config['validation']` parameter.

The `isValid()` method returns a boolean: whether the current state is one of those configured as valid, like an [Acceptor](https://en.wikipedia.org/wiki/Finite-state_machine#Acceptors). The instance can be coerced into a `string` or converted to a `number`, in both cases returning the respective representation of the state, like a [Classifier](https://en.wikipedia.org/wiki/Finite-state_machine#Classifiers). This output can be mapped to another set of values that serve a particular business case—the implementation on the whole then acting like a [Moore machine](https://en.wikipedia.org/wiki/Moore_machine).

By passing a function to `$config['validation']`, Binliner's deterministic behaviour can be side-stepped, introducing side-effects or any other custom validation logic required. At that point, Binliner's utility might be brought into question, although it does seem to help elucidate complex conditional logic.

### What it is not

[](#what-it-is-not)

Binliner is not a garbage-collection utility, despite the name. It "lines up" binary flags in a sequence, and since it validates the sequence against configured rules, it can be said to catch errors aka "catch garbage" like a binliner :)

### What is a binary sequence?

[](#what-is-a-binary-sequence)

It is a series of bits, each of which has a value of either 0 or 1. It is typically used for data transmission, compression or storage, but also can be used for error detection and correction, among other uses. By encapsulating arbitrary boolean conditions using the implicit ordering of numerically-indexed arrays, Binliner can faciliate complex control flows in a more compact yet still transparent/readable way.

For trivial control flows, Binliner is probably ill-suited, but it can be helpful in more complex cases. It also allows re-use of the condition state.

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

[](#installation)

```
composer require sepiariver/binliner-php

```

Usage
-----

[](#usage)

### Example

[](#example)

> If Bob's age is less than 21, reject. If his age is 21 to 65, check his license, and reject if invalid. If he is over 65 and has a valid license, re-test. If he fails the test, or lacks a valid license, reject.

Note: this example is not intended to condone ageism

```
use SepiaRiver\Binliner;

class Bob
{
    // define bob
};
$bob = new Bob();
$ofAge = ($bob->age > 20);               // Postiion 0 in the sequence
$needsRetest = ($bob->age > 65);         // Position 1
$validLicense = ($bob->license.valid);   // Position 2
$passedTest = ($bob->test.results > 60); // Position 3

/**
 * Truth table
 * ofAge | needsRetest | validLicense | passedTest
 * 1 | 0 | 1 | 0 // of age, valid license, test result irrelevant
 * 1 | 0 | 1 | 1 // of age, valid license, test result irrelevant
 * 1 | 1 | 1 | 1 // of age, valid license, passed test
 *
 * ALL OTHER STATES ARE INVALID
 */

$config = [
    'size' => 4,
    'validation' => ['1010', '1011', '1111'],
];
$binliner = new Binliner(
    $config,
    $ofAge,
    $needsRetest,
    $validLicense,
    $passedTest
);

if (!$binliner->isValid()) {
    // Reject
    throw new Exception('Invalid state!');
}
// Just for convenience you can reason about intval((string)$binliner, 2);
if ($binliner->toInt() < 12) {
    // Accept
    return true;
}
// The only remaining valid state is '1111'
return handlePassedRetest($bob);
```

See [test/ExamplesTest.php](test/ExamplesTest.php) for more.

Testing
-------

[](#testing)

1. Clone this repo
2. `composer install`
3. `vendor/bin/phpunit`

Contributing
------------

[](#contributing)

Submit pull requests to \[\]

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

1534d ago

### Community

Maintainers

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

---

Top Contributors

[![sepiariver](https://avatars.githubusercontent.com/u/821671?v=4)](https://github.com/sepiariver "sepiariver (1 commits)")

---

Tags

validatortreebinaryheapsequenceconditional-logic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sepiariver-binliner-php/health.svg)

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[seld/jsonlint

JSON Linter

1.3k217.8M205](/packages/seld-jsonlint)[composer/spdx-licenses

SPDX licenses list and validation library.

1.4k184.2M25](/packages/composer-spdx-licenses)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15544.9M188](/packages/laminas-laminas-validator)

PHPackages © 2026

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