PHPackages                             max13/dtion - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. max13/dtion

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

max13/dtion
===========

Dtion allows you to serialize and unserialize conditions and results. For instace: if $x between 'A' and 'C', result is 'X'. Else if $x between 'D' and 'F', result is 'Y'.

v1.4.0(3y ago)018MITPHPPHP ^7.0 || ^8.0

Since Aug 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Max13/dtion)[ Packagist](https://packagist.org/packages/max13/dtion)[ Docs](https://github.com/max13/dtion)[ RSS](/packages/max13-dtion/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (8)Used By (0)

Dtion
=====

[](#dtion)

How to serialize and store multiple if/else and the values corresponding to the different conditions?

`Dtion` is a serializable classes allowing you to store a condition and result. `Dtion` can store `string`, `int`, `float`, `callable` and `Stringable` values as boudaries and result. `callable` boundaries are evaluated during comparison but the result is returned as stored.

`DtionList` is also serializable and is used to store a list of `Dtion`, allowing you to `find()` the `Dtion` matching a given criterion, if any. `DtionList` can also directly return the `resultFor()` a matching criterion.

Example, you can store conditions like:

- If the **category** of the employee is **between 1 and 5**, the *prior notice* is **1 month**.
- If the **category** of the employee is **between 6 and 7**, the *prior notice* is **2 months**.
- If the **category** of the employee is **between 8 and 12**, the *prior notice* is **3 months**.

Here is another example using date intervals as conditions:

- If the **fixed term contract** lasts from 0 to **6 months**, then the *trial period* is **15 days**.
- Above **6 months**, the *trial period* is **1 month**.

Expressing these intervals (as `DateInterval` or `CarbonInterval`) as conditions with `Dtion` is easy. See bellow.

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

[](#installation)

You can use composer: `composer require max13/dtion`

Usage
-----

[](#usage)

Using the examples above:

```
use Dtion\Dtion;
use Dtion\DtionList;

$priorNoticeList = new DtionList([
    new Dtion(1, 5, new DateInterval('P1M'),
    new Dtion(6, 7, new DateInterval('P2M'),
    new Dtion(8, 12, new DateInterval('P3M'),
]);

$category = 2;
$p = $priorNoticeList->resultFor($category);
// returns DateInterval('P1M')

$dtion = $priorNoticeList->find($category);
// returns the corresponding Dtion, or null if not found.
$result = $dtion->result();
```

Need help?
----------

[](#need-help)

Open an issue.

Now have fun.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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 ~4 days

Total

6

Last Release

1401d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/531249?v=4)[Adnan RIHAN](/maintainers/Max13)[@Max13](https://github.com/Max13)

---

Top Contributors

[![Max13](https://avatars.githubusercontent.com/u/531249?v=4)](https://github.com/Max13 "Max13 (22 commits)")

---

Tags

serializationconditional

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/max13-dtion/health.svg)

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

###  Alternatives

[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k234.9M326](/packages/opis-closure)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k141.9M929](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k92.4M679](/packages/jms-serializer-bundle)[google/flatbuffers

FlatBuffers for PHP

26.1k148.3k5](/packages/google-flatbuffers)[apache/avro

Apache Avro™ is a data serialization system.

3.3k60.2k3](/packages/apache-avro)[flix-tech/avro-serde-php

A library to serialize and deserialize Avro records making use of the confluent schema registry

684.2M21](/packages/flix-tech-avro-serde-php)

PHPackages © 2026

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