Skip to content

Commit

Permalink
updating bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
janwebdev committed Apr 15, 2022
1 parent 299c20a commit c5f5a8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 4 additions & 12 deletions Listener/LocaleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace Janwebdev\SFI18nBundle\Listener;

use Janwebdev\SFI18nBundle\Locale\LocaleInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
/**
*
* @author Leonardo Proietti (leonardo.proietti@gmail.com)
* @author Jan Rogozinsky (janwebdev@gmail.com)
*/
class LocaleListener implements EventSubscriberInterface
class LocaleListener
{
private LocaleInterface $locale;

Expand All @@ -18,14 +17,7 @@ public function __construct(LocaleInterface $locale)
$this->locale = $locale;
}

public static function getSubscribedEvents(): array
{
return [
'kernel.request' => 'setLocale'
];
}

public function setLocale(ResponseEvent $event): void
public function setLocale(RequestEvent $event): void
{
$this->locale->setLocale($event->getRequest()->getLocale());
}
Expand Down
5 changes: 4 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
services:
jwd.i18n.event.adapter:
class: Janwebdev\SFI18nBundle\Mapping\Event\Adapter\ORM\DoctrineAdapter

jwd.i18n.locale:
class: Janwebdev\SFI18nBundle\Locale\Locale
arguments: ["%locale%"]

jwd.i18n.locale_listener:
class: Janwebdev\SFI18nBundle\Listener\LocaleListener
arguments: ["@jwd.i18n.locale"]
tags:
- { name: kernel.event_subscriber }
- { name: kernel.event_listener, event: kernel.request, method: setLocale }

jwd.i18n.translatable_listener:
class: Janwebdev\SFI18nBundle\Listener\TranslatableListener
arguments: ["@jwd.i18n.event.adapter", "@jwd.i18n.locale"]
Expand Down

0 comments on commit c5f5a8b

Please sign in to comment.