<commit_before><?php

namespace Victoire\Bundle\I18nBundle\Route;

use Gedmo\Sluggable\Util\Urlizer;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Victoire\Bundle\CoreBundle\Route\RouteLoader as BaseRouteLoader;
use Victoire\Bundle\I18nBundle\Resolver\LocaleResolver;

/**
 * The I18nRouteLoader overwrite Victoire default RouteLoader to.
 */
class I18nRouteLoader extends BaseRouteLoader
{
    protected $localeResolver;
    protected $urlizer;

    public function __construct($widgets, LocaleResolver $localeResolver)
    {
        parent::__construct($widgets);
        $this->localeResolver = $localeResolver;
        $this->urlizer = new Urlizer();
    }

    /**
     * {@inheritdoc}
     */
    public function load($resource, $type = null)
    {
        $collection = new RouteCollection();
        foreach ($this->localeResolver->getDomainConfig() as $_domain => $_locale) {
            $_collection = parent::load($resource, $type);
            foreach ($_collection->all() as $_name => $_route) {
                $_route->addDefaults(
                    [
                        '_locale' => $_locale,
                    ]
                );
                $_route->setHost($_domain);
                $collection->add($_locale.'__'.$this->urlizer->urlize($_domain, '_').'__'.$_name, $_route);
            }
        }

        /*
         * Add default(fallback) route for default locale/domain
         * needs to be after the loop
         * */
        $defaultCollection = parent::load($resource, $type);
        $defaultCollection->addDefaults(['_locale' => $this->localeResolver->defaultLocale]);
        if ($this->localeResolver->localePattern == LocaleResolver::PATTERN_DOMAIN) {
            $domainRegex = addslashes(implode('|', array_keys($this->localeResolver->getDomainConfig())));
            $defaultCollection->setHost(
                '{domain}',
                ['domain' => $this->localeResolver->defaultDomain],
                ['domain' => $domainRegex ? $domainRegex : '[^\.]++']
            );
        }
        $collection->addCollection($defaultCollection);

        if ($this->localeResolver->localePattern == LocaleResolver::PATTERN_PARAMETER) {
            $collection = parent::load($resource, $type);
            //Prefix every victoire route with the locale
            $collection->addPrefix('/{_locale}');
            $collection->addCollection($collection);
            //Add a redirection to the default locale homepage when empty url '/'
            $this->addHomepageRedirection($collection);
        }

        return $collection;
    }

    /**
     * Add a homepage redirection route to the collection.<commit_msg>remove requirement on pattern_domain same as pattern_parameter<commit_after><?php

namespace Victoire\Bundle\I18nBundle\Route;

use Gedmo\Sluggable\Util\Urlizer;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Victoire\Bundle\CoreBundle\Route\RouteLoader as BaseRouteLoader;
use Victoire\Bundle\I18nBundle\Resolver\LocaleResolver;

/**
 * The I18nRouteLoader overwrite Victoire default RouteLoader to.
 */
class I18nRouteLoader extends BaseRouteLoader
{
    protected $localeResolver;
    protected $urlizer;

    public function __construct($widgets, LocaleResolver $localeResolver)
    {
        parent::__construct($widgets);
        $this->localeResolver = $localeResolver;
        $this->urlizer = new Urlizer();
    }

    /**
     * {@inheritdoc}
     */
    public function load($resource, $type = null)
    {
        $collection = new RouteCollection();
        foreach ($this->localeResolver->getDomainConfig() as $_domain => $_locale) {
            $_collection = parent::load($resource, $type);
            foreach ($_collection->all() as $_name => $_route) {
                $_route->addDefaults(
                    [
                        '_locale' => $_locale,
                    ]
                );
                $_route->setHost($_domain);
                $collection->add($_locale.'__'.$this->urlizer->urlize($_domain, '_').'__'.$_name, $_route);
            }
        }

        /*
         * Add default(fallback) route for default locale/domain
         * needs to be after the loop
         * */
        $defaultCollection = parent::load($resource, $type);
        $defaultCollection->addDefaults(['_locale' => $this->localeResolver->defaultLocale]);
        if ($this->localeResolver->localePattern == LocaleResolver::PATTERN_DOMAIN) {
            $defaultCollection->setHost(
                '{domain}',
                ['domain' => $this->localeResolver->defaultDomain]
            );
        }
        $collection->addCollection($defaultCollection);

        if ($this->localeResolver->localePattern == LocaleResolver::PATTERN_PARAMETER) {
            $collection = parent::load($resource, $type);
            //Prefix every victoire route with the locale
            $collection->addPrefix('/{_locale}');
            $collection->addCollection($collection);
            //Add a redirection to the default locale homepage when empty url '/'
            $this->addHomepageRedirection($collection);
        }

        return $collection;
    }

    /**
     * Add a homepage redirection route to the collection.
{'fraction_non_alphanumeric': 0.12847156621953523, 'fraction_numerical': 0.0030228603816361234, 'mean_word_length': 2.4376623376623376, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 64, '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': '2482856', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1337, 'n_words': 275}