src/Mandango/Mondator/ClassExtension.php
protected function processTemplate(Definition $definition, $name, array $variables = array())
    {
        $twig = $this->getTwig();

        $variables['extension'] = $this;
        $variables['options'] = $this->options;
        $variables['class'] = $this->class;
        $variables['config_class'] = $this->configClass;
        $variables['config_classes'] = $this->configClasses;

        $result = $twig->loadTemplate($name)->render($variables);

        // properties
        $expression = '/
            (?P<docComment>\ \ \ \ \/\*\*\n[\s\S]*\ \ \ \ \ \*\/)?\n?
             \ \ \ \ (?P<static>static\ )?
            (?P<visibility>public|protected|private)
            \s
            \$
            (?P<name>[a-zA-Z0-9_]+)
            ;
        /xU';
        preg_match_all($expression, $result, $matches);

        for ($i = 0; $i <= count($matches[0]) - 1; $i++) {
            $property = new Property($matches['visibility'][$i], $matches['name'][$i], null);
            if ($matches['static'][$i]) {
                $property->setStatic(true);
            }
            if ($matches['docComment'][$i]) {
                $property->setDocComment($matches['docComment'][$i]);
            }
            $definition->addProperty($property);
        }

        // methods
        $expression = '/
            (?P<docComment>\ \ \ \ \/\*\*\n[\s\S]*\ \ \ \ \ \*\/)?\n
            \ \ \ \ (?P<static>static\ )?
            (?P<visibility>public|protected|private)
            \s
            function
            \s
            (?P<name>[a-zA-Z0-9_]+)
            \((?P<arguments>[$a-zA-Z0-9_\\\=\(\), ]*)\)
            \n
            \ \ \ \ \{
                (?P<code>[\s\S]*)
            \n\ \ \ \ \}
        /xU';
        preg_match_all($expression, $result, $matches);

        for ($i = 0; $i <= count($matches[0]) - 1; $i++) {
            $code = trim($matches['code'][$i], "\n");
            $method = new Method($matches['visibility'][$i], $matches['name'][$i], $matches['arguments'][$i], $code);
            if ($matches['static'][$i]) {
                $method->setStatic(true);
            }
            if ($matches['docComment'][$i]) {
                $method->setDocComment($matches['docComment'][$i]);
            }
            $definition->addMethod($method);
        }
    }
protected function processTemplate(Definition $definition, $name, array $variables = array())
    {
        $twig = $this->getTwig();

        $variables['extension'] = $this;
        $variables['options'] = $this->options;
        $variables['class'] = $this->class;
        $variables['config_class'] = $this->configClass;
        $variables['config_classes'] = $this->configClasses;

        $result = $twig->loadTemplate($name)->render($variables);

        // properties
        $expression = '/
            (?P<docComment>\ \ \ \ \/\*\*\n[\s\S]*\ \ \ \ \ \*\/)?\n?
             \ \ \ \ (?P<static>static\ )?
            (?P<visibility>public|protected|private)
            \s
            \$
            (?P<name>[a-zA-Z0-9_]+)
            ;
        /xU';
        preg_match_all($expression, $result, $matches);

        for ($i = 0; $i <= count($matches[0]) - 1; $i++) {
            $property = new Property($matches['visibility'][$i], $matches['name'][$i], null);
            if ($matches['static'][$i]) {
                $property->setStatic(true);
            }
            if ($matches['docComment'][$i]) {
                $property->setDocComment($matches['docComment'][$i]);
            }
            $definition->addProperty($property);
        }

        // methods
        $expression = '/
            (?P<docComment>\ \ \ \ \/\*\*\n[\s\S]*\ \ \ \ \ \*\/)?\n
            \ \ \ \ (?P<static>static\ )?
            (?P<visibility>public|protected|private)
            \s
            function
            \s
            (?P<name>[a-zA-Z0-9_]+)
            \((?P<arguments>[$a-zA-Z0-9_\\\=\(\), ]*)\)
            \n
            \ \ \ \ \{
                (?P<code>[\s\S]*)
            \n\ \ \ \ \}
        /xU';
        preg_match_all($expression, $result, $matches);

        for ($i = 0; $i <= count($matches[0]) - 1; $i++) {
            $code = trim($matches['code'][$i], "\n");
            $method = new Method($matches['visibility'][$i], $matches['name'][$i], $matches['arguments'][$i], $code);
            if ($matches['static'][$i]) {
                $method->setStatic(true);
            }
            if ($matches['docComment'][$i]) {
                $method->setDocComment($matches['docComment'][$i]);
            }
            $definition->addMethod($method);
        }
    }
Twig.