zendframework / zend-expressive-twigrenderer

Twig integration for Expressive
BSD 3-Clause "New" or "Revised" License
25 stars 14 forks source link

Allow overriding optimizations and autoescape options via configuration #46

Closed edigu closed 6 years ago

edigu commented 6 years ago

Twig Environment provides following additional options for developers:

TwigEnvironmentFactory currently creating a new Environment instance using a limited list of options and Environment has no interface to set these options later but the construction.

This PR provides a compatible way for disabling optimizations and auto-escaping (which enabled by default) using configration:

$config = [
    'twig' = [
          'timezone'       => 'UTC',
          'cache_dir'      => 'data/cache/twig',
          // ... after all others
          'autoescape'     => false, // 'html' by default
          'optimizations'  => 0, // -1 by default
    ],
];

I have also wrote two test cases for these new options and considered using same values as Twig defaults in factory.

Only detail that bugging me is if Twig decides to change these defaults in a future release, TwigEnvironmentFactory would also need to be adjusted to reflect this changes.

edigu commented 6 years ago

I have documented them in both README.md and src/TwigEnvironmentFactory.php

weierophinney commented 6 years ago

Thanks, @edigu!