PHPackages                             preflow/components - 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. preflow/components

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

preflow/components
==================

Preflow components — component base class, renderer, error boundaries

v0.13.1(1mo ago)0454MITPHPPHP &gt;=8.4

Since Apr 10Pushed 1mo agoCompare

[ Source](https://github.com/getpreflow/components)[ Packagist](https://packagist.org/packages/preflow/components)[ RSS](/packages/preflow-components/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (32)Used By (4)

preflow/components
==================

[](#preflowcomponents)

Core component system for Preflow. Provides an abstract base class, a renderer with lifecycle management, an error boundary, and a Twig integration.

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

[](#installation)

```
composer require preflow/components
```

Requires PHP 8.4+.

What it does
------------

[](#what-it-does)

Each component is a PHP class co-located with a `.twig` template. The renderer calls `resolveState()` (load data from DB, session, etc.) then renders the template with the component's public properties as variables. The output is wrapped in a tagged element keyed by a stable component ID.

Errors are caught by `ErrorBoundary`: in dev mode it renders an inline panel with the exception class, message, component class, props, lifecycle phase, and stack trace; in prod mode it calls the component's `fallback()` or renders a hidden ``.

API
---

[](#api)

### `Component` (abstract base class)

[](#component-abstract-base-class)

MethodDescription`resolveState(): void`Override to load data before render.`actions(): string[]`Return allowed action names for this component.`action{Name}(array $params): void`Implement one method per declared action.`fallback(\Throwable $e): ?string`Return fallback HTML on error (prod only). Return `null` to hide.`setProps(array $props): void`Set props from outside (called by the renderer/extension).`getProps(): array`Read current props.`getComponentId(): string``ShortClassName-{propsHash}` — stable across renders with same props.`getTag(): string`Wrapper HTML tag (default `div`). Override `$tag` to change.Public properties are automatically exposed as Twig template variables alongside `componentId`.

### `ComponentRenderer`

[](#componentrenderer)

```
$renderer->render(Component $component): string                  // full lifecycle + wrapper
$renderer->renderFragment(Component $component): string          // inner HTML only (for HTMX partials)
$renderer->renderResolved(Component $component): string          // skip resolveState (after action dispatch)
$renderer->renderResolvedFragment(Component $component): string  // skip resolveState, inner HTML only
```

`renderResolvedFragment()` combines the two partial-render flags: it skips `resolveState()` (state was already mutated by an action) and returns inner HTML without the wrapper element. Used by `ComponentEndpoint` when the HTMX target does not match the component's own ID.

### `ComponentExtension` (Twig)

[](#componentextension-twig)

Registers `{{ component('Name', {props}) }}`. Component names are resolved via a short-name → FQCN map or a fully-qualified class name.

Usage
-----

[](#usage)

**Component class** (`src/Components/Counter/Counter.php`):

```
use Preflow\Components\Component;

final class Counter extends Component
{
    public int $count = 0;

    public function resolveState(): void
    {
        $this->count = (int) ($_SESSION['count'] ?? 0);
    }

    public function actions(): array
    {
        return ['increment'];
    }

    public function actionIncrement(array $params): void
    {
        $this->count++;
        $_SESSION['count'] = $this->count;
    }
}
```

**Template** (`src/Components/Counter/Counter.twig`):

```
Count: {{ count }}
+1
```

**In a page template:**

```
{{ component('Counter', { initialCount: 0 }) }}

{# Or using a fully-qualified class name: #}
{{ component('App\\Components\\Counter\\Counter') }}
```

**Register the extension:**

```
$componentMap = ['Counter' => App\Components\Counter\Counter::class];
$twig->addExtension(new ComponentExtension($renderer, $componentMap));
```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance89

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

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

Total

31

Last Release

53d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d8b54efbc79683c32645e3fa8d3590037fa003963a16e0ed989104c6f4a2723?d=identicon)[smyr](/maintainers/smyr)

---

Top Contributors

[![smeyerme](https://avatars.githubusercontent.com/u/1925560?v=4)](https://github.com/smeyerme "smeyerme (21 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/preflow-components/health.svg)

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

###  Alternatives

[react/zmq

ZeroMQ bindings for React.

2471.7M33](/packages/react-zmq)[maritos/magento2-performance-fixes

Magento 2 performance fixes.

6321.8k](/packages/maritos-magento2-performance-fixes)[microinginer/yii2-cbrf-rates

1019.5k](/packages/microinginer-yii2-cbrf-rates)[balbuf/composer-wp

Manage WordPress core, plugins, and themes with composer.

173.6k](/packages/balbuf-composer-wp)

PHPackages © 2026

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