array union in controllers

! fix issue when handling parameter with string type, add according test
This commit is contained in:
Chris Reichel
2025-05-19 12:21:45 +02:00
parent 2b30ec1c9b
commit 848a90dea8
3 changed files with 8 additions and 4 deletions

View File

@ -217,6 +217,9 @@ class Controller extends \yii\base\Controller
return ['', true];
}
if ($typeName === 'string') {
return [$param, true];
}
$filterResult = $this->filterParamByType($param, $typeName);
return [$filterResult, $filterResult !== null];
}

View File

@ -235,16 +235,17 @@ class ControllerTest extends TestCase
$aksi1 = new InlineAction('aksi1', $this->controller, 'actionAksi1');
$params = ['foo' => '100', 'bar' => null, 'true' => 'on', 'false' => 'false'];
list($foo, $bar, $true, $false) = $this->controller->bindActionParams($aksi1, $params);
$params = ['foo' => '100', 'bar' => null, 'true' => 'on', 'false' => 'false', 'string' => 'strong'];
list($foo, $bar, $true, $false, $string) = $this->controller->bindActionParams($aksi1, $params);
$this->assertSame(100, $foo);
$this->assertSame(null, $bar);
$this->assertSame(true, $true);
$this->assertSame(false, $false);
$this->assertSame('strong', $string);
// allow nullable argument to be set to empty string (as null)
// https://github.com/yiisoft/yii2/issues/18450
$params = ['foo' => 100, 'bar' => '', 'true' => true, 'false' => true];
$params = ['foo' => 100, 'bar' => '', 'true' => true, 'false' => true, 'string' => 'strong'];
list(, $bar) = $this->controller->bindActionParams($aksi1, $params);
$this->assertSame(null, $bar);

View File

@ -17,7 +17,7 @@ class FakePhp7Controller extends Controller
{
public $enableCsrfValidation = false;
public function actionAksi1(int $foo, ?float $bar, bool $true, bool $false)
public function actionAksi1(int $foo, ?float $bar, bool $true, bool $false, string $string)
{
}