public function TwigSandboxPolicy::__construct
public TwigSandboxPolicy::__construct()
Constructs a new TwigSandboxPolicy object.
File
- core/lib/Drupal/Core/Template/TwigSandboxPolicy.php, line 37
Class
- TwigSandboxPolicy
- Default sandbox policy for Twig templates.
Namespace
Drupal\Core\TemplateCode
public function __construct() { // Allow settings.php to override our default whitelisted classes, methods, // and prefixes. $whitelisted_classes = Settings::get('twig_sandbox_whitelisted_classes', [ // Allow any operations on the Attribute object as it is intended to be // changed from a Twig template, for example calling addClass(). 'Drupal\Core\Template\Attribute', ]); // Flip the arrays so we can check using isset(). $this->whitelisted_classes = array_flip($whitelisted_classes); $whitelisted_methods = Settings::get('twig_sandbox_whitelisted_methods', [ // Only allow idempotent methods. 'id', 'label', 'bundle', 'get', '__toString', 'toString', ]); $this->whitelisted_methods = array_flip($whitelisted_methods); $this->whitelisted_prefixes = Settings::get('twig_sandbox_whitelisted_prefixes', [ 'get', 'has', 'is', ]); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Template!TwigSandboxPolicy.php/function/TwigSandboxPolicy::__construct/8.1.x