<commit_before><?php

namespace PS\Bundle\XsltBundle;

use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\Loader\LoaderInterface;
use Symfony\Component\Templating\Storage\FileStorage;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class XsltEngine implements EngineInterface
{

    protected $parser;
    protected $loader;
    protected $globals;
    
    /**
     * Constructor.
     *
     * @param TemplateNameParserInterface $parser    A TemplateNameParserInterface instance
     * @param LoaderInterface             $loader    A LoaderInterface instance
     * @param GlobalVariables|null        $globals   A GlobalVariables instance or null
     */
    public function __construct(TemplateNameParserInterface $parser,
        LoaderInterface $loader,
        GlobalVariables $globals = null)
    {
        $this->parser = $parser;
        $this->loader = $loader;
        $this->globals = $globals;
    }
 
    /**
     * Renders a template.
     *
     * @param mixed $name       A template name or a TemplateReferenceInterface instance
     * @param array $parameters An array of parameters to pass to the template
     *
     * @return string The evaluated template as a string
     *
     * @throws \RuntimeException if the template cannot be rendered
     *
     * @api
     */
    public function render($name, array $parameters = array())
    {
        $template = $this->parse($name);
        $xsltDom = $this->load($template);
        var_dump($xsltDom->saveXML());
        die;
    }

    /**
     * Returns true if the template exists.
     *
     * @param mixed $name A template name or a TemplateReferenceInterface instance
     *
     * @return Boolean true if the template exists, false otherwise
     *
     * @api
     */
    public function exists($name)
    {
        d();
    }

    /**
     * Returns true if this class is able to render the given template.
     *
     * @param mixed $name A template name or a TemplateReferenceInterface instance
     *
     * @return Boolean true if this class supports the given template, false otherwise
     */
    public function supports($name)
    {
        return $this->parser->parse($name)->get('engine') === 'xsl';
    }

    /**
     * Renders a view and returns a Response.
     *
     * @param string   $view       The view name
     * @param array    $parameters An array of parameters to pass to the view
     * @param Response $response   A Response instance
     *
     * @return Response A Response instance
     */
    public function renderResponse($view, array $parameters = array(), Response $response = null)
    {
        if (null === $response) {
            $response = new Response();
        }

        $response->setContent($this->render($view, $parameters));

        return $response;
    }

    /**
     * Parses the given template.
     *
     * @param string $name A template name
     *
     * @return mixed The resource handle of the template file or template object
     *
     * @throws \InvalidArgumentException if the template cannot be found
     */
    public function parse($name)
    {
        return $this->parser->parse($name);
    }

    /**
     * Loads the given template.
     *
     * @param TemplateReferenceInterface $name The template to be loaded
     *
     * @return DomDocument The DOM Document representing the template
     *
     * @throws \InvalidArgumentException if the template cannot be found
     */
    public function load($template)
    {

        $storage = $this->loader->load($template);

        if (false === $storage) {
            throw new \InvalidArgumentException(sprintf('The template "%s" does not exist.', $template->getLogicalName()));
        }

        $xsltDom = new \DomDocument();

        if ($storage instanceof FileStorage) {
            $xsltDom->load((string) $storage);
        } else {
            $xsltDom->loadXML($storage);
        }

        return $xsltDom;
    }
}
<commit_msg>use own parse method<commit_after><?php

namespace PS\Bundle\XsltBundle;

use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\Loader\LoaderInterface;
use Symfony\Component\Templating\Storage\FileStorage;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class XsltEngine implements EngineInterface
{

    protected $parser;
    protected $loader;
    protected $globals;
    
    /**
     * Constructor.
     *
     * @param TemplateNameParserInterface $parser    A TemplateNameParserInterface instance
     * @param LoaderInterface             $loader    A LoaderInterface instance
     * @param GlobalVariables|null        $globals   A GlobalVariables instance or null
     */
    public function __construct(TemplateNameParserInterface $parser,
        LoaderInterface $loader,
        GlobalVariables $globals = null)
    {
        $this->parser = $parser;
        $this->loader = $loader;
        $this->globals = $globals;
    }
 
    /**
     * Renders a template.
     *
     * @param mixed $name       A template name or a TemplateReferenceInterface instance
     * @param array $parameters An array of parameters to pass to the template
     *
     * @return string The evaluated template as a string
     *
     * @throws \RuntimeException if the template cannot be rendered
     *
     * @api
     */
    public function render($name, array $parameters = array())
    {
        $template = $this->parse($name);
        $xsltDom = $this->load($template);
        var_dump($xsltDom->saveXML());
        die;
    }

    /**
     * Returns true if the template exists.
     *
     * @param mixed $name A template name or a TemplateReferenceInterface instance
     *
     * @return Boolean true if the template exists, false otherwise
     *
     * @api
     */
    public function exists($name)
    {
        d();
    }

    /**
     * Returns true if this class is able to render the given template.
     *
     * @param mixed $name A template name or a TemplateReferenceInterface instance
     *
     * @return Boolean true if this class supports the given template, false otherwise
     */
    public function supports($name)
    {
        return $this->parse($name)->get('engine') === 'xsl';
    }

    /**
     * Renders a view and returns a Response.
     *
     * @param string   $view       The view name
     * @param array    $parameters An array of parameters to pass to the view
     * @param Response $response   A Response instance
     *
     * @return Response A Response instance
     */
    public function renderResponse($view, array $parameters = array(), Response $response = null)
    {
        if (null === $response) {
            $response = new Response();
        }

        $response->setContent($this->render($view, $parameters));

        return $response;
    }

    /**
     * Parses the given template.
     *
     * @param string $name A template name
     *
     * @return mixed The resource handle of the template file or template object
     *
     * @throws \InvalidArgumentException if the template cannot be found
     */
    public function parse($name)
    {
        return $this->parser->parse($name);
    }

    /**
     * Loads the given template.
     *
     * @param TemplateReferenceInterface $name The template to be loaded
     *
     * @return DomDocument The DOM Document representing the template
     *
     * @throws \InvalidArgumentException if the template cannot be found
     */
    public function load($template)
    {

        $storage = $this->loader->load($template);

        if (false === $storage) {
            throw new \InvalidArgumentException(sprintf('The template "%s" does not exist.', $template->getLogicalName()));
        }

        $xsltDom = new \DomDocument();

        if ($storage instanceof FileStorage) {
            $xsltDom->load((string) $storage);
        } else {
            $xsltDom->loadXML($storage);
        }

        return $xsltDom;
    }
}

{'fraction_non_alphanumeric': 0.0964697658161482, 'fraction_numerical': 0.0, 'mean_word_length': 2.4936914936914936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5153400', 'n_tokens_mistral': 2258, 'n_tokens_neox': 2209, 'n_words': 687}