1111
1212namespace CodeIgniter \Exceptions ;
1313
14+ use Config \Services ;
1415use OutOfBoundsException ;
1516
1617class PageNotFoundException extends OutOfBoundsException implements ExceptionInterface
@@ -26,21 +27,37 @@ class PageNotFoundException extends OutOfBoundsException implements ExceptionInt
2627
2728 public static function forPageNotFound (?string $ message = null )
2829 {
29- return new static ($ message ?? lang ('HTTP.pageNotFound ' ));
30+ return new static ($ message ?? self :: lang ('HTTP.pageNotFound ' ));
3031 }
3132
3233 public static function forEmptyController ()
3334 {
34- return new static (lang ('HTTP.emptyController ' ));
35+ return new static (self :: lang ('HTTP.emptyController ' ));
3536 }
3637
3738 public static function forControllerNotFound (string $ controller , string $ method )
3839 {
39- return new static (lang ('HTTP.controllerNotFound ' , [$ controller , $ method ]));
40+ return new static (self :: lang ('HTTP.controllerNotFound ' , [$ controller , $ method ]));
4041 }
4142
4243 public static function forMethodNotFound (string $ method )
4344 {
44- return new static (lang ('HTTP.methodNotFound ' , [$ method ]));
45+ return new static (self ::lang ('HTTP.methodNotFound ' , [$ method ]));
46+ }
47+
48+ /**
49+ * Get translated system message
50+ *
51+ * Use a non-shared Language instance in the Services.
52+ * If a shared instance is created, the Language will
53+ * have the current locale, so even if users call
54+ * `$this->request->setLocale()` in the controller afterwards,
55+ * the Language locale will not be changed.
56+ */
57+ private static function lang (string $ line , array $ args = []): string
58+ {
59+ $ lang = Services::language (null , false );
60+
61+ return $ lang ->getLine ($ line , $ args );
4562 }
4663}
0 commit comments