Skip to content

Commit 69c1654

Browse files
authored
Merge pull request #5 from nguyenk/3.0
Add SessionManager && fix wrong session initialisation in setLanguage
2 parents 2701076 + c9a0433 commit 69c1654

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

src/Mouf/Utils/I18n/Fine/Language/SessionLanguageDetection.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* See the file LICENSE.txt for copying permission.
66
*/
77
namespace Mouf\Utils\I18n\Fine\Language;
8+
use Mouf\Utils\Session\SessionManager\SessionManagerInterface;
89

910
/**
1011
* Use fixed language detection if you want to always use the same language in your application.
@@ -16,16 +17,33 @@
1617
* @Component
1718
*/
1819
class SessionLanguageDetection implements LanguageDetectionInterface {
19-
20-
/**
20+
21+
/**
22+
* @var SessionManagerInterface
23+
*/
24+
private $sessionManager;
25+
26+
/**
27+
* SessionLanguageDetection constructor.
28+
* @param SessionManagerInterface $sessionManager
29+
*/
30+
public function __construct(SessionManagerInterface $sessionManager)
31+
{
32+
$this->sessionManager = $sessionManager;
33+
}
34+
35+
36+
/**
2137
* Returns the language to use.
2238
*
2339
* @see plugins/utils/i18n/fine/2.1/language/LanguageDetectionInterface::getLanguage()
2440
* @return string
2541
*/
2642
public function getLanguage() {
27-
if (!session_id()){
28-
session_start();
43+
if (!session_id()) {
44+
if ($this->sessionManager) {
45+
$this->sessionManager->start();
46+
}
2947
}
3048
if (!isset($_SESSION['_fine_I18n_language'])){
3149
$this->setLanguage('default');
@@ -39,6 +57,11 @@ public function getLanguage() {
3957
* @param string $language
4058
*/
4159
public function setLanguage($language) {
60+
if (!session_id()) {
61+
if ($this->sessionManager) {
62+
$this->sessionManager->start();
63+
}
64+
}
4265
$_SESSION['_fine_I18n_language'] = $language;
4366
}
4467
}

0 commit comments

Comments
 (0)