diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index 0b6c2b83a12d..e81ae9cabbd9 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\HTTP; use Config\App; +use Locale; use RuntimeException; /** @@ -280,4 +281,13 @@ private function returnNullOrEmptyArray($index) { return ($index === null || is_array($index)) ? [] : null; } + + /** + * Gets the current locale, with a fallback to the default + * locale if none is set. + */ + public function getLocale(): string + { + return Locale::getDefault(); + } } diff --git a/tests/system/HTTP/CLIRequestTest.php b/tests/system/HTTP/CLIRequestTest.php index e8e57dbc611b..b294d1621b2b 100644 --- a/tests/system/HTTP/CLIRequestTest.php +++ b/tests/system/HTTP/CLIRequestTest.php @@ -599,16 +599,21 @@ public function testGetGet() public function testGetPost() { - $this->assertSame([], $this->request->getGet()); + $this->assertSame([], $this->request->getPost()); } public function testGetPostGet() { - $this->assertSame([], $this->request->getGet()); + $this->assertSame([], $this->request->getPostGet()); } public function testGetGetPost() { - $this->assertSame([], $this->request->getGet()); + $this->assertSame([], $this->request->getGetPost()); + } + + public function testGetLocale() + { + $this->assertSame('en', $this->request->getLocale()); } }