<commit_before><?php
/**
 * Created by PhpStorm.
 * User: eduardo
 * Date: 08/01/15
 * Time: 17:35
 */

namespace Cacic\MultiBundle\EventListener;

use Cacic\MultiBundle\Connection\ConnectionWrapper;
use Cacic\MultiBundle\Site\SiteManager;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Class CurrentSiteListener
 * Copied from http://knpuniversity.com/screencast/question-answer-day/symfony2-dynamic-subdomains
 *
 * @package Cacic\MultiBundle\EventListener
 */
class CurrentSiteListener {
    private $siteManager;

    private $container;

    //private $em;

    //private $baseHost;

    public function __construct(SiteManager $siteManager, ContainerInterface $container)
    {
        $this->siteManager = $siteManager;
        $this->container = $container;
        //$this->em = $em;
        //$this->baseHost = $baseHost;
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        /*
        $currentHost = $request->getHttpHost();
        $subdomain = str_replace('.'.$this->baseHost, '', $currentHost);


        $site = $this->em
            ->getRepository('QADayBundle:Site')
            ->findOneBy(array('subdomain' => $subdomain))
        ;
        if (!$site) {
            throw new NotFoundHttpException(sprintf(
                'No site for host "%s", subdomain "%s"',
                $this->baseHost,
                $subdomain
            ));
        }


        $this->siteManager->setCurrentSite($subdomain);
        */

        $domain = $request->getBasePath();
        $this->siteManager->setCurrentSite($domain);

        // Load the database for this website
        $dbname = trim($domain, "/");
        $container = $this->container;

        // TODO: allow $dbuser and $dbpass for each website
        $dbuser = $container->getParameter('database_user');
        $dbpass = $container->getParameter('database_password');

        $container->get('doctrine.dbal.dynamic_connection')->forceSwitch($dbname, $dbuser, $dbpass);
    }
<commit_msg>Peque correção que falhava para URL's na raiz<commit_after><?php
/**
 * Created by PhpStorm.
 * User: eduardo
 * Date: 08/01/15
 * Time: 17:35
 */

namespace Cacic\MultiBundle\EventListener;

use Cacic\MultiBundle\Connection\ConnectionWrapper;
use Cacic\MultiBundle\Site\SiteManager;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Class CurrentSiteListener
 * Copied from http://knpuniversity.com/screencast/question-answer-day/symfony2-dynamic-subdomains
 *
 * @package Cacic\MultiBundle\EventListener
 */
class CurrentSiteListener {
    private $siteManager;

    private $container;

    //private $em;

    //private $baseHost;

    public function __construct(SiteManager $siteManager, ContainerInterface $container)
    {
        $this->siteManager = $siteManager;
        $this->container = $container;
        //$this->em = $em;
        //$this->baseHost = $baseHost;
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        /*
        $currentHost = $request->getHttpHost();
        $subdomain = str_replace('.'.$this->baseHost, '', $currentHost);


        $site = $this->em
            ->getRepository('QADayBundle:Site')
            ->findOneBy(array('subdomain' => $subdomain))
        ;
        if (!$site) {
            throw new NotFoundHttpException(sprintf(
                'No site for host "%s", subdomain "%s"',
                $this->baseHost,
                $subdomain
            ));
        }


        $this->siteManager->setCurrentSite($subdomain);
        */

        $domain = $request->getBasePath();
        $this->siteManager->setCurrentSite($domain);

        // Load the database for this website
        $dbname = trim($domain, "/");
        $container = $this->container;

        // Se for nulo, pega o valor que está no parâmetro
        if (empty($dbname)) {
            $dbname = $container->getParameter('database_name');
        }

        // TODO: allow $dbuser and $dbpass for each website
        $dbuser = $container->getParameter('database_user');
        $dbpass = $container->getParameter('database_password');

        $container->get('doctrine.dbal.dynamic_connection')->forceSwitch($dbname, $dbuser, $dbpass);
    }

{'fraction_non_alphanumeric': 0.13409630749298207, 'fraction_numerical': 0.004750593824228029, 'mean_word_length': 2.765853658536585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, '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': '3630841', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1301, 'n_words': 249}