0 follower

Final Class Yiisoft\Data\Db\FieldMapper\ArrayFieldMapper

InheritanceYiisoft\Data\Db\FieldMapper\ArrayFieldMapper
ImplementsYiisoft\Data\Db\FieldMapper\FieldMapperInterface

Maps field names using an array-based mapping configuration.

This mapper uses a predefined array to map field names to database column names or expressions. If a field is not found in the mapping, it returns the original field name.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( (\Yiisoft\Db\Expression\ExpressionInterface|string)[] $map )
$map (\Yiisoft\Db\Expression\ExpressionInterface|string)[]

The field mapping array where keys are field names and values are column names or expressions.

For example:

[
    'name' => 'username',
    'jobId' => 'job_id',
    'profileData' => new Expression("data->>'profile'"),
]
 ```

                public function __construct(
    private readonly array $map,
) {}

            
map() public method

public string|\Yiisoft\Db\Expression\ExpressionInterface map ( string $field )
$field string

                public function map(string $field): string|ExpressionInterface
{
    return $this->map[$field] ?? $field;
}