PHPackages                             phptransformers/phptransformer - 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. phptransformers/phptransformer

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

phptransformers/phptransformer
==============================

Normalize the API of any PHPTransformer.

1.0.0(10y ago)42201[20 issues](https://github.com/phptransformers/phptransformer/issues)[1 PRs](https://github.com/phptransformers/phptransformer/pulls)10MITPHPPHP &gt;=5.3.0

Since Apr 24Pushed 8y ago2 watchersCompare

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

READMEChangelogDependencies (3)Versions (6)Used By (10)

PHPTransformer
==============

[](#phptransformer)

[![](https://raw.githubusercontent.com/phptransformers/phptransformer/master/logo.png)](http://github.com/phptransformers/phptransformer)[![Latest Version](https://camo.githubusercontent.com/3dd148d0651ac4a7f05774f47646224681c49aa52c97e3d337fad781b07303d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7068707472616e73666f726d6572732f7068707472616e73666f726d65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/phptransformers/phptransformer/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/4750f7247aef9d31d00b933084ad87b40d3e8757adc1856f0cdd771f9fd1cd12/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068707472616e73666f726d6572732f7068707472616e73666f726d65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/phptransformers/phptransformer)[![Coverage Status](https://camo.githubusercontent.com/00648bde3b25a89c87dd9888157e90e31c06625a4cc8060b432a124a744880e3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7068707472616e73666f726d6572732f7068707472616e73666f726d65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/phptransformers/phptransformer/code-structure)[![Quality Score](https://camo.githubusercontent.com/28abb5298703860746a9d27534c9b5167a668a4201f4322b2ed79edc8a40d726/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7068707472616e73666f726d6572732f7068707472616e73666f726d65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/phptransformers/phptransformer)[![Total Downloads](https://camo.githubusercontent.com/91e354e105266f6be39a13227c669ca44765d1f95d58c115013bc8706e6bbb20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068707472616e73666f726d6572732f7068707472616e73666f726d6572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phptransformers/phptransformer)

Common interface to manipulate strings/data with any transformer. Great for use in templating libraries, static site generators, web frameworks, and more. Inspired by [JSTransformers](http://github.com/jstransformers).

Supported Transformers
----------------------

[](#supported-transformers)

To use each of these transformers, you will also need to `composer require` them in your project.

- [Twig](https://github.com/phptransformers/twig) (From SensioLabs/Symfony)
- [Smarty](https://github.com/phptransformers/smarty)
- [Mustache](https://github.com/phptransformers/mustache)
- [Latte](https://github.com/phptransformers/latte) (From Nette Framework)
- [StringTemplate](https://github.com/phptransformers/string-template)
- [Plates](https://github.com/phptransformers/plates) (From The PHP League)
- [Dwoo](https://github.com/phptransformers/dwoo)
- [Blade](https://github.com/phptransformers/blade) (From Laravel Framework)
- [PHPTAL](https://github.com/phptransformers/phptal)
- [Text-Template](https://github.com/phptransformers/text-template) (From PHPUnit)

Install
-------

[](#install)

Via Composer

```
$ composer require phptransformers/phptransformer
```

Usage
-----

[](#usage)

```
// With "phptransfomers/twig" package
$transformer = new PhpTransformers\Twig\TwigTransformer();
echo $transformer->render('Hello, {{ name }}!', array(
	'name' => 'World'
));
//=> Hello, World!
```

API
---

[](#api)

Before all examples, you will need to load a transformer:

```
$transformer = new PhpTransformers\Twig\TwigTransformer();
$transformer = new PhpTransformers\Smarty\SmartyTransformer();
// ... same thing for all other Transformers
```

*See each transformers' repository for more details*

### `->render($template, $locals)`

[](#-rendertemplate-locals)

Renders the given template string, using the provides locals for options passed in. Returns the result as a string.

```
$locals = array('name' => 'World');
$output = $transformer->render('Hello, {{ name }}!', $locals);
```

### `->renderFile($file, $locals)`

[](#-renderfilefile-locals)

Renders the given file, using the provided locals for options passed in. Returns the result as a string.

```
$locals = array('name' => 'World');
$output = $transformer->renderFile('hello.twig', $locals);
```

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Rob Loach](https://github.com/RobLoach)
- [stoeffel](https://github.com/stoeffel)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 61.5% 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 ~307 days

Total

2

Last Release

3735d ago

Major Versions

0.0.1 → 1.0.02016-02-25

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25086?v=4)[Rob Loach](/maintainers/RobLoach)[@RobLoach](https://github.com/RobLoach)

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

---

Top Contributors

[![RobLoach](https://avatars.githubusercontent.com/u/25086?v=4)](https://github.com/RobLoach "RobLoach (8 commits)")[![MacFJA](https://avatars.githubusercontent.com/u/1475671?v=4)](https://github.com/MacFJA "MacFJA (5 commits)")

---

Tags

phptransformer

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phptransformers-phptransformer/health.svg)

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

PHPackages © 2026

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