{"id":37001340,"url":"https://github.com/alevikzs/phmap","last_synced_at":"2026-01-14T00:09:55.609Z","repository":{"id":56944162,"uuid":"50264344","full_name":"alevikzs/phmap","owner":"alevikzs","description":"The PhMap is a library for creating objects from json strings, associative arrays and objects","archived":false,"fork":false,"pushed_at":"2017-03-18T21:20:14.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-11-16T12:06:41.111Z","etag":null,"topics":["apc","deserialization","phalcon","php","xcache"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alevikzs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-23T23:50:32.000Z","updated_at":"2017-10-19T20:00:38.000Z","dependencies_parsed_at":"2022-08-21T07:50:59.511Z","dependency_job_id":null,"html_url":"https://github.com/alevikzs/phmap","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/alevikzs/phmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alevikzs%2Fphmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alevikzs%2Fphmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alevikzs%2Fphmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alevikzs%2Fphmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alevikzs","download_url":"https://codeload.github.com/alevikzs/phmap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alevikzs%2Fphmap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["apc","deserialization","phalcon","php","xcache"],"created_at":"2026-01-14T00:09:55.060Z","updated_at":"2026-01-14T00:09:55.588Z","avatar_url":"https://github.com/alevikzs.png","language":"PHP","readme":"# PhMap\n\n[![License](http://poser.pugx.org/alevikzs/phmap/license)](https://packagist.org/packages/alevikzs/phmap)\n[![Latest Stable Version](http://poser.pugx.org/alevikzs/phmap/v/stable)](https://packagist.org/packages/alevikzs/phmap) \n[![Total Downloads](http://poser.pugx.org/alevikzs/phmap/downloads)](https://packagist.org/packages/alevikzs/phmap) \n[![Dependency Status](https://www.versioneye.com/user/projects/56da017bd5a5350029ae5cd8/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56da017bd5a5350029ae5cd8)\n[![Reference Status](https://www.versioneye.com/php/alevikzs:phmap/reference_badge.svg?style=flat)](https://www.versioneye.com/php/alevikzs:phmap/references)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/alevikzs/phmap/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/alevikzs/phmap/?branch=master)\n[![Code Climate](https://codeclimate.com/github/alevikzs/phmap/badges/gpa.svg)](https://codeclimate.com/github/alevikzs/phmap)\n[![Build Status](https://scrutinizer-ci.com/g/alevikzs/phmap/badges/build.png?b=master)](https://scrutinizer-ci.com/g/alevikzs/phmap/build-status/master)\n[![Code Coverage](https://scrutinizer-ci.com/g/alevikzs/phmap/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/alevikzs/phmap/?branch=master)\n## About\n\nThe PhMap is a PHP package for create objects from JSON strings, associative arrays and objects. The PhMap is \nbased on [phalcon annotations](https://docs.phalconphp.com/en/latest/reference/annotations.html).\n\n## Requirements\n\n* PHP \u003e= 5.4 \u0026\u0026 \u003c 7.0;\n* [Phalcon framework](https://phalconphp.com) \u003e= 2.0;\n* If you will be using [APC](http://php.net/manual/en/book.apc.php) or [XCache](https://xcache.lighttpd.net/) adapters you need to install corresponding PHP extensions.\n\n## Installation\n\n1. Require the package and its dependencies with composer: ```$ composer require alevikzs/phmap```\n2. Install [Phalcon framework](https://phalconphp.com). Detail guide is [here](https://phalconphp.com/en/download).\n\n## How to use\n\n```php\nclass Tree {\n\n    private $height;\n    private $name;\n    private $branch;\n\n    public function getHeight() {\n        return $this-\u003eheight;\n    }\n\n    public function setHeight($height) {\n        $this-\u003eheight = $height;\n    }\n\n    public function getName() {\n        return $this-\u003ename;\n    }\n\n    public function setName($name) {\n        $this-\u003ename = $name;\n    }\n\n    public function getBranch() {\n        return $this-\u003ebranch;\n    }\n\n    /**\n     * @mapper(class=\"\\Tests\\Dummy\\Branch\")\n     */\n    public function setBranch(Branch $branch) {\n        $this-\u003ebranch = $branch;\n    }\n    \n}\n```\n\nAs you can see, if some property of you object has type of another class - you must declare an annotation ```@mapper``` \nfor setter method of this property. This annotation has two arguments: ```class``` and ```isArray```. The first \nargument is a string with the class name and second is a boolean value that indicates your property value is\narray or not.\n\n```php\nclass Branch {\n\n    private $length;\n    private $leaves;\n    \n    public function getLength() {\n        return $this-\u003elength;\n    }\n\n    public function setLength($length) {\n        $this-\u003elength = $length;\n    }\n\n    public function getLeaves() {\n        return $this-\u003eleaves;\n    }\n\n    /**\n     * @mapper(class=\"\\Tests\\Dummy\\Leaf\", isArray=true)\n     */\n    public function setLeaves(array $leaves) {\n        $this-\u003eleaves = $leaves;\n    }\n\n}\n\nclass Leaf {\n\n    private $height;\n    private $width;\n    \n    public function getHeight() {\n        return $this-\u003eheight;\n    }\n\n    public function setHeight($height) {\n        $this-\u003eheight = $height;\n    }\n\n    public function getWidth() {\n        return $this-\u003ewidth;\n    }\n\n    public function setWidth($width) {\n        $this-\u003ewidth = $width;\n    }\n\n}\n```\n\nCreate object of Tree class from JSON string:\n\n```php\n$result = (new \\PhMap\\Wrapper\\Json($json, 'Tree'))-\u003emap();\n```\n\nCreate object of Tree class from associative array:\n\n```php\n$result = (new \\PhMap\\Mapper\\Structure\\Associative($array, 'Tree'))-\u003emap();\n```\n\nCreate object of Tree class from another object:\n\n```php\n$result = (new \\PhMap\\Mapper\\Structure\\Object($object, 'Tree'))-\u003emap();\n```\n\nYou can use ```\\PhMap\\Mapper\\Smart``` if you don't know what type of you value. In this case mapping instructions \nwill be applied automatically:\n\n```php\n$result = (new \\PhMap\\Wrapper\\Smart($value, 'Tree'))-\u003emap();\n```\n\nBy default mapper use [memory adapter](https://docs.phalconphp.com/en/latest/api/Phalcon_Annotations_Adapter_Memory.html),\nbut also you can use [file adapter](https://docs.phalconphp.com/en/latest/api/Phalcon_Annotations_Adapter_Files.html),\n[APC adapter](https://docs.phalconphp.com/en/latest/api/Phalcon_Annotations_Adapter_Apc.html) and\n[XCache adapter](https://docs.phalconphp.com/en/latest/api/Phalcon_Annotations_Adapter_Xcache.html):\n\n```php\nnew \\PhMap\\Wrapper\\Json($json, 'Tree', \\PhMap\\Mapper::MEMORY_ANNOTATION_ADAPTER);\n\nnew \\PhMap\\Wrapper\\Smart($json, 'Tree', \\PhMap\\Mapper::FILES_ANNOTATION_ADAPTER);\n\nnew \\PhMap\\Mapper\\Structure\\Associative($array, 'Tree', \\PhMap\\Mapper::APC_ANNOTATION_ADAPTER);\n\nnew \\PhMap\\Mapper\\Structure\\Object($object, 'Tree', \\PhMap\\Mapper::X_CACHE_ANNOTATION_ADAPTER);\n```\n\nAlso, you can pass already exist object to constructor:\n\n```php\n$tree = new Tree();\n\n$result = (new \\PhMap\\Mapper\\Smart($json, $tree))-\u003emap();\n```\n\nYou can reuse mapper object. Just set the necessary properties, and call the method ```map()```:\n\n```php\n$mapper = new \\PhMap\\Mapper\\Structure\\Object($tree, 'Tree', \\PhMap\\Mapper::X_CACHE_ANNOTATION_ADAPTER)\n$result = $mapper-\u003emap();\n\n$mapper-\u003esetInputObject($branch)\n    -\u003esetOutputObject(new Branch())\n    -\u003esetAnnotationAdapterType(Mapper::MEMORY_ANNOTATION_ADAPTER);\n$result = $mapper-\u003emap();\n```\n\nMapper object has ```setTransforms(Transforms $transforms)``` method. The argument of this method is a transforms \nobject. This object is used to declare a set of rules where each rule indicates what field of input value corresponds \nto the output field value:\n\n```php\n$mapper = new \\PhMap\\Mapper\\Structure\\Object($tree, 'Tree')\n\n$transforms = (new \\PhMap\\Transforms())\n    -\u003eadd(\n        (new \\PhMap\\Transform())\n            -\u003esetInputFieldName('nameIn')\n            -\u003esetOutputFieldName('name')\n    )\n    -\u003eadd(\n        (new \\PhMap\\Transform())\n            -\u003esetInputFieldName('branchIn')\n            -\u003esetOutputFieldName('branch')\n            -\u003esetTransforms(\n                (new \\PhMap\\Transforms())-\u003eadd(\n                    (new \\PhMap\\Transform())\n                        -\u003esetInputFieldName('leavesIn')\n                        -\u003esetOutputFieldName('leaves')\n                )\n            )\n    );\n\n$result = $mapper-\u003esetTransforms($transforms)-\u003emap();\n```\n\nFor skipping some attributes and not map them, you can use ```setSkipAttributes(array $attributes)```:\n\n```php\n$mapper = new \\PhMap\\Mapper\\Structure\\Object($tree, 'Tree')\n\n$attributes = [\n    'name',\n    'branch.length'\n];\n\n$result = $mapper-\u003esetSkipAttributes($attributes)-\u003emap();\n```\n\nIf you want to disable validation you can use ```disableValidation()``` method:\n\n```php\n$result = $mapper-\u003edisableValidation()-\u003emap();\n```\n\nIf you want your class can map some value to itself you must use MapperTrait in your class declaration:\n\n```php\nclass Tree {\n\n   use \\PhMap\\MapperTrait;\n   \n   //other class declaration\n   \n}\n```\n\nand then you can call ```mapper()``` or ```staticMapper()``` methods:\n\n```php\n$tree = new Tree();\n$result = $tree-\u003emapper($json)-\u003emap();\n\n$result = Tree::staticMapper($json)-\u003emap();\n```\n\n## The MIT License (MIT)\n\n**Copyright (c) 2016 Alexey Novikov \u003calekseeey@gmail.com\u003e**\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falevikzs%2Fphmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falevikzs%2Fphmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falevikzs%2Fphmap/lists"}