PHPackages                             aight8/draft-php-validator - 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. aight8/draft-php-validator

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

aight8/draft-php-validator
==========================

A library which validates and clean the ContentState

0200PHP

Since Jan 11Pushed 9y agoCompare

[ Source](https://github.com/aight8/draft-php-validator)[ Packagist](https://packagist.org/packages/aight8/draft-php-validator)[ RSS](/packages/aight8-draft-php-validator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Draft.php
=========

[](#draftphp)

A validation library which build on top of the draft-php library.

[![Latest Version on Packagist](https://camo.githubusercontent.com/cf603816c534e74f06730601b19b52fa35f0a0f1076da71cde5f91a20109a1cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6169676874382f64726166742d7068702d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aight8/draft-php-validator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/052c3df2e1e462e372910e4fc8e1343caef6e6e874c5ce2124bfe37fc0725431/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6169676874382f64726166742d7068702d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/aight8/draft-php-validator)[![Total Downloads](https://camo.githubusercontent.com/51112eeaff2066dd4800bdc2fdc1e37fca0b9333ee321c49732dad40359c0cc0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6169676874382f64726166742d7068702d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aight8/draft-php-validator)

This library validates the content state by the given configuration.

Optional: Additionally it can Autofix invalid content states if possible.

Features
--------

[](#features)

##### Validate the block depth

[](#validate-the-block-depth)

- **Is possible on target block type** (Autofix: Set to 0)
- **Depth raises in incremental steps** (Autofix: Set to last valid depth)
- **Maximal depth** (Autofix: Set to maximum depth)

##### Allows only specific...

[](#allows-only-specific)

- **Content block types** (Autofix: Set to default block type)
- **Entity types** (Autofix: Remove from ContentBlock and EntityMap)
- **Inline styles** (Autofix: Remove from ContentBlock)

##### Check for limits when set...

[](#check-for-limits-when-set)

- **Character count** (no Autofix)
- **Word count** (no Autofix)
- **Line count** (no Autofix)

##### ContentBlock

[](#contentblock)

- **No newline character** - called soft newlines in draft.js (Autofix: Split block)

##### CharacterMetadata

[](#charactermetadata)

- **Entity must reference to an existing entity in the entity map** (Autofix: Remove from ContentBlock)

##### EntityMap

[](#entitymap)

- **Not referenced entities** (Autofix: Remove from EntityMap)
- **Validat entity data** (Autofix: filter the entity data)

More Features
-------------

[](#more-features)

- Unicode Characters are handled correctly
- draft.js Defaults are included (Block Types, Inline Styles, List Block Types)

Usage
-----

[](#usage)

The default configuration of the ValidatorConfig is lazy and contains only the very basics.

### ValidatorConfig class

[](#validatorconfig-class)

```
public function __construct(array $config = null)

```

The passed configuration array can contains following options:

Configuration keyTypeDescriptionDefault valuecontent\_block\_max\_depth...int4content\_block\_types...string\[\]?Defaults::BLOCK\_TYPESinline\_styles...string\[\]?Defaults::INLINE\_STYLESentity\_types...string\[\]?\[\]entity\_validator...callback(DraftEntity):DraftEntity?nullblock\_types\_with\_depth...string\[\]?Defaults::LIST\_BLOCK\_TYPESincremental\_depth\_steps...booltruemax\_character\_count...int?nullmax\_word\_count...int?nullmax\_line\_count...int?null`content_block_types`, `inline_styles`, `entity_types`, `block_types_with_depth` have all a default value (the default constants in draft.js).

- If one of those values is set to `null` - then everything is allowed.
- If one of those values is set to `[]` then nothing is allowed.

### Validator class

[](#validator-class)

The relevant validation function is this one:

```
public function validate(ContentState $contentState, $validatorConfig = null, $tryAutoFix = null)
```

If the third parameter `tryAutoFix` is true, it autofixes all invalid catches. **Excepted for character/word/line limitations!** This will always throw an exception.

If `tryAutoFix` is false then it always throws an exception on the first invalid catch.

By default autofix is enabled because this is the most common use case.

### Future

[](#future)

- Optional Autofix for max char/word/line count by shrinking when it overlaps But this is not default since data loss should be never the default. However this limitation checks should be implemented on the client side first! This is only a safety check.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

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

---

Top Contributors

[![aight8](https://avatars.githubusercontent.com/u/1138623?v=4)](https://github.com/aight8 "aight8 (5 commits)")

### Embed Badge

![Health badge](/badges/aight8-draft-php-validator/health.svg)

```
[![Health](https://phpackages.com/badges/aight8-draft-php-validator/health.svg)](https://phpackages.com/packages/aight8-draft-php-validator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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