PHPackages                             nabeghe/risma - 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. nabeghe/risma

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

nabeghe/risma
=============

A lightweight, flexible string processing and template engine for PHP with function chaining support.

v1.0.0(1mo ago)24MITPHPPHP &gt;=7.4

Since Feb 3Pushed 4mo agoCompare

[ Source](https://github.com/nabeghe/risma-php)[ Packagist](https://packagist.org/packages/nabeghe/risma)[ Docs](https://github.com/nabeghe/risma-php)[ RSS](/packages/nabeghe-risma/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

Risma for PHP ≥ 7.4
===================

[](#risma-for-php--74)

> A lightweight, flexible string processing and template engine for PHP with function chaining support.

**Risma** is a lightweight, high-performance string processing engine for PHP. It allows you to transform raw text into dynamic content using a flexible, pipe-like syntax. Whether you're building a template system, a dynamic notification builder, or a content sanitizer, Risma provides a clean interface to chain functions and variables seamlessly.

---

Key Features
------------

[](#key-features)

- **Variable Injection:** Easily replace placeholders with dynamic data.
- **Function Chaining:** Pipe data through multiple functions using dot notation.
- **Nested Placeholders:** Support for recursive placeholder resolution in function arguments.
- **Global &amp; Custom Functions:** Use native PHP functions or register your own logic.
- **Class Integration:** Directly map class methods to your processing pipeline.
- **Escaping Mechanism:** Built-in support for literal braces using `!{}`.
- **Clean Syntax:** Intuitive `{var.func1.func2}` syntax.
- Compatible with PHP 7.4+

---

🫡 Usage
-------

[](#-usage)

### 🚀 Installation

[](#-installation)

You can install the package via composer:

```
composer require nabeghe/risma
```

Or manually include the Risma.php if you want to keep it old school.

```
use Nabeghe\Risma\Risma;

$risma = new Risma();
```

Basic Example
-------------

[](#basic-example)

### 1. Simple Variables

[](#1-simple-variables)

Pass an associative array of variables to the render method.

```
$text = "Hello {name}!";
echo $risma->render($text, ['name' => 'Hadi']);
// Output: Hello Hadi!
```

### 2. Function Chaining

[](#2-function-chaining)

Transform variables on the fly by chaining functions. The output of one function becomes the first argument of the next.

```
// Using native PHP functions (strtoupper)
$text = "Welcome, {user.strtoupper}!";
echo $risma->render($text, ['user' => 'alice']);
// Output: Welcome, ALICE!
```

### 3. Arguments &amp; Native Logic

[](#3-arguments--native-logic)

You can pass arguments to functions just like in PHP.

```
$text = "Profile: {slug.str_replace('-', ' ')}";
echo $risma->render($text, ['slug' => 'hello-world']);
// Output: Profile: hello world
```

### 4. Direct Function Calls (@)

[](#4-direct-function-calls-)

Starting an expression with @ triggers a direct function call without requiring a variable.

```
$text = "Current Year: {@date('Y')}";
echo $risma->render($text, []);
// Output: Current Year: 2026
```

Built-in Functions
------------------

[](#built-in-functions)

Risma comes with several helpful built-in functions that you can use out of the box:

### exists

[](#exists)

Returns `'1'` if the value is not empty or null, otherwise returns `'0'`.

```
echo $risma->render('{name.exists}', ['name' => 'Hadi']);
// Output: 1

echo $risma->render('{name.exists}', ['name' => '']);
// Output: 0
```

### ok

[](#ok)

Returns '1' if the value is truthy, otherwise returns '0'.

```
echo $risma->render('{status.ok}', ['status' => true]);
// Output: 1

echo $risma->render('{status.ok}', ['status' => false]);
// Output: 0
```

### prepend

[](#prepend)

Adds a prefix to the beginning of the value.

```
echo $risma->render('{name.prepend("Mr. ")}', ['name' => 'Hadi']);
// Output: Mr. Hadi
```

### append

[](#append)

Adds a suffix to the end of the value.

```
echo $risma->render('{domain.append(".com")}', ['domain' => 'example']);
// Output: example.com
```

You can also chain these with other functions:

```
echo $risma->render('{name.strtoupper.prepend("Hello, ").append("!")}', ['name' => 'hadi']);
// Output: Hello, HADI!
```

Advanced Configuration
----------------------

[](#advanced-configuration)

### Custom Functions

[](#custom-functions)

Register specific callbacks that are only available within Risma.

```
$risma->addFunc('greet', function($name) {
    return "Hi, " . ucfirst($name);
});

echo $risma->render("{name.greet}", ['name' => 'Hadi']);
// Output: Hi, Hadi
```

### Registering Classes

[](#registering-classes)

Make an entire class's methods available to your text processor.

```
class StringHelper {
    public static function bold($text) {
        return "$text";
    }
}

$risma->addClass(StringHelper::class);
echo $risma->render("{title.bold}", ['title' => 'Risma']);
// Output: Risma
```

### Nested Placeholders

[](#nested-placeholders)

Risma supports nested placeholders, allowing you to embed variables and expressions inside function arguments.

```
// Simple nested variable
echo $risma->render('{@strtoupper("{name}")}', ['name' => 'hadi']);
// Output: HADI

// Multiple nested placeholders
echo $risma->render('{@str_replace("{old}", "{new}", "{text}")}', [
    'old' => 'foo',
    'new' => 'bar',
    'text' => 'hello foo world'
]);
// Output: hello bar world

// Deep nesting with function chains
echo $risma->render('{@sprintf("%s %s", "{@ucfirst("{first}")}", "{@ucfirst("{last}")}")}', [
    'first' => 'hadi',
    'last' => 'akbarzadeh'
]);
// Output: Hadi Akbarzadeh
```

Nested placeholders are recursively processed from the innermost to the outermost level, giving you full flexibility in building complex dynamic templates.

### Escaping

[](#escaping)

If you need to display the braces literally, prefix them with an exclamation mark.

```
echo $risma->render("This is !{ignored}", []);
// Output: This is {ignored}
```

API Reference
-------------

[](#api-reference)

`render(string $text, array $vars, bool $default = true): string`Processes the string.

- $text: The raw string containing `{}` tags.
- $vars: Key-value pair of data.
- $default: If `true`, returns empty string for missing variables. If `false`, throws an Exception.

`addFunc(string $name, callable $callback): void`Registers a custom function to the internal engine.

`addClass(string $className): void`Registers a class. Risma will look for methods within this class when processing chains.

### Syntax Rules at a Glance

[](#syntax-rules-at-a-glance)

SyntaxDescription`{var}`Simple variable replacement.`{var.func}`Pass variable to `func`.`{var.f1.f2}`Chain: `f2(f1(var))`.`{@func()}`Execute a function directly without a variable.`{@func("{var}")}`Nested placeholder inside function arguments.`!{var}`Escape the tag (returns `{var}`).`{var.func('arg')}`Pass additional arguments.📖 License
---------

[](#-license)

Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance82

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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

Total

3

Last Release

31d ago

Major Versions

v0.2.0 → v1.0.02026-06-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12207627?v=4)[Hadi Akbarzadeh](/maintainers/nabeghe)[@nabeghe](https://github.com/nabeghe)

---

Top Contributors

[![nabeghe](https://avatars.githubusercontent.com/u/12207627?v=4)](https://github.com/nabeghe "nabeghe (2 commits)")

---

Tags

phpphplibphplibraryphptemplatehelperstringlibrarystring manipulationtextchainingsupporttemplate enginetext-processingstring-helperstring supportbinderplaceholder-replacementtext-bindertext-morphervariable-bindingrisma

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/nabeghe-risma/health.svg)

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

###  Alternatives

[jasonlam604/stringizer

Stringizer is a PHP string manipulation library with support for method chaining and multibyte handling

35110.5k1](/packages/jasonlam604-stringizer)[lolli42/finediff

PHP implementation of a Fine granularity Diff engine

139.8M9](/packages/lolli42-finediff)

PHPackages © 2026

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