<commit_before><?php

namespace ZfcTwig\Service;

use InvalidArgumentException;
use ZfcTwig\Twig\Loader\Filesystem;
use ZfcTwig\Twig\Environment;
use ZfcTwig\Twig\Extension;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class EnvironmentFactory implements FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('Configuration');
        $config = $config['zfctwig'];
        $manager = $serviceLocator->get('ViewHelperManager');

        $loader = new Filesystem(array());
        $resolver = $serviceLocator->get('ViewResolver');
        $loader->setFallbackResolver($resolver);
        
        foreach ($config['namespaces'] as $namespace => $path) {
            $loader->addPath($path, $namespace);
        }

        $twig = new Environment($loader, $config['config']);
        $twig->addExtension(new Extension($twig, $serviceLocator));
        $twig->setManager($manager);

        foreach($config['extensions'] as $ext) {
            if (!is_string($ext)) {
                throw new InvalidArgumentException('Extension name must be a string');
            }
            $twig->addExtension(new $ext);
        }


        return $twig;
    }
}<commit_msg>Fixed bug when using view helpers with 2 view strategies<commit_after><?php

namespace ZfcTwig\Service;

use InvalidArgumentException;
use ZfcTwig\Twig\Loader\Filesystem;
use ZfcTwig\Twig\Environment;
use ZfcTwig\Twig\Extension;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class EnvironmentFactory implements FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('Configuration');
        $config = $config['zfctwig'];
        $manager = clone $serviceLocator->get('ViewHelperManager');

        $loader = new Filesystem(array());
        $resolver = $serviceLocator->get('ViewResolver');
        $loader->setFallbackResolver($resolver);
        
        foreach ($config['namespaces'] as $namespace => $path) {
            $loader->addPath($path, $namespace);
        }

        $twig = new Environment($loader, $config['config']);
        $twig->addExtension(new Extension($twig, $serviceLocator));
        $twig->setManager($manager);

        foreach($config['extensions'] as $ext) {
            if (!is_string($ext)) {
                throw new InvalidArgumentException('Extension name must be a string');
            }
            $twig->addExtension(new $ext);
        }


        return $twig;
    }
}
{'fraction_non_alphanumeric': 0.1267552182163188, 'fraction_numerical': 0.0003795066413662239, 'mean_word_length': 3.20414673046252, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '7475883', 'n_tokens_mistral': 731, 'n_tokens_neox': 710, 'n_words': 144}