How to register a Twig Extension in services.yaml?
<p>I use twig with Symfony2, and my project structure is:</p>

<pre><code>/myprojectroot
    /app
        /config
            services.yml
        bootstrap.php
    /src
        /Foo
            /Bar
                /Util
                    myextension.php
</code></pre>

<p>I'm following <a href="http://symfony.com/doc/current/cookbook/templating/twig_extension.html" rel="nofollow">this documentation</a> to create my extension, but I find that it's lacking details about namespaces, paths and the registration. I also went through the <a href="http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension" rel="nofollow">detailed doc</a> but it didn't help much.</p>

<pre><code>services:
    app.twig_extension:  &lt;---What is this line? Just a name? 
        class: AppBundle\Twig\AppExtension
        public: false
        tags:
            - { name: twig.extension } &lt;--- Should I ever change that?
</code></pre>

<p>My extension is defined as:</p>

<p><strong>edit: I corrected my getFunctions() according to Jason Roman's answer, but the error persist.</strong></p>

<pre><code>namespace Foo\Bar\Util;        

class QrCodeHandler extends \Twig_Extension
{
    public function getFunctions()
    {
        return array(
                new \Twig_SimpleFunction('genqr', 'generateQRcode'),
        );
    }

    public function generateQRcode($data)
    {
        //snip code...
    }

    public function getName()
    {
        return 'qr_extension';
    }
}
</code></pre>

<p>and my services.yaml:</p>

<pre><code>services:
  qr_extension:
        class: Foo\Bar\Util\QrCodeHandler
        public: false
        tags:
            - { name: twig.extension }
</code></pre>

<p>services.yml is loaded by bootstrap.php with this code:</p>

<pre><code>$services = $parser-&gt;parse(__DIR__ . '/config/services.yml');

if (isset($services['services']))
{
    foreach ( $services['services'] as $name =&gt; $class )
    {
        $app['service.' . $name] = $app-&gt;share(function (Application $app) use($class) {
            $service = new $class($app);
            if (!$service instanceof ServiceInterface)
            {
                $errorMessage = get_class($service) . ' must implement ServiceInterface.';
                $app['monolog']-&gt;addError($errorMessage);
                throw new \Exception($errorMessage);
            }

            return $service;
        });
    }
}
</code></pre>

<p>Of course I'm asking because I'm getting an error </p>

<blockquote>
  <p>Twig_Error_Syntax: The function "genqr" does not exist</p>
</blockquote>

<p>so I wonder what's wrong. I suppose the problem is how I register it. </p>

<p><strong>Can someone explain me what are the various part of the registration code and what should I use for it to work?</strong> </p>