ryancco/canon

Generate files from templates

v0.3 2022-12-21 08:40 UTC

README

Latest Version on Packagist Tests Total Downloads

Generate files from templates in PHP. Useful in development for templating commonly created files or files with extensive boilerplate or formatting. Leverage the full power of your preferred templating language by implementing the Ryancco\Canon\Contracts\Compiler interface. This package includes a dependency-free, "pure PHP" implementation that supports simple variable replacement as well as an implementation for the Blade templating engine and the Twig templating engine. Each require you add the respective compiler engine to your project dependencies.

Write or read files to and from separate filesystems including local, S/FTP, AWS S3 and more by requiring any of the supported Flysystem adapters.

Installation

You can install the package via composer:

composer require [--dev] ryancco/canon

Usage

use Ryancco\Canon;

$canon = new Canon($filesystem);

// using a template file
$canon->generate('hello-world.txt', 'filename.out', ['name' => 'World']);

// using a template string
$canon->generate('Hello, { name }.', 'filename.out', ['name' => 'World']);

Testing

composer test

Changelog

Please see the Release Notes for more information on what has changed recently.

Credits

License

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