Skip to content

Commit 31aab61

Browse files
authored
Merge pull request codeigniter4#6442 from kenjis/fix-CLIRequest-getLocale-error
fix: Call to undefined method CodeIgniter\HTTP\CLIRequest::getLocale()
2 parents 6a31be4 + 6aafff0 commit 31aab61

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

system/HTTP/CLIRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\HTTP;
1313

1414
use Config\App;
15+
use Locale;
1516
use RuntimeException;
1617

1718
/**
@@ -280,4 +281,13 @@ private function returnNullOrEmptyArray($index)
280281
{
281282
return ($index === null || is_array($index)) ? [] : null;
282283
}
284+
285+
/**
286+
* Gets the current locale, with a fallback to the default
287+
* locale if none is set.
288+
*/
289+
public function getLocale(): string
290+
{
291+
return Locale::getDefault();
292+
}
283293
}

tests/system/HTTP/CLIRequestTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,21 @@ public function testGetGet()
599599

600600
public function testGetPost()
601601
{
602-
$this->assertSame([], $this->request->getGet());
602+
$this->assertSame([], $this->request->getPost());
603603
}
604604

605605
public function testGetPostGet()
606606
{
607-
$this->assertSame([], $this->request->getGet());
607+
$this->assertSame([], $this->request->getPostGet());
608608
}
609609

610610
public function testGetGetPost()
611611
{
612-
$this->assertSame([], $this->request->getGet());
612+
$this->assertSame([], $this->request->getGetPost());
613+
}
614+
615+
public function testGetLocale()
616+
{
617+
$this->assertSame('en', $this->request->getLocale());
613618
}
614619
}

0 commit comments

Comments
 (0)