phptransformers / phptransformer
Normalize the API of any PHPTransformer.
Installs: 178
Dependents: 11
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 1
Open Issues: 21
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.6
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is auto-updated.
Last update: 2024-10-16 23:28:53 UTC
README
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.
- Twig (From SensioLabs/Symfony)
- Smarty
- Mustache
- Latte (From Nette Framework)
- StringTemplate
- Plates (From The PHP League)
- Dwoo
- Blade (From Laravel Framework)
- PHPTAL
- Text-Template (From PHPUnit)
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.