PHPackages                             khanhicetea/twigeval - 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. khanhicetea/twigeval

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

khanhicetea/twigeval
====================

Evaluate expression using Twig

1.4.1(5y ago)03.1k↓50%MITPHPPHP &gt;=7.2.5CI failing

Since Jun 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/khanhicetea/twigeval)[ Packagist](https://packagist.org/packages/khanhicetea/twigeval)[ RSS](/packages/khanhicetea-twigeval/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

Twigeval
========

[](#twigeval)

[![Latest Stable Version](https://camo.githubusercontent.com/907b7e615d5dc68e46b09784a754c2a13a90d0cd814fa8043a20eeabf0dc0a1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616e686963657465612f747769676576616c2e737667)](https://packagist.org/packages/khanhicetea/twigeval)[![Minimum PHP Version](https://camo.githubusercontent.com/5c3072425e67297c8ef63d17acd2c86a0d2ef324f19249f2280bd7de902f63a2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e302d3838393242462e737667)](https://php.net/)[![Build Status](https://camo.githubusercontent.com/211c432d30453218163bdfa8c205f7526b80f8d336d63e3fd6152159d334e7c3/68747470733a2f2f6170692e7472617669732d63692e6f72672f6b68616e686963657465612f747769676576616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/khanhicetea/twigeval)[![GitHub license](https://camo.githubusercontent.com/ed5dc5960e1443a77ed01062716e9b8216405395ec105495e66bea52792aa710/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b68616e686963657465612f747769676576616c2e737667)](https://github.com/khanhicetea/twigeval/blob/master/LICENSE)

**SAFE** processing expression of variables from string without using `eval` (seems to be **evil**).

Core
----

[](#core)

Using **twig** template engine to produce the result, so you can use any twig syntax and its filters.

Usage
-----

[](#usage)

```
$ composer require khanhicetea/twigeval
```

```
/*
$cacheDir could be :
    - false : no use cache (mean use eval function), be carefully !
    - null : use sys_get_temp_dir() to get system temp directory as cache dir
    - string : cache directory path
*/
$cacheDir = null;
$calculator = new KhanhIceTea\Twigeval\Calculator($cacheDir);
$math = $calculator->number('a / 4 + b * 3', ['a' => 16, 'b' => 3]); // => 13
$boolean1 = $calculator->isTrue('(a and b) or c', ['a' => false, 'b' => true, 'c' => false]); // => false
$boolean2 = $calculator->isFalse('(a and b) or c', ['a' => false, 'b' => true, 'c' => false]); // => true
$string = $calculator->calculate('{{ a|reverse }} world !', ['a' => 'hello']); // => olleh world !
```

LICENSE
-------

[](#license)

The MIT License (MIT) Copyright (c) 2018 KhanhIceTea

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.2% 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 ~123 days

Recently: every ~184 days

Total

7

Last Release

2164d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.0.0

1.4.0PHP &gt;=7.2.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/7813bb37bdbd56acf5eb3e1fdcbe1f31c34fcb16134a1538ee7d7b6b9d2825af?d=identicon)[khanhicetea](/maintainers/khanhicetea)

---

Top Contributors

[![khanhicetea](https://avatars.githubusercontent.com/u/4528223?v=4)](https://github.com/khanhicetea "khanhicetea (15 commits)")[![haiquang9994](https://avatars.githubusercontent.com/u/13959257?v=4)](https://github.com/haiquang9994 "haiquang9994 (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/khanhicetea-twigeval/health.svg)

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91492.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36763.2M221](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

22046.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

22918.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21914.8M162](/packages/symfony-ux-twig-component)

PHPackages © 2026

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