55 * See the file LICENSE.txt for copying permission.
66 */
77namespace 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.
1617 * @Component
1718 */
1819class 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