<?php 

namespace NPS\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use NPS\DependencyInjection\IExpertSystemBridge;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use NPS\Controller\ConsultationController;
use NPS\Controller\KnowledgeController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

/**
 * Language subscriber sets language of expert
 */
class LanguageSubscriber implements EventSubscriberInterface
{

    /**
     * @inherit 
     */
    public static function getSubscribedEvents()
    {
        return [
            'kernel.request' => 'onKernelRequest'
        ];
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        
        if($locale = $request->get('lang'))
        {
            $request->setLocale($locale);
        }
    }

}

