PHPackages                             vdhicts/conditions - 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. vdhicts/conditions

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

vdhicts/conditions
==================

Package for handling conditions

v1.4.0(1mo ago)05MITPHPPHP ^8.2CI passing

Since Nov 26Pushed 1mo ago1 watchersCompare

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

READMEChangelog (5)Dependencies (8)Versions (7)Used By (0)

Conditions
==========

[](#conditions)

This package offers a way to handle conditions for actions in your application. For example to check if a record has the required state (and which conditions are considered valid and/or invalid) or if a certain transition would be possible. See the Usage section for more examples.

Requirements
------------

[](#requirements)

This package requires PHP 8.1+.

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

[](#installation)

You can install the package via composer:

`composer require vdhicts/conditions`

Usage
-----

[](#usage)

### Terms

[](#terms)

- **Condition**: A condition is a single check which can be fulfilled or not. A condition can have a level, message and additional data.
- **ConditionCollection**: A collection of conditions.
- **ConditionLevel**: A condition level is a level which can be used to indicate the severity of a condition. Useful for displaying or filtering the conditions. Does not affect the fulfillment of a condition, so an info level condition which is not fulfilled is still a not fulfilled condition.
- **ConditionTransformer**: A condition transformer is used to transform a condition to another presentation or create the condition from another presentation.

### Condition

[](#condition)

First create a condition. A condition has at least a name. *When the fulfilled parameter is not provided, the condition is considered fulfilled.*

```
use Vdhicts\Conditions\Condition;
use Vdhicts\Conditions\Enums\ConditionLevel;

// Basic variant
$condition = new Condition(
    name: 'Contact has email address',
    fulfilled: $contact->email_address !== null,
);

// Extended variant
$condition = new Condition(
    name: 'Contact has email address',
    fulfilled: $contact->email_address !== null,
    level: ConditionLevel::Error,
    message: 'The contact needs to have an e-mail address to receive the newsletter.',
    data: [
        'contact_id' => $contact->id,
        'newsletter_id' => $newsletter->id,
    ]
);

// Fluent variant
$condition = (new Condition())
    ->setName('Contact has email address')
    ->setFulfilled($contact->email_address !== null)
    ->setLevel(ConditionLevel::Error)
    ->setMessage('The contact needs to have an e-mail address to receive the newsletter.')
    ->setData([
        'contact_id' => $contact->id,
        'newsletter_id' => $newsletter->id,
    ]);
```

### Condition collection

[](#condition-collection)

When you have multiple conditions, you can add them to a condition collection. A condition collection is considered fulfilled when all conditions in it are fulfilled or there aren't any conditions provided.

```
use Vdhicts\Conditions\ConditionCollection;

// Basic variant
$conditionCollection = new ConditionCollection(collect([
    new Condition('Contact has e-mail address', $contact->email_address !== null),
    new Condition('Contact has name', $contact->name !== null),
]));

// Fluent variant
$conditionCollection = (new ConditionCollection())
    ->add(new Condition('Contact has e-mail address', $contact->email_address !== null))
    ->add(new Condition('Contact has name', $contact->name !== null));
```

The collection can be checked if it is fulfilled or not.

```
$conditionCollection->isFulfilled(); // true or false
$conditionCollection->isNotFulfilled(); // true or false
```

To easily process the conditions, there are also some methods available to retrieve the conditions based on certain requirements.

```
$conditionCollection->get(); // Returns a collection of all conditions

$conditionCollection->getFulfilledConditions(); // Returns a collection of fulfilled conditions
$conditionCollection->getNotFulfilledConditions(); // Returns a collection of not fulfilled conditions

$conditionCollection->only([ConditionLevel::Error, ConditionLevel::Warning]); // Returns a condition collection of conditions with the provided levels
$conditionCollection->except([ConditionLevel::Info]); // Returns a condition collection of conditions without the provided levels
```

It's also possible to merge multiple collections to one.

```
$conditionCollection->merge($otherConditionCollection);
```

### Transformer

[](#transformer)

A transformer can be used to transform a condition to another presentation or create the condition from another presentation.

```
use Vdhicts\Conditions\Condition;
use Vdhicts\Conditions\ConditionTransformer;

// Transform a condition to an array
$array = ConditionTransformer::toArray(new Condition(
    name: 'Contact has email address',
    fulfilled: $contact->email_address !== null,
));

// Transform an array to a condition
$condition = ConditionTransformer::fromArray([
    'name' => 'Contact has email address',
    'fulfilled' => $contact->email_address !== null,
]);
```

Contribution
------------

[](#contribution)

Found a bug or want to add a new feature? Great! There are also many other ways to make meaningful contributions such as reviewing outstanding pull requests and writing documentation. Even opening an issue for a bug you found is appreciated.

Security
--------

[](#security)

If you discover any security related issues in this or other packages of Vdhicts, please email instead of using the issue tracker.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

About Vdhicts
-------------

[](#about-vdhicts)

[Vdhicts](https://www.vdhicts.nl) develops and implements IT solutions for businesses based on the Laravel framework.

###  Health Score

44

—

FairBetter than 91% of packages

Maintenance95

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

5

Last Release

51d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.3.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/88d23e7b707d1cfe0eea91c00590613f45e0c75cb0a3ce89354328332e5c0c02?d=identicon)[vdhicts](/maintainers/vdhicts)

---

Top Contributors

[![dvdheiden](https://avatars.githubusercontent.com/u/90568118?v=4)](https://github.com/dvdheiden "dvdheiden (6 commits)")

---

Tags

conditions

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vdhicts-conditions/health.svg)

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

###  Alternatives

[illuminate/support

The Illuminate Support package.

583107.1M34.4k](/packages/illuminate-support)[pragmarx/countries

PHP Countries and Currencies

1.9k3.3M18](/packages/pragmarx-countries)[illuminate/events

The Illuminate Events package.

13454.3M1.7k](/packages/illuminate-events)[illuminate/config

The Illuminate Config package.

10842.7M2.2k](/packages/illuminate-config)[illuminate/pagination

The Illuminate Pagination package.

10532.5M857](/packages/illuminate-pagination)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.5M177](/packages/illuminate-broadcasting)

PHPackages © 2026

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