Skip to content

Use container to get request locale #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Bundle/I18nBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ services:
victoire_i18n.translator:
class: Victoire\Bundle\I18nBundle\Translation\Translator
arguments: ["@service_container", "@translator.selector",{}, {cache_dir:"%kernel.cache_dir%/translations%", debug: "%kernel.debug%"}]
scope: request
calls:
- [ setRequestStack, ["@request_stack"] ]

victoire_i18n.locale_subscriber:
class: Victoire\Bundle\I18nBundle\Subscriber\LocaleSubscriber
Expand Down
14 changes: 5 additions & 9 deletions Bundle/I18nBundle/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Symfony\Bundle\FrameworkBundle\Translation\Translator as BaseTranslator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Translation\MessageSelector;

class Translator extends BaseTranslator
Expand All @@ -16,7 +15,6 @@ class Translator extends BaseTranslator
'resource_files' => [],
];
protected $loaderIds;
protected $requestStack;

/**
* @var MessageSelector
Expand Down Expand Up @@ -111,15 +109,13 @@ public function getVictoireLocale()
return $this->locale;
}

public function setRequestStack(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

/**
* @return mixed|string
*/
public function getCurrentLocale()
{
if ($this->requestStack) {
return $this->requestStack->getCurrentRequest()->getLocale();
if ($this->container->get('request_stack')->getCurrentRequest()) {
return $this->container->get('request')->getLocale();
}

return $this->container->getParameter('kernel.default_locale');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,36 @@ public function generateKey($alias, $id)
return $alias.':'.$id;
}

public static function isSerialized($data) {
public static function isSerialized($data)
{
// if it isn't a string, it isn't serialized
if ( !is_string( $data ) )
if (!is_string($data)) {
return false;
$data = trim( $data );
if ( 'N;' == $data )
}
$data = trim($data);
if ('N;' == $data) {
return true;
if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
}
if (!preg_match('/^([adObis]):/', $data, $badions)) {
return false;
switch ( $badions[1] ) {
case 'a' :
case 'O' :
case 's' :
if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
}
switch ($badions[1]) {
case 'a':
case 'O':
case 's':
if (preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data)) {
return true;
}
break;
case 'b' :
case 'i' :
case 'd' :
if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
case 'b':
case 'i':
case 'd':
if (preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data)) {
return true;
}
break;
}

return false;
}
}