<commit_before><?php

namespace Webfactory\Util;

use Symfony\Component\HttpKernel\KernelInterface;

/**
 * Iterator that iterates over the file paths of all Twig templates that belong
 * to the application (application *and* vendor bundles).
 */
class TwigTemplateIterator
{
    /**
     * Reads templates from the application with the given kernel.
     *
     * @param KernelInterface $kernel
     */
    public function __construct(KernelInterface $kernel)
    {

    }
}<commit_msg>implemented template iterator (#11)<commit_after><?php

namespace Webfactory\Util;

use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\KernelInterface;

/**
 * Iterator that iterates over the file paths of all Twig templates that belong
 * to the application (application *and* vendor bundles).
 */
class TwigTemplateIterator implements \IteratorAggregate
{
    /**
     * The kernel whose templates are returned.
     *
     * @var KernelInterface
     */
    protected $kernel = null;

    /**
     * Reads templates from the application with the given kernel.
     *
     * @param KernelInterface $kernel
     */
    public function __construct(KernelInterface $kernel)
    {
        $this->kernel = $kernel;
    }

    /**
     * Returns an iterator that provides Twig template paths.
     *
     * @return \Traversable
     */
    public function getIterator()
    {
        $this->kernel->boot();
        $viewDirectories = array();
        $globalResourceDirectory = $this->kernel->getRootDir() . '/Resources';
        if (is_dir($globalResourceDirectory)) {
            $viewDirectories[] = $globalResourceDirectory;
        }
        foreach ($this->kernel->getBundles() as $bundle) {
            /* @var $bundle BundleInterface */
            $viewDirectory = $bundle->getPath() . '/Resources/views';
            if (is_dir($viewDirectory)) {
                $viewDirectories[] = $viewDirectory;
            }
        }
        if (count($viewDirectories) === 0) {
            return new \ArrayIterator();
        }
        $templates = Finder::create()->in($viewDirectories)->files()->name('*.*.twig');
        $templates = iterator_to_array($templates, false);
        $templates = array_map(function (SplFileInfo $file) {
            return $file->getRealPath();
        }, $templates);
        return new \ArrayIterator($templates);
    }


}
{'fraction_non_alphanumeric': 0.11661926046322633, 'fraction_numerical': 0.001219016659894352, 'mean_word_length': 2.7078313253012047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6950705', 'n_tokens_mistral': 664, 'n_tokens_neox': 654, 'n_words': 168}