PHPackages                             maximaster/attributemplate - 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. maximaster/attributemplate

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

maximaster/attributemplate
==========================

Create dynamic templates for your classes using attributes.

1.0.0(1y ago)0101MITPHPPHP &gt;=8.3

Since Apr 17Pushed 1y ago2 watchersCompare

[ Source](https://github.com/maximaster/attributemplate)[ Packagist](https://packagist.org/packages/maximaster/attributemplate)[ RSS](/packages/maximaster-attributemplate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (2)Used By (1)

maximaster/attributemplate
==========================

[](#maximasterattributemplate)

This library generates new classes from templates by resolving attributes into executable logic. Ideal for scenarios like creating database migrations from templates, configuration generation, etc.

Features
--------

[](#features)

### 1. Attribute-Driven Template Customization

[](#1-attribute-driven-template-customization)

Define templates using PHP attributes to dynamically set class names, constants, and other properties:

```
#[Rename(new EvalString('sprintf("Version%s", date("YmdHis"))')]
class MigrationTemplate {
    #[SetValue(new Guid())]
    public const ID = '';
}
```

### 2. Lazy Evaluation Providers

[](#2-lazy-evaluation-providers)

Use built-in providers to resolve values at runtime:

- `EvalString`: Execute PHP expressions (e.g., `new EvalString('uniqid()')`)
- `Guid`: Generates UUIDs
- `Expression`: Evaluate Symfony expressions
- `Param`: Inject values from context

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

[](#installation)

```
composer require maximaster/attributemplate
```

Usage Example
-------------

[](#usage-example)

#### Input Template

[](#input-template)

```
// examples/001/input.php
namespace App;

use Maximaster\Attributemplate\TemplateAttribute\Rename;
use Maximaster\Attributemplate\TemplateAttribute\SetValue;
use Maximaster\Attributemplate\JustScalar\EvalString;
use Ramsey\Uuid\Uuid;

#[Rename(new EvalString('sprintf("Version%s", date("YmdHis"))'))]
class Migration
{
    #[SetValue(new EvalString('Uuid::uuid5("namespace", "name")->toString()'))]
    public const ID = '';
}
```

#### Generated Output

[](#generated-output)

```
// examples/001/output.php
namespace App;

class Version20230101120000
{
    public const ID = '550e8400-e29b-41d4-a716-446655440000';
}
```

Available Attributes
--------------------

[](#available-attributes)

### `@Rename`

[](#rename)

Dynamically rename the class:

```
#[Rename(new EvalString('MyDynamicName'))]
class Base {}
// Output: class MyDynamicName {}
```

### `@SetValue`

[](#setvalue)

Set constant/property values:

```
#[SetValue(new Guid())]
public const UUID = '';
// Output: public const UUID = '123e4567-e89b-12d3-a456-426614174000';
```

Quirks &amp; Considerations
---------------------------

[](#quirks--considerations)

⚠️ **Security Note**: `EvalString` executes arbitrary PHP code - only use trusted expressions.

⚠️ Requires **PHP 8.3+** and Nette\\PhpGenerator.

⚠️ Attributes can only be applied to:

- Classes
- Class constants
- Parameters
- Properties

Contributing
------------

[](#contributing)

- test with `composer test`
- lint with `composer lint` (also see `composer fix`)
- `composer qa` shortcuts both `test` and `lint`

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance47

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community10

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

Unknown

Total

1

Last Release

391d ago

### Community

Maintainers

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

---

Top Contributors

[![mlavrinenko](https://avatars.githubusercontent.com/u/15840214?v=4)](https://github.com/mlavrinenko "mlavrinenko (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/maximaster-attributemplate/health.svg)

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

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.1k23.1k9](/packages/tempest-framework)[livewire/blaze

A tool for optimizing Blade component performance by folding them into parent templates

688221.3k17](/packages/livewire-blaze)[twigstan/twigstan

TwigStan is a static analyzer for Twig templates powered by PHPStan

27412.1k](/packages/twigstan-twigstan)[viewi/viewi

Powerful tool for building progressive and completely reactive web applications

5911.7k6](/packages/viewi-viewi)

PHPackages © 2026

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