phptransformers/phptransformer

Normalize the API of any PHPTransformer.

1.0.0 2016-02-25 12:18 UTC

This package is auto-updated.

Last update: 2024-03-16 22:21:36 UTC


README

logo.png Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

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.

Supported Transformers

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

Install

Via Composer

$ composer require phptransformers/phptransformer

Usage

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

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)

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)

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

$ composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.