PHPackages                             wwaz/components-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. [Templating &amp; Views](/categories/templating)
4. /
5. wwaz/components-php

ActiveLibrary[Templating &amp; Views](/categories/templating)

wwaz/components-php
===================

A PHP library for managing and rendering data-driven UI components

v1.1.0(4w ago)04↓100%MITPHPPHP ^8.1CI passing

Since Apr 16Pushed 4w agoCompare

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

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

Components
==========

[](#components)

A PHP library for building data-driven UI components.

Define composable, nestable components that render plain data into clean HTML, XML, or SVG — declaratively, with built-in validation and no template engine needed.

Works great for rendering structured content from headless CMSs or APIs, generating server-side UI fragments, producing email markup, or assembling document-like output.

After installation:

```
$link = Factory::make('fragment.html.a', [
    'href'    => 'https://example.com',
    'class'   => 'btn btn-primary',
    'content' => 'Get started',
]);

echo $link->render();
// Get started
```

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

[](#installation)

```
composer require wwaz/components-php
```

Usage
-----

[](#usage)

### Register components

[](#register-components)

Register the namespace for your components once, then use it anywhere:

```
use wwaz\Components\Factory;

Factory::addNamespace('MyApp\\Components');
```

### Creating components

[](#creating-components)

A component is created by extending Component class. Each component defines its own properties, which can be freely configured and are passed during construction. Validation rules control the expected type and whether a value is required. Every component also requires a public markup() method that returns the component's markup.

```
namespace MyApp\Components;

use wwaz\Components\Component;

// Define the component class
class Card extends Component
{
    protected $properties = [
        'content' => [
            'title' => 'required|isString',
            'text'  => 'required|isString',
        ],
    ];
    public function markup(): string
    {
        return '
            ' . $this->content('title') . '
            ' . $this->content('text') . '
        ';
    }
}

// Create the component instance with its content
$component = new Card([
    'title' => 'My Card',
    'text' => 'My text'
]);

// Render and output the markup
echo $component->render();
```

### Validating Component properties

[](#validating-component-properties)

Properties are validated automatically before rendering. Declare rules in your component:

```
protected $properties = [
    'content' => [
        'title'  => 'required|isString|length:1,100',
        'status' => 'select:draft,published|default:draft',
        'teaser' => 'isString',
        'link' => 'isComponent|required'
    ],
];
```

Available validators and rule helpers in this package:

RuleDescription`required`The value must be present.`isString`The value must be a PHP string.`isInt`The value must be a PHP integer.`isNumber`The value must be numeric.`isComponent`The value must be an instance of a class extending `wwaz\Components\Component`.`select:foo,bar,baz`The value must match one of the listed options.`default:value`Sets a fallback value when the property is missing. This is a rule helper, not a validator.In addition to these package-specific rules, you can also use native `Respect\Validation` rules such as `length`, `boolVal`, and many others.

Invalid data stops execution with a clear HTML error message, which is helpful during development and easy to catch in production.

### Manipulating instances at runtime

[](#manipulating-instances-at-runtime)

Every fragment and component shares the same fluent API for attributes and classes:

```
$el = Factory::make('fragment.html.a', ['href' => '#']);

$el->setAttribute('aria-label', 'Home');
$el->addClass('is-active');
$el->addContent(' (current)');

echo $el->render();
//  (current)
```

On components you can also control the wrapper element:

```
$card->setWrapTag('article');
$card->addComponentClass('dark-mode');

echo $card->render();
// ...

// Or drop the wrapper entirely:
echo $card->render(false);
```

### Configuration

[](#configuration)

Global settings are inherited by all namespaces. Override per namespace as needed:

```
use wwaz\Components\Config;

Config::set('global', [
    'wrapComponent' => ['wrap' => true, 'tag' => 'div'],
]);

Config::set('MyApp\\Components', [
    'wrapComponent' => ['tag' => 'section', 'class' => 'my-app'],
    'url'           => ['images' => 'public/assets/images'],
]);

Config::get('MyApp\\Components', 'url.images');
// → 'public/assets/images'
```

Development
-----------

[](#development)

For contributor onboarding, local quality checks, and PR expectations, see [CONTRIBUTING.md](CONTRIBUTING.md).

Common local commands:

```
composer lint
composer stan
composer test
composer qa
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance94

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

Total

4

Last Release

29d ago

Major Versions

0.0.1 → 1.0.12026-04-16

### Community

Maintainers

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

---

Top Contributors

[![WWAZ](https://avatars.githubusercontent.com/u/25566288?v=4)](https://github.com/WWAZ "WWAZ (14 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3861.2M](/packages/limenius-react-bundle)[jelix/wikirenderer

WikiRenderer is a library to generate HTML or anything else from wiki content.

1712.2k1](/packages/jelix-wikirenderer)[webkinder/sproutset

A Composer package for handling responsive images in Roots Bedrock + Sage + Blade projects.

291.8k](/packages/webkinder-sproutset)

PHPackages © 2026

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