Created
January 24, 2012 13:24
-
-
Save Dattaya/1670163 to your computer and use it in GitHub Desktop.
Revisions
-
Yaroslav Kiliba revised this gist
Jan 30, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ framework: ... translator: { fallback: %fallback_locale% } session: default_locale: %locale% -
Yaroslav Kiliba revised this gist
Jan 30, 2012 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,4 @@ framework: translator: { fallback: %fallback_locale% } session: default_locale: %locale% -
Yaroslav Kiliba revised this gist
Jan 30, 2012 . 7 changed files with 5 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # symfony2/app/config/parameters.ini locale="undefined" fallback_locale="en" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ framework: translator: { fallback: %fallback_locale% } File renamed without changes.File renamed without changes.File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ -
Yaroslav Kiliba revised this gist
Jan 26, 2012 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,9 +35,6 @@ public function setLocaleForUnauthenticatedUser(GetResponseEvent $event) */ public function setLocaleForAuthenticatedUser(InteractiveLoginEvent $event) { /** @var \Application\Sonata\UserBundle\Entity\User $user */ $user = $event->getAuthenticationToken()->getUser(); -
Yaroslav Kiliba revised this gist
Jan 25, 2012 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ Reading order: parameters.ini User.php services.yml UserListener.php -
Yaroslav Kiliba renamed this gist
Jan 25, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Yaroslav Kiliba revised this gist
Jan 25, 2012 . 2 changed files with 5 additions and 86 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,86 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ Reading order: symfony2/app/config/parameters.ini symfony2/src/Application/Sonata/UserBundle/Entity/User.php symfony2/src/Application/Sonata/UserBundle/Resources/config/services.yml symfony2/src/Application/Sonata/UserBundle/EventListener/UserListener.php -
Yaroslav Kiliba revised this gist
Jan 25, 2012 . 4 changed files with 86 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ <?php // symfony2/src/Application/Sonata/UserBundle/Entity/User.php class User extends BaseUser { //... /** * @ORM\Column(name="locale", type="string", length=5, nullable="true") * */ protected $locale; public function getLocale() { return $this->locale; } /** * @param string $locale */ public function setLocale($locale) { $this->locale = $locale; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ <?php // symfony2/src/Application/Sonata/UserBundle/EventListener/UserListener.php namespace Application\Sonata\UserBundle\EventListener; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent, Symfony\Component\HttpKernel\Event\GetResponseEvent, Symfony\Component\HttpKernel\HttpKernelInterface; class UserListener { /** * kernel.request event. If a guest user doesn't have an opened session, locale is equal to * "undefined" as configured by default in parameters.ini. If so, set as a locale the user's * preferred language. * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ public function setLocaleForUnauthenticatedUser(GetResponseEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; } $request = $event->getRequest(); if ('undefined' == $request->getLocale()) { $request->setLocale($request->getPreferredLanguage()); } } /** * security.interactive_login event. If a user chose a locale in preferences, it would be set, * if not, a locale that was set by setLocaleForUnauthenticatedUser remains. * * @param \Symfony\Component\Security\Http\Event\InteractiveLoginEvent $event */ public function setLocaleForAuthenticatedUser(InteractiveLoginEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; } /** @var \Application\Sonata\UserBundle\Entity\User $user */ $user = $event->getAuthenticationToken()->getUser(); if ($user->getLocale()) { $event->getRequest()->setLocale($user->getLocale()); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # symfony2/app/config/parameters.ini locale="undefined" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ # symfony2/src/Application/Sonata/UserBundle/Resources/config/services.yml services: application_sonata_user.security.interactive_login_listener: class: Application\Sonata\UserBundle\EventListener\UserListener tags: - { name: kernel.event_listener, event: security.interactive_login, method: setLocaleForAuthenticatedUser } application_sonata_user.security.kernel_request_listener: class: Application\Sonata\UserBundle\EventListener\UserListener tags: - { name: kernel.event_listener, event: kernel.request, method: setLocaleForUnauthenticatedUser } -
Dattaya revised this gist
Jan 24, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ // symfony2/app/config/parameters.ini locale="undefined" // symfony2/src/Application/Sonata/UserBundle/Entity/User.php class User extends BaseUser { ... -
Dattaya revised this gist
Jan 24, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ // symfony2/app/config/parameters.ini locale="undefined" // User entity class User extends BaseUser { ... -
Dattaya revised this gist
Jan 24, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,6 +38,7 @@ services: tags: - { name: kernel.event_listener, event: kernel.request, method: setLocaleForUnauthenticatedUser } // symfony2/src/Application/Sonata/UserBundle/EventListener/UserListener.php namespace Application\Sonata\UserBundle\EventListener; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent, Symfony\Component\HttpKernel\Event\GetResponseEvent, -
Dattaya revised this gist
Jan 24, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,7 @@ class User extends BaseUser * */ protected $locale; public function getLocale() { return $this->locale; -
Dattaya revised this gist
Jan 24, 2012 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,9 @@ use Symfony\Component\Security\Http\Event\InteractiveLoginEvent, class UserListener { /** * kernel.request event. If a guest user doesn't have an opened session, locale is equal to * "undefined" as configured by default in parameters.ini. If so, set as a locale the user's * preferred language. * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ @@ -62,7 +64,8 @@ class UserListener } /** * security.interactive_login event. If a user chose a locale in preferences, it would be set, * if not, a locale that was set by setLocaleForUnauthenticatedUser remains. * * @param \Symfony\Component\Security\Http\Event\InteractiveLoginEvent $event */ -
Dattaya revised this gist
Jan 24, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,7 +35,7 @@ services: application_sonata_user.security.kernel_request_listener: class: Application\Sonata\UserBundle\EventListener\UserListener tags: - { name: kernel.event_listener, event: kernel.request, method: setLocaleForUnauthenticatedUser } namespace Application\Sonata\UserBundle\EventListener; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent, @@ -50,7 +50,7 @@ class UserListener * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ public function setLocaleForUnauthenticatedUser(GetResponseEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; -
Dattaya revised this gist
Jan 24, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <?php // symfony2/app/config/parameters.ini locale="undefined" //User entity class User extends BaseUser -
Dattaya revised this gist
Jan 24, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php // symfony2/app/config/parameters.ini // locale="undefined" -
Dattaya created this gist
Jan 24, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,80 @@ // symfony2/app/config/parameters.ini // locale="undefined" //User entity class User extends BaseUser { ... /** * @ORM\Column(name="locale", type="string", length=5, nullable="true") * */ protected $locale; public function getLocale() { return $this->locale; } /** * @param string $locale */ public function setLocale($locale) { $this->locale = $locale; } } // symfony2/src/Application/Sonata/UserBundle/Resources/config/services.yml services: application_sonata_user.security.interactive_login_listener: class: Application\Sonata\UserBundle\EventListener\UserListener tags: - { name: kernel.event_listener, event: security.interactive_login, method: setLocaleForAuthenticatedUser } application_sonata_user.security.kernel_request_listener: class: Application\Sonata\UserBundle\EventListener\UserListener tags: - { name: kernel.event_listener, event: kernel.request, method: setLocaleForUnauthenticatedFirstTimeAccessUser } namespace Application\Sonata\UserBundle\EventListener; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent, Symfony\Component\HttpKernel\Event\GetResponseEvent, Symfony\Component\HttpKernel\HttpKernelInterface; class UserListener { /** * kernel.request event * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ public function setLocaleForUnauthenticatedFirstTimeAccessUser(GetResponseEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; } $request = $event->getRequest(); if ('undefined' == $request->getLocale()) { $request->setLocale($request->getPreferredLanguage()); } } /** * security.interactive_login event * * @param \Symfony\Component\Security\Http\Event\InteractiveLoginEvent $event */ public function setLocaleForAuthenticatedUser(InteractiveLoginEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; } /** @var \Application\Sonata\UserBundle\Entity\User $user */ $user = $event->getAuthenticationToken()->getUser(); if ($user->getLocale()) { $event->getRequest()->setLocale($user->getLocale()); } } }