Final Class Yiisoft\Yii\DataView\ValuePresenter\SimpleValuePresenter
| Inheritance | Yiisoft\Yii\DataView\ValuePresenter\SimpleValuePresenter |
|---|---|
| Implements | Yiisoft\Yii\DataView\ValuePresenter\ValuePresenterInterface |
Presents scalars and Stringable objects as strings.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\DataView\ValuePresenter\SimpleValuePresenter | |
| present() | Yiisoft\Yii\DataView\ValuePresenter\SimpleValuePresenter |
Method Details
| public mixed __construct ( string $null = '', string $true = 'True', string $false = 'False', string $dateTimeFormat = 'Y-m-d H:i:s' ) | ||
| $null | string |
Label to use for |
| $true | string |
Label to use for |
| $false | string |
Label to use for |
| $dateTimeFormat | string |
The format to use for |
public function __construct(
private readonly string $null = '',
private readonly string $true = 'True',
private readonly string $false = 'False',
private readonly string $dateTimeFormat = 'Y-m-d H:i:s',
) {}
| public string|\Stringable present ( mixed $value ) | ||
| $value | mixed | |
| throws | InvalidArgumentException | |
|---|---|---|
public function present(mixed $value): string|Stringable
{
return match (gettype($value)) {
'NULL' => $this->null,
'boolean' => $value ? $this->true : $this->false,
'string' => $value,
'integer', 'double' => (string) $value,
'object' => match (true) {
$value instanceof Stringable => $value,
$value instanceof DateTimeInterface => $value->format($this->dateTimeFormat),
$value instanceof UnitEnum => $value->name,
default => $this->throwUnsupportedType($value),
},
default => $this->throwUnsupportedType($value),
};
}
Signup or Login in order to comment.