11
11
12
12
namespace CodeIgniter \Exceptions ;
13
13
14
+ use Config \Services ;
14
15
use OutOfBoundsException ;
15
16
16
17
class PageNotFoundException extends OutOfBoundsException implements ExceptionInterface
@@ -26,21 +27,37 @@ class PageNotFoundException extends OutOfBoundsException implements ExceptionInt
26
27
27
28
public static function forPageNotFound (?string $ message = null )
28
29
{
29
- return new static ($ message ?? lang ('HTTP.pageNotFound ' ));
30
+ return new static ($ message ?? self :: lang ('HTTP.pageNotFound ' ));
30
31
}
31
32
32
33
public static function forEmptyController ()
33
34
{
34
- return new static (lang ('HTTP.emptyController ' ));
35
+ return new static (self :: lang ('HTTP.emptyController ' ));
35
36
}
36
37
37
38
public static function forControllerNotFound (string $ controller , string $ method )
38
39
{
39
- return new static (lang ('HTTP.controllerNotFound ' , [$ controller , $ method ]));
40
+ return new static (self :: lang ('HTTP.controllerNotFound ' , [$ controller , $ method ]));
40
41
}
41
42
42
43
public static function forMethodNotFound (string $ method )
43
44
{
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 );
45
62
}
46
63
}
0 commit comments