<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Request | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/request/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Thu, 13 Oct 2011 16:14:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Symfony 2 &#8211; Set Default Locale On Form Login #2</title>
		<link>https://nerdpress.org/2011/10/13/symfony-2-set-default-locale-on-form-login-2/</link>
					<comments>https://nerdpress.org/2011/10/13/symfony-2-set-default-locale-on-form-login-2/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 13 Oct 2011 16:14:05 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Locale]]></category>
		<category><![CDATA[Request]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Session]]></category>
		<category><![CDATA[symfony 2]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1891</guid>

					<description><![CDATA[<p>A small update/correction out of sequence: A few weeks ago i described how to hook into the form login process in order to change the user session´s locale. In the meantime a non backwards compatible code modification has been introduced that outdated this article. From now on (Symfony 2.0.4) the locale and default locale settings &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2011/10/13/symfony-2-set-default-locale-on-form-login-2/" class="more-link">Continue reading<span class="screen-reader-text"> "Symfony 2 &#8211; Set Default Locale On Form Login #2"</span></a></p>
The post <a href="https://nerdpress.org/2011/10/13/symfony-2-set-default-locale-on-form-login-2/">Symfony 2 – Set Default Locale On Form Login #2</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>A small update/correction out of sequence:</p>
<p><a href="https://nerdpress.org/2011/08/14/symfony-2-security-bundle-set-user-locale-on-form-login/">A few weeks ago i described how to hook into the form login process in order to change the user session´s locale.</a></p>
<p>In the meantime a non backwards compatible code modification has been <a href="http://symfony.com/blog/a-week-of-symfony-249-3-9-october-2011">introduced</a> that outdated this article. From now on (Symfony 2.0.4) the locale and default locale settings are maintained within the request object (and not as used to be in the session).</p>
<p>So, here is a little update &#8211; under reserve &#8211; because the locale setting´s logic will probably <a href="https://github.com/symfony/symfony/commit/74bc699b270122b70b1de6ece47c726f5df8bd41">change again in the future</a>.</p>
<p><span id="more-1891"></span></p>
<p>At first, the new locale maintenance code by using a LocaleListener is <a href="https://github.com/symfony/symfony/issues/search?q=locale">still buggy</a>. Specially this issue breaks the whole thing atm: https://github.com/symfony/symfony/issues/2386</p>
<p>A quick workaround is to change the priority of the listener from 255 to let´s say 127. That forces the SessionListener to initialize the session right BEFORE the locale listener, so that $request->hasPreviousSession() has actually the chance to return TRUE.</p>
<p>Change Symfony\Component\HttpKernel\EventListener\LocaleListener, L. 69</p>
<pre class="brush: php; title: ; notranslate">
KernelEvents::REQUEST =&gt; array(array('onEarlyKernelRequest', 255), array('onKernelRequest', -1)),
</pre>
<p>to</p>
<pre class="brush: php; title: ; notranslate">
KernelEvents::REQUEST =&gt; array(array('onEarlyKernelRequest', 127), array('onKernelRequest', -1)),
</pre>
<p>Hopefully a patch will be available soon to fix the problem &#8211; source code modifications in this way are things YOU MUST NOT DO!</p>
<p>For now and demonstration purposes only, this will fit. After that, it´s easy to modify our <a href="https://nerdpress.org/2011/08/14/symfony-2-security-bundle-set-user-locale-on-form-login/">previously elaborated source code</a> to fit the new circumstances:</p>
<p>Change our listener from:</p>
<pre class="brush: php; title: ; notranslate">
class EventListener
{
    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
    {
        $token = $event-&gt;getAuthenticationToken();
        $session = $event-&gt;getRequest()-&gt;getSession();
        $session-&gt;setLocale($token-&gt;getUser()-&gt;getLocale());
    }
}
</pre>
<p>into:</p>
<pre class="brush: php; title: ; notranslate">
class EventListener
{
    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
    {
        $token = $event-&gt;getAuthenticationToken();
         
        $request = $event-&gt;getRequest();
        $session = $request-&gt;getSession();

        $locale = $token-&gt;getUser()-&gt;getLocale();
        $session-&gt;set('_locale', $locale);
        $request-&gt;setLocale($locale);
    }
}
</pre>
<p>I am still not sure if this is the best solution to the problem &#8211; hopefully the new implementation will be well documented in the future or changed in a way the produces less WTFs &#8230;</p>
<p>Any comments appreciated.</p>The post <a href="https://nerdpress.org/2011/10/13/symfony-2-set-default-locale-on-form-login-2/">Symfony 2 – Set Default Locale On Form Login #2</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2011/10/13/symfony-2-set-default-locale-on-form-login-2/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
