{"id":18440917,"url":"https://github.com/pfazzi/simplex-mapper","last_synced_at":"2026-03-01T14:02:34.428Z","repository":{"id":57038329,"uuid":"444551434","full_name":"pfazzi/simplex-mapper","owner":"pfazzi","description":"A simple PHP library to transfer data from a source (object or array) to an object.","archived":false,"fork":false,"pushed_at":"2022-01-07T08:59:20.000Z","size":38,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-03T21:51:59.971Z","etag":null,"topics":["mapping","orm","php","sql"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pfazzi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-04T20:17:19.000Z","updated_at":"2022-09-22T14:27:39.000Z","dependencies_parsed_at":"2022-08-24T14:52:53.180Z","dependency_job_id":null,"html_url":"https://github.com/pfazzi/simplex-mapper","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/pfazzi/simplex-mapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfazzi%2Fsimplex-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfazzi%2Fsimplex-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfazzi%2Fsimplex-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfazzi%2Fsimplex-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pfazzi","download_url":"https://codeload.github.com/pfazzi/simplex-mapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfazzi%2Fsimplex-mapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29970543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T13:32:00.443Z","status":"ssl_error","status_checked_at":"2026-03-01T13:32:00.084Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mapping","orm","php","sql"],"created_at":"2024-11-06T06:33:56.873Z","updated_at":"2026-03-01T14:02:34.308Z","avatar_url":"https://github.com/pfazzi.png","language":"PHP","readme":"# SimplexMapper\n\nA simple PHP library to transfer data from a source (object or array) to an object.\n\n```php\n$dbData = [\n    'username' =\u003e 'pfazzi',\n    'emailAddress' =\u003e 'pfazzi@test.com',\n    'isEnabled' =\u003e '1',\n];\n\n$mapper = new \\Pfazzi\\SimplexMapper\\Mapper();\n\n$user = $mapper-\u003emap(\n    source: $dbData, \n    target: User::class, \n);\n```\n\nAre you looking for an easy way to convert an array to an object?  \nDo you want to map a DTO to a domain object?  \nDo you want to hydrate an object from an array?  \nUse SimplexMapper! \n\n## Features\n\n- Easy to use\n- Zero configuration\n- Zero dependencies\n- Supports PHP 8 union types\n- Supports nested objects\n- Uses reflection, no need to modify your objects\n\n## Installation\n\nInstall SimplexMapper with composer\n\n```bash\ncomposer require pfazzi/simplex-mapper\n```\n\n## Usage\n\n### Map\n\nMaps the source data to a new instance of the target class\n\n```php\n$mapper = new \\Pfazzi\\SimplexMapper\\Mapper();\n\n// From Array \n\n$userEntity = $mapper-\u003emap(source: ['name' =\u003e 'patrick'], target: UserEntity::class);\n\n// From stdClass \n\n$rawData = new \\stdClass();\n$rawData-\u003ename = 'Patrick';\n\n$userEntity = $mapper-\u003emap(source: $rawData, target: UserEntity::class);\n\n// From anonymous class\n\n$rawData = new class {\n    public function __construct(private string $name = 'Patrick') {}\n};\n\n$userEntity = $mapper-\u003emap(source: $rawData, target: UserEntity::class);\n\n// From object\n\n$rawData = new UserDto('Patrick');\n\n$userEntity = $mapper-\u003emap(source: $rawData, target: UserEntity::class);\n```\n\n### Hydrate\n\nHydrates an object instance with data from the source:\n\n```php\n$mapper = new \\Pfazzi\\SimplexMapper\\Mapper();\n\n$userEntity = $entityManager-\u003efind(UserEntity::class, 1);\n\n// From Array \n\n$mapper-\u003ehydrate(source: ['name' =\u003e 'patrick'], target: $userEntity);\n\n// From stdClass \n\n$rawData = new \\stdClass();\n$rawData-\u003ename = 'Patrick';\n\n$mapper-\u003emap(source: $rawData, target: $userEntity);\n\n// From anonymous class\n\n$rawData = new class {\n    public function __construct(private string $name = 'Patrick') {}\n};\n\n$mapper-\u003emap(source: $rawData, target: $userEntity);\n\n// From object\n\n$rawData = new UserDto('Patrick');\n\n$mapper-\u003emap(source: $rawData, target: $userEntity);\n```\n\n## Use Cases\n\n### Map database data to read models\n\nYou want to read data from supplier table using Doctrine DBAL Connection and instantiate a Supplier read model:\n\n```php\nclass Supplier\n{\n    public function __construct(\n        public int $id,\n        public string $taxId,\n        public bool $onConsignment,\n    ) {\n    }\n}\n\n$result = $connection-\u003eexecuteQuery(\u003c\u003c\u003c'SQL'\n    SELECT\n        supplier.id,\n        supplier.tax_id AS taxId,\n        supplier.is_enabled AS isEnabled\n    FROM supplier\n    WHERE supplier.tax_id = :taxId\nSQL, ['taxId' =\u003e $taxId]);\n\n$data = $result-\u003efetchAssociative();\n```\n\nWithout SimplexMapper you have to write mapping code, such as:\n\n```php\n$readModel = new Supplier(\n    (int) $data['id'],\n    $data['taxId'],\n    '1' == $data['isEnabled'],\n);\n```\n\nWith SimplexMapper all you need to write is just the following line:\n\n```php\n$readModel = $this-\u003emapper-\u003emap($data, Supplier::class);\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpfazzi%2Fsimplex-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpfazzi%2Fsimplex-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpfazzi%2Fsimplex-mapper/lists"}