PHPackages                             intaro/twig-sandbox-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. intaro/twig-sandbox-bundle

ActiveSymfony-bundle[Templating &amp; Views](/categories/templating)

intaro/twig-sandbox-bundle
==========================

Annotation configuration of the allowed methods and properties for Twig\_Sandbox extension

v3.4.0(8mo ago)7720.7k↑14.2%7MITPHPPHP ^8.1

Since Jun 23Pushed 8mo ago5 watchersCompare

[ Source](https://github.com/intaro/twig-sandbox-bundle)[ Packagist](https://packagist.org/packages/intaro/twig-sandbox-bundle)[ RSS](/packages/intaro-twig-sandbox-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (27)Versions (23)Used By (0)

TwigSandboxBundle
=================

[](#twigsandboxbundle)

[![CI](https://github.com/intaro/twig-sandbox-bundle/workflows/CI/badge.svg?branch=master)](https://github.com/intaro/twig-sandbox-bundle/workflows/CI/badge.svg?branch=master)

There is [Twig](https://twig.symfony.com)-extension [Sandbox](https://twig.symfony.com/doc/2.x/api.html#sandbox-extension) which can be used to evaluate untrusted code and where access to unsafe properties and methods is prohibited. This bundle allows to configure security policy for sandbox.

Installation
------------

[](#installation)

TwigSandboxBundle requires Symfony 6.0 or higher.

Install the bundle:

```
$ composer require intaro/twig-sandbox-bundle

```

Register the bundle in `config/bundles.php`:

```
return [
    // ...
    Intaro\TwigSandboxBundle\IntaroTwigSandboxBundle::class => ['all' => true],
];
```

Usage
-----

[](#usage)

Define allowed properties and methods for your entities using attribute `#[Sandbox]`. Optionally you can add `type` option for attribute (for example `#[Sandbox(type: 'int')]`). This option defines type of value that property stores or method returns.

In your application you can use annotation reader to extract value of `type` option and use this value to perform additional checks or any other actions, for example, use twig filters according to value of the option.

```
