Download the PHP package max13/dtion without Composer
On this page you can find all versions of the php package max13/dtion. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package dtion
Short Description 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'.
License MIT
Homepage https://github.com/max13/dtion
Informations about the package 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
You can use composer: composer require max13/dtion
Usage
Using the examples above:
Need help?
Open an issue.
Now have fun.
All versions of dtion with dependencies
php Version ^7.0 || ^8.0