{"id":21090931,"url":"https://github.com/gjerokrsteski/php-identity-map","last_synced_at":"2025-07-03T17:35:17.342Z","repository":{"id":148208313,"uuid":"2658578","full_name":"gjerokrsteski/php-identity-map","owner":"gjerokrsteski","description":"Building an Identity Map in PHP","archived":false,"fork":false,"pushed_at":"2012-07-07T08:47:14.000Z","size":208,"stargazers_count":19,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-16T13:44:31.998Z","etag":null,"topics":["data-mapper","identity-map","oop","pdo","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"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/gjerokrsteski.png","metadata":{"files":{"readme":"README.markdown","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":"2011-10-27T14:09:43.000Z","updated_at":"2025-02-06T14:17:40.000Z","dependencies_parsed_at":"2023-03-27T17:17:07.674Z","dependency_job_id":null,"html_url":"https://github.com/gjerokrsteski/php-identity-map","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gjerokrsteski/php-identity-map","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-identity-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-identity-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-identity-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-identity-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gjerokrsteski","download_url":"https://codeload.github.com/gjerokrsteski/php-identity-map/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-identity-map/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263370146,"owners_count":23456420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["data-mapper","identity-map","oop","pdo","php"],"created_at":"2024-11-19T21:42:10.791Z","updated_at":"2025-07-03T17:35:17.304Z","avatar_url":"https://github.com/gjerokrsteski.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Building an Identity Map in PHP\n===============================\n\nSample application used for training.\n\nThis example code is no production code and should be used for training\npurposes only.\n\nThis example code requires:\n---------------------------\n* PDO a lightweight, consistent interface for accessing databases in PHP.\n* PHPUnit a unit testing framework for PHP projects.\n\nThis example code implements:\n-----------------------\n* Data-Mapper Pattern\n* Identity-Map Pattern\n\nWhy identity mapping?\n---------------------\nBy using Data-Mapper pattern without an identity map, you can easily run\ninto problems because you may have more than one object that references\nthe same domain entity.\n\nData-Mapper without identity map\n----------------------------------\n\n      $userMapper = new UserMapper($pdo);\n\n      $user1 = $userMapper-\u003efind(1); // creates new object\n      $user2 = $userMapper-\u003efind(1); // creates new object\n\n      echo $user1-\u003egetNickname(); // joe123\n      echo $user2-\u003egetNickname(); // joe123\n\n      $user1-\u003esetNickname('bob78');\n\n      echo $user1-\u003egetNickname(); // bob78\n      echo $user2-\u003egetNickname(); // joe123 -\u003e ?!?\n\nData-Mapper with identity map\n----------------------------------\nThe identity map solves this problem by acting as a registry for all\nloaded domain instances.\n\n      $userMapper = new UserMapper($pdo);\n\n      $user1 = $userMapper-\u003efind(1); // creates new object\n      $user2 = $userMapper-\u003efind(1); // returns same object\n\n      echo $user1-\u003egetNickname(); // joe123\n      echo $user2-\u003egetNickname(); // joe123\n\n      $user1-\u003esetNickname('bob78');\n\n      echo $user1-\u003egetNickname(); // bob78\n      echo $user2-\u003egetNickname(); // bob78 -\u003e yes, much better\n\nBy using an identity map you can be confident that your domain entity is\nshared throughout your application for the duration of the request.\n\nNote that using an identity map is not the same as adding a cache layer\nto your mappers. Although caching is useful and encouraged, it can still\nproduce duplicate objects for the same domain entity.\n\nLoad the Data-Mappers with the Repository class\n-----------------------------------------------\n\n\n      $repository = new Repository($this-\u003edb);\n      $userMapper = $repository-\u003eload('User');\n      $insertId = $userMapper-\u003einsert(new User('billy', 'gatter'));\n      \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgjerokrsteski%2Fphp-identity-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgjerokrsteski%2Fphp-identity-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgjerokrsteski%2Fphp-identity-map/lists"}