PHPackages                             texditor/blockify-php - 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. texditor/blockify-php

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

texditor/blockify-php
=====================

Working with the Texditor block data. Validation and sanitization of blocks.

2.1.4(1mo ago)079MITPHPPHP &gt;=8.1

Since Aug 14Pushed 1mo agoCompare

[ Source](https://github.com/texditor/blockify-php)[ Packagist](https://packagist.org/packages/texditor/blockify-php)[ Docs](https://texditor.priveted.com)[ RSS](/packages/texditor-blockify-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (3)Versions (25)Used By (0)

Blockify
========

[](#blockify)

Blockify is a PHP library designed for processing and visualizing structured content, which is presented in the form of `texditror/editror` () blocks. It provides validation, sanitization, and output of data in HTML format.

Features
--------

[](#features)

- Process JSON or array input into structured blocks
- Validate block data against configurable models
- Merge similar adjacent content items
- Render blocks to HTML with customizable output
- Development mode for error handling

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

[](#installation)

Install via Composer:

```
composer require texditor/blockify-php
```

Basic Usage
-----------

[](#basic-usage)

```
use Texditor\Blockify\Blockify;
use Texditor\Blockify\Config;
use Texditor\Blockify\Models\ParagraphBlock;
use Texditor\Blockify\Models\CodeBlock;
use Texditor\Blockify\Models\FileBlock;
use Texditor\Blockify\Models\ImageBlock;
use Texditor\Blockify\Models\HeaderBlock;
use Texditor\Blockify\Models\OrderedListBlock;
use Texditor\Blockify\Models\UnorderedListBlock;

// Initialize configuration
$config = (new Config())
    ->addModels(
        (new ParagraphBlock())
          ->setAllowedTags(['a', 'b']),
        new CodeBlock(),
        (new FileBlock())
            ->setSourceProtocols(['https', 'http'])
            ->transformItem(function ($item) {
                $item['hello'] = 'world';
                return $item;
            }),
            ->setSourceHosts([
                'priveted.com',
                'github.com'
            ])
            // or only locally
            ->setSourceRegex(["/^\/uploads\/.*\.(png|jpg|jpeg|gif)$/"]),
        (new ImageBlock())
            ->setIsLinkStrategy(true) // the old strategy, use IDs
            // ->setIsMeta(true)
            // ->setIsMetaCaption(true)
            // ->setIsMetaDesc(false)
            ->setSourceHosts([
                'priveted.com',
                'myimageserver.com'
            ])
            ->setSourceProtocols(['https'])
            ->setMetaPosition('top')
            ->setImageTypes(['image/png', 'image/jpeg'])
            ->setVideoTypes(['video/mp4'])
            ->setVideoAttributes([
                'controls' => 'true'
            ]),

        new VideoBlock(),
        new UnorderedListBlock(),
        new OrderedListBlock(),
        // Default h1
        new HeaderBlock(),
        (new HeaderBlock())
            ->setOutputName('h2')
            ->setInputName('h2'),
            //... and other block model methods (Texditor\Blockify\BlockModel)
    );
// Dev mode
$config->setDev(true);

// Process data
$blockify = (new Blockify($config))
    ->setData($jsonData);

// Or if filters are needed
$blockify
    ->filter(function (array $block, int $index, BlockModelInterface $model) {
        if ($model->isPreformatted())
            return false;

        if ($block['type'] == 'p')
            return false;

        return true;
    })
    ->dataFilter(function (
        array|string $item,
        int $index,
        array $block,
        int $blockIndex,
        BlockModelInterface $model
    ) {
        if (
            is_array($item) &&
            $block['type'] == 'gallery' &&
            empty($item['id'])
        ) {
            return false;
        }

        return true;
    });

// Get secure and processed data
$blocks = $blockify->getData();
```

### Error Handling

[](#error-handling)

```
//...
$blockify = new Blockify($config);

if (!$blockify->isValid()) {
    $errors = $blockify->getErrors();
    // Handle errors
}
```

### Rendering

[](#rendering)

```
use Texditor\Blockify\HtmlBuilder;

//...
// Initializes the HTML builder with security and rendering settings.
$htmlBuilder = new HtmlBuilder($config);

// Renders all provided blocks into a safe HTML string.
$html = $htmlBuilder->render($blocks);

// Renders all blocks into plain text, stripping all HTML tags.
$text = $htmlBuilder->renderAsText($blocks);

// Renders only the specified block types ('p', 'h1') into HTML.
$html = $htmlBuilder->renderOnly($blocks, ["p", "h1"]);

// Renders only the specified block types into plain text.
$text = $htmlBuilder->renderOnly($blocks, ["p", "h1"], true);
```

Available Block Models
----------------------

[](#available-block-models)

The library includes these default block models:

- `ParagraphBlock` - For text paragraphs
- `CodeBlock` - For code snippets
- `FileBlock` - For file attachments
- `ImageBlock` - For image attachments
- `VideoBlock` - For video attachments
- `FilesBlock (deprecated)` - For file attachments
- `GalleryBlock (deprecated)` - For image/video galleries
- `HeaderBlock` - For headings (h1-h6)
- `OrderedListBlock` - For numbered lists
- `UnorderedListBlock` - For bulleted lists

Configuration Options
---------------------

[](#configuration-options)

- `addModels()` - Register block models
- `setDev()` - Enable/disable development mode
- `setBlockCssPrefix()` - Set CSS class prefix
- `setRenderTagNames()` - Customize HTML tag names
- `setRenderBlockNames()` - Customize block output tags

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance93

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.1% 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 ~14 days

Recently: every ~5 days

Total

24

Last Release

34d ago

Major Versions

1.1.0 → 2.0.02026-06-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/202995908?v=4)[texditor](/maintainers/texditor)[@texditor](https://github.com/texditor)

---

Top Contributors

[![texditor](https://avatars.githubusercontent.com/u/202995908?v=4)](https://github.com/texditor "texditor (33 commits)")[![priveted](https://avatars.githubusercontent.com/u/18353516?v=4)](https://github.com/priveted "priveted (1 commits)")

---

Tags

phpvalidatorsanitizermanagerblockstexditor

### Embed Badge

![Health badge](/badges/texditor-blockify-php/health.svg)

```
[![Health](https://phpackages.com/badges/texditor-blockify-php/health.svg)](https://phpackages.com/packages/texditor-blockify-php)
```

PHPackages © 2026

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