<p dir="auto">This is about how to properly integrate twig sandbox with the twig-bundles configuration.</p>
<p dir="auto">The major problem with this is, that there is very limited documentation available about the sandbox itself and none regarding the integration with symfony. I think the sandbox is a very nice feature and should get some more love (at least an article in the symfony docs).</p>
<p dir="auto">When i was evaluating the sandbox extension and how to integrate it, there are a few questions that came up, that would be best answered by the "designers intent":</p>
<ul dir="auto">
<li>Should there be a new twig env for each sandbox "profile"?<br>
-&gt; If yes, how to duplicate the default twig environment with all its integrated features (profiler, loaders, forms etc) without too much pain?<br>
-&gt; If no, how to enable different sandbox "profiles"? Could this be a feature request against twig itself?</li>
<li>A way to setup the policy (or multiple policies) by configuration (similar to <a href="https://github.com/intaro/twig-sandbox-bundle">https://github.com/intaro/twig-sandbox-bundle</a> which is a good start, but isnt up to date and has its design flaws)</li>
<li>If using the sandbox, the feature to be implemented is dealing with user supplied templates most of the time. There is a twig lint command and an article in the twig docs on how to validate the twig syntax. there are also some blog entries on how to create a validator for this. imho this should be included in the twig bundle just as the lint command is.</li>
</ul>
<p dir="auto">It's only possible to have one route with a given name, but it is possible for duplicate route names to go undetected because Symfony will silently ignore the issue. I believe the second one found will overwrite the first, although I guess the loading order is non-deterministic (or determined by factors that can easily change).</p>
<p dir="auto">Given two bundles both trying to define a login route:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    # src/AppBundle/Resources/config/routing.yml
    login:
        path:      /login
        defaults:  { _controller: AppBundle:Login:index }"><pre class="notranslate"><code class="notranslate">    # src/AppBundle/Resources/config/routing.yml
    login:
        path:      /login
        defaults:  { _controller: AppBundle:Login:index }
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    # src/AdminBundle/Resources/config/routing.yml
    login:
        path:      /admin/login
        defaults:  { _controller: AdminBundle:Login:index }"><pre class="notranslate"><code class="notranslate">    # src/AdminBundle/Resources/config/routing.yml
    login:
        path:      /admin/login
        defaults:  { _controller: AdminBundle:Login:index }
</code></pre></div>
<p dir="auto">Only one of these routes will exist. This might be an extreme example, because usually the changed behaviour is noticeable. But for applications with many bundles or locale-specific routes, or where it's a simple content page instead of login, then it can be missed.</p>
<p dir="auto">Usually Symfony is quite strict about configuration problems, helping to ensure they're spotted straight away. Is there a reason for the current behaviour, or can the router throw an exception when trying to overwrite a route?</p>