<commit_before><?php

namespace Ojs\Common\Listener;

use \Ojs\Common\Model\JournalDomain;
use \Doctrine\ORM\EntityManager;
use \Symfony\Component\HttpKernel\Event\GetResponseEvent;

class DomainListener
{

    private $journalDomain;
    private $em;
    private $baseHost;

    public function __construct(JournalDomain $journalDomain, EntityManager $em, $baseHost)
    {
        $this->journalDomain = $journalDomain;
        $this->em = $em;
        $this->baseHost = $baseHost;
    }

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

        $currentHost = $request->getHttpHost();
        $subdomain = str_replace('.' . $this->baseHost, '', $currentHost);
        if ($this->baseHost === $subdomain) {
            // no journal selected. this url may refer a management page under baseurl.
        } else {
            // search o for subdomains or domains 
            $qb = $this->em->getRepository('OjsJournalBundle:Journal')->createQueryBuilder('do');
            $qb->select('do')->where($qb->expr()->orX(
                            $qb->expr()->eq('do.subdomain', ':domain'), $qb->expr()->eq('do.domain', ':domain')
            ))->setParameter('domain', $subdomain);
            $journal = $qb->getQuery()->getSingleResult();
            /**
             * @todo show human friendly error page if there is no journal for this subdomain or domain
             */
            if ($journal) {
                $this->journalDomain->setCurrentJournal($journal);
            }
        }
    }

}<commit_msg>GetSingleResult throw DoctrineNoResultException if can not find a record. This is also cause to testings fails.<commit_after><?php

namespace Ojs\Common\Listener;

use \Ojs\Common\Model\JournalDomain;
use \Doctrine\ORM\EntityManager;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use \Symfony\Component\HttpKernel\Event\GetResponseEvent;

class DomainListener
{

    private $journalDomain;
    private $em;
    private $baseHost;

    public function __construct(JournalDomain $journalDomain, EntityManager $em, $baseHost)
    {
        $this->journalDomain = $journalDomain;
        $this->em = $em;
        $this->baseHost = $baseHost;
    }

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

        $currentHost = $request->getHttpHost();
        $subdomain = str_replace('.' . $this->baseHost, '', $currentHost);
        if ($this->baseHost === $subdomain) {
            // no journal selected. this url may refer a management page under baseurl.
        } else {
            // search o for subdomains or domains 
            $qb = $this->em->getRepository('OjsJournalBundle:Journal')->createQueryBuilder('do');
            $qb->select('do')->where($qb->expr()->orX(
                            $qb->expr()->eq('do.subdomain', ':domain'), $qb->expr()->eq('do.domain', ':domain')
            ))->setParameter('domain', $subdomain);
            $journal = $qb->getQuery()->getOneOrNullResult();
            /**
             * @todo show human friendly error page if there is no journal for this subdomain or domain
             */
            if ($journal) {
                $this->journalDomain->setCurrentJournal($journal);
            }
        }
    }

}
{'fraction_non_alphanumeric': 0.14035617265318442, 'fraction_numerical': 0.0, 'mean_word_length': 2.4737945492662474, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '6877128', 'n_tokens_mistral': 926, 'n_tokens_neox': 906, 'n_words': 205}