PHPackages                             decodelabs/lucid - 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. decodelabs/lucid

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

decodelabs/lucid
================

Flexible and expansive sanitisation and validation framework

v0.8.1(7mo ago)319.4k112MITPHPPHP ^8.4CI passing

Since Sep 7Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/decodelabs/lucid)[ Packagist](https://packagist.org/packages/decodelabs/lucid)[ RSS](/packages/decodelabs-lucid/feed)WikiDiscussions develop Synced 1w ago

READMEChangelog (10)Dependencies (5)Versions (31)Used By (12)

Lucid
=====

[](#lucid)

[![PHP from Packagist](https://camo.githubusercontent.com/f2f7ad6b354d4549ec88cb54f17d7386dc4cd3d076920702473d3e2fcae6d5e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6465636f64656c6162732f6c756369643f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/lucid)[![Latest Version](https://camo.githubusercontent.com/f41e8b92cbd76dd9a7de851204d0d7044b028f7fc0e5fd6145fef4a741020b43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465636f64656c6162732f6c756369642e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/lucid)[![Total Downloads](https://camo.githubusercontent.com/7d0ce6e572abe63885f6d373b599462c061e0b08b6d1c3d3bcb7a8f9106e902a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465636f64656c6162732f6c756369642e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/lucid)[![GitHub Workflow Status](https://camo.githubusercontent.com/5e61ac8afd4e000020f3d4bc545ff451f625e2341ae27ad011946e48b1fba0a5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6465636f64656c6162732f6c756369642f696e746567726174652e796d6c3f6272616e63683d646576656c6f70)](https://github.com/decodelabs/lucid/actions/workflows/integrate.yml)[![PHPStan](https://camo.githubusercontent.com/e25c14ce011edabdd0fbd2e10415b41cc5d66ed11ef3e5b7edd074c5bdd35a2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d3434434331312e7376673f6c6f6e6743616368653d74727565267374796c653d666c6174)](https://github.com/phpstan/phpstan)[![License](https://camo.githubusercontent.com/8b3bf44b1596baf3098cf2d48fa154e6d3b53281bd613b5799265d8181df4147/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465636f64656c6162732f6c756369643f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/lucid)

### Flexible and expansive sanitisation and validation framework for PHP

[](#flexible-and-expansive-sanitisation-and-validation-framework-for-php)

Lucid provides a unified single-value sanitisation and validation structure for making sure your input makes sense.

---

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

[](#installation)

This package requires PHP 8.4 or higher.

Install via Composer:

```
composer require decodelabs/lucid
```

Usage
-----

[](#usage)

Direct value sanitisation can be achieved quickly and painlessly:

```
use DecodeLabs\Lucid;
$lucid = new Lucid();

// This ensures the value is a string
$myString = $lucid->cast('This is a string', 'string');

// This is nullable
$notAString = $lucid->cast(null, '?string');

// These are constraints - throws an exception
$myString = $lucid->cast('My very long piece of text', 'string', [
    'maxLength' => 10,
    'maxWords' => 4
]);

// Creates an instance of Carbon (DateTime)
$myDate = $lucid->cast('tomorrow', 'date', [
    'min' => 'yesterday',
    'max' => '+3 days'
]);
```

If you need more fine grained control of the responses to constraints, use `validate()`:

```
$result = $lucid->validate('potato', 'int', [
    'min' => 4
]);

if(!$result->valid) {
    // Do something with the potato

    foreach($result->errors as $error) {
        echo $error->message;
    }
}
```

Or conversely if you just need a yes or no answer, use `is()`:

```
if(!$lucid->is('not a number', 'float')) {
    // do something
}
```

Custom processors
-----------------

[](#custom-processors)

Lucid uses [Archetype](https://github.com/decodelabs/archetype) to load both `Processors` and `Constraints` - implement your own custom classes within `DecodeLabs\Lucid\Processor` or `DecodeLabs\Lucid\Constraint` namespaces, or create your own Archetype `Resolver` to load them from elsewhere.

Please see the selection of existing implementations for details on how to build your own custom classes.

Provider interfaces
-------------------

[](#provider-interfaces)

Lucid builds on a sub-package, [Lucid Support](https://github.com/decodelabs/lucid-support) which makes available a set of `Provider` interfaces to enable embedded implementations of the Sanitizer structure.

Please see the readme in [Lucid Support](https://github.com/decodelabs/lucid-support) for integrating Lucid into your own libraries.

Licensing
---------

[](#licensing)

Lucid is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance67

Regular maintenance activity

Popularity31

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 98.8% 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 ~39 days

Recently: every ~9 days

Total

29

Last Release

233d ago

PHP version history (3 changes)v0.1.0PHP ^8.0

v0.4.2PHP ^8.1

v0.5.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a241d64d12b3b5ee94197862ec1ec30b82ed2efa34a0cd7f4c3565a021daddd?d=identicon)[betterthanclay](/maintainers/betterthanclay)

---

Top Contributors

[![betterthanclay](https://avatars.githubusercontent.com/u/1273586?v=4)](https://github.com/betterthanclay "betterthanclay (170 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (2 commits)")

---

Tags

phpsanitizationvalidationvalidationinputsanitisation

### Embed Badge

![Health badge](/badges/decodelabs-lucid/health.svg)

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k489.6M672](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8412.9M47](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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