Skip to content

Map to object where properties are in a single associative array #82

@dingledorf

Description

@dingledorf

Hey there,

I was wondering if there was an easy way to map to a destination object where all the properties are in a single associative array?

For example

class Employee
{
    private $id;
    private $firstName;
    private $lastName;
    private $birthYear;
    
    public function __construct($id, $firstName, $lastName, $birthYear)
    {
        $this->id = $id;
        $this->firstName = $firstName;
        $this->lastName = $lastName;
        $this->birthYear = $birthYear;
    }

    public function getId()
    {
        return $this->id;
    }

    // And so on...
}

and MapTo

class EmployeeEntity
{
    private $_propDict = [];
    
    public function getId()
    {
        return $_propDict['id'] ?? null;
    }

    public function setId($val)
    {
        $_propDict['id'] = $val;
    }

    // And so on...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions