PHPackages                             webignition/stubble - 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. webignition/stubble

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

webignition/stubble
===================

A minimal library to replace mustache-like variables in strings

1.0(5mo ago)16.7k[1 issues](https://github.com/webignition/stubble/issues)2MITPHPPHP ^8.4

Since Oct 8Pushed 5mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (19)Used By (2)

Stubble
=======

[](#stubble)

A minimal library to replace mustache-like variables in strings, using PHP.

Installing
----------

[](#installing)

`composer require webignition/stubble`

Hello {{ name }}! Example
-------------------------

[](#hello--name--example)

```
use webignition\Stubble\VariableResolver;
use webignition\StubbleResolvable\Resolvable;

// Using a VariableResolver instance
$resolver = new VariableResolver();

$resolvable = new Resolvable(
    'Hello {{ name }}!',
    [
        'name' => 'World',
    ]
);

$resolvedTemplate = $resolver->resolve($resolvable);
echo $resolvedTemplate; // Hello World!
```

Unresolved Variables
--------------------

[](#unresolved-variables)

Variables remaining after resolving a template are considered unresolved variables. An unresolved variable in a template indicates that you are missing one or more values in the context. This is probably not what you want.

A `UnresolvedVariableException` is thrown for the first unresolved variable.

```
use webignition\Stubble\UnresolvedVariableException;
use webignition\Stubble\VariableResolver;
use webignition\StubbleResolvable\Resolvable;

$resolver = new VariableResolver();

$resolvable = new Resolvable(
    'Hello {{ name }} and welcome to {{ location }}.',
    [
        'name' => 'World',
    ]
);

try {
    $resolvedTemplate = $resolver->resolve($resolvable);
} catch (UnresolvedVariableException $exception) {
    // Do something useful ... logging?
    $exception->getVariable(); // 'location'
    $exception->getTemplate(); // 'Hello {{ name }} and welcome to {{ location }}.'
}
```

Selectively Allowing Unresolved Variables
-----------------------------------------

[](#selectively-allowing-unresolved-variables)

### Unresolved Variable Deciders

[](#unresolved-variable-deciders)

You may expect unresolved variables in resolved templates, for example if the content being generated is itself a template for use elsewhere.

Using a `UnresolvedVariableFinder`, a resolver can make use of one or more unresolved variable deciders, with each decider being a callable returning a boolean. The first decider to return true allows an unresolved variable to be present without throwing an exception.

```
use webignition\Stubble\UnresolvedVariableFinder;
use webignition\Stubble\VariableResolver;
use webignition\StubbleResolvable\Resolvable;

$resolver = new VariableResolver(
    new UnresolvedVariableFinder([
        function (string $variable) {
            return 'location' === $variable;
        },
    ])
);

$resolvable = new Resolvable(
    'Hello {{ name }} and welcome to {{ location }}.',
    [
        'name' => 'World',
    ]
);

$resolvedTemplate = $resolver->resolve($resolvable);
echo $resolvedTemplate; // Hello Jon and welcome to {{ location }}.
```

### Use the DeciderFactory to Create Common Deciders

[](#use-the-deciderfactory-to-create-common-deciders)

```
use webignition\Stubble\DeciderFactory;
use webignition\Stubble\VariableResolver;
use webignition\Stubble\UnresolvedVariableFinder;

$resolver = new VariableResolver(
    new UnresolvedVariableFinder([
        // Allow all unresolved variables
        DeciderFactory::createAllowAllDecider(),
        // Disallow all unresolved variables
        DeciderFactory::createDisallowAllDecider(),
        // Allow unresolved variables by pattern (regular expression),
        DeciderFactory::createAllowByPatternDecider('/^variable[0-9]$/')
    ])
);
```

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance52

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

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

Recently: every ~467 days

Total

17

Last Release

158d ago

Major Versions

0.16 → 1.02025-12-11

PHP version history (4 changes)0.1PHP &gt;=7.4

0.14PHP &gt;=7.4|^8

0.15PHP ^8.0|^8.1

1.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/278be37d1b614ef0c40b22b777663e545a1f6d69dd4f908888cbb557ad7e608f?d=identicon)[webignition](/maintainers/webignition)

---

Top Contributors

[![webignition](https://avatars.githubusercontent.com/u/76546?v=4)](https://github.com/webignition "webignition (39 commits)")

---

Tags

stringmustachehandlebarsreplacementreplace

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/webignition-stubble/health.svg)

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.3M129](/packages/webpatser-laravel-uuid)[spatie/string

String handling evolved

5604.6M24](/packages/spatie-string)[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4235.0M21](/packages/kwn-number-to-words)

PHPackages © 2026

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