{"id":36981625,"url":"https://github.com/mozahran/data-mapper","last_synced_at":"2026-01-13T22:51:28.852Z","repository":{"id":52850751,"uuid":"352042192","full_name":"mozahran/data-mapper","owner":"mozahran","description":"A data mapping tool that helps you map JSON with configuration files (JSON structure transformation). It also supports if conditions, casting, and mutators (custom or built-in functions).","archived":false,"fork":false,"pushed_at":"2024-11-25T21:38:55.000Z","size":57,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-27T16:49:01.948Z","etag":null,"topics":["data","json","mapper","mappings","mutator","transformer"],"latest_commit_sha":null,"homepage":"","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/mozahran.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":"2021-03-27T10:21:14.000Z","updated_at":"2024-11-25T21:38:59.000Z","dependencies_parsed_at":"2022-08-20T15:30:12.848Z","dependency_job_id":null,"html_url":"https://github.com/mozahran/data-mapper","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/mozahran/data-mapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozahran%2Fdata-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozahran%2Fdata-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozahran%2Fdata-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozahran%2Fdata-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mozahran","download_url":"https://codeload.github.com/mozahran/data-mapper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozahran%2Fdata-mapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28402171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: 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":["data","json","mapper","mappings","mutator","transformer"],"created_at":"2026-01-13T22:51:28.747Z","updated_at":"2026-01-13T22:51:28.838Z","avatar_url":"https://github.com/mozahran.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/mozahran/data-mapper/actions/workflows/php.yml/badge.svg)](https://github.com/mozahran/data-mapper/actions/workflows/php.yml)\n\n# JSON Data Mapper\n\n\u003e Author: [Mohamed Zahran](https://www.linkedin.com/in/mo-zahran/)\n\n## Requirements\n\n- PHP 7.2 or higher.\n- cakephp/utility 4.0 or higher.\n\n## Table of Contents\n\n* [Installation](#installation)\n* [Usage](#usage)\n* [Examples](#mappings-examples)\n    1. [Mapping JSON Objects](#1-mapping-json-objects)\n    1. [Mapping JSON Arrays](#2-mapping-json-arrays)\n    1. [Applying Conditions](#3-applying-conditions)\n    1. [Cast Values To Another Type](#4-cast-values-to-another-type)\n    1. [Applying Mutators](#5-applying-mutators)\n    1. [Additional Features](#6-additional-features)\n* [Extending The Package](#extending-the-package)\n    1. [Custom Cast Type](#custom-cast-type)\n    1. [Add Custom Condition](#add-custom-condition)\n    1. [Add Custom Mutator](#add-custom-mutator)\n* [Contributing](#contributing)\n* [Credits](#credits)\n* [License](#license)\n\n## Installation\n\nInstall using composer:\n\n```bash\ncomposer require zahran/data-mapper\n```\n\n## Usage\n\nAfter installing the package, make sure you get an instance of the `Container` and register the instances that the tool\nneeds. Each instance have an alias/id so it can be easily overridden by custom implementations. The overriding part will\nbe explained in detail later on.\n\n```php\n\u003c?php\n\nrequire_once 'vendor/autoload.php';\n$container = \\Zahran\\Mapper\\Container::getInstance();\n$container-\u003eadd([\n    'cast_type.boolean' =\u003e new \\Zahran\\Mapper\\CastType\\Boolean(),\n    'cast_type.date' =\u003e new \\Zahran\\Mapper\\CastType\\Date(),\n    'cast_type.integer' =\u003e new \\Zahran\\Mapper\\CastType\\Integer(),\n    'cast_type.string' =\u003e new \\Zahran\\Mapper\\CastType\\Stringify(),\n    'cast_type.float' =\u003e new \\Zahran\\Mapper\\CastType\\FloatingPointNumber(),\n    'condition.contains' =\u003e new \\Zahran\\Mapper\\Condition\\Contains(),\n    'condition.eq' =\u003e new \\Zahran\\Mapper\\Condition\\Equals(),\n    'condition.gt' =\u003e new \\Zahran\\Mapper\\Condition\\GreaterThan(),\n    'condition.gte' =\u003e new \\Zahran\\Mapper\\Condition\\GreaterThanOrEquals(),\n    'condition.in' =\u003e new \\Zahran\\Mapper\\Condition\\Inset(),\n    'condition.not_in' =\u003e new \\Zahran\\Mapper\\Condition\\NotInset(),\n    'condition.lt' =\u003e new \\Zahran\\Mapper\\Condition\\LessThan(),\n    'condition.lte' =\u003e new \\Zahran\\Mapper\\Condition\\LessThanOrEquals(),\n    'condition.neq' =\u003e new \\Zahran\\Mapper\\Condition\\NotEquals(),\n    'condition.notnull' =\u003e new \\Zahran\\Mapper\\Condition\\NotNullable(),\n    'condition.null' =\u003e new \\Zahran\\Mapper\\Condition\\Nullable(),\n    'condition.is_numeric' =\u003e new \\Zahran\\Mapper\\Condition\\IsNumeric(),\n    'condition.is_string' =\u003e new \\Zahran\\Mapper\\Condition\\IsString(),\n    'condition.is_boolean' =\u003e new \\Zahran\\Mapper\\Condition\\IsBoolean(),\n    'condition.is_float' =\u003e new \\Zahran\\Mapper\\Condition\\IsFloat(),\n    'condition.is_double' =\u003e new \\Zahran\\Mapper\\Condition\\IsDouble(),\n    'mutator.multiply' =\u003e new \\Zahran\\Mapper\\Mutator\\Multiply(),\n    'helper.util' =\u003e new \\Zahran\\Mapper\\Helper\\Util(),\n    'factory.cast_type' =\u003e new \\Zahran\\Mapper\\Factory\\CastTypeFactory(),\n    'factory.condition' =\u003e new \\Zahran\\Mapper\\Factory\\ConditionFactory(),\n    'factory.mutator' =\u003e new \\Zahran\\Mapper\\Factory\\MutatorFactory(),\n]);\n$mapper = new \\Zahran\\Mapper\\DataMapper(\n    new \\Zahran\\Mapper\\Factory\\AttributeFactory(),\n    new \\Zahran\\Mapper\\DataModifier()\n);\n$output = $mapper-\u003emap(\n    file_get_contents('./path/to/data.json'),\n    file_get_contents('./path/to/mappings.json')\n);\n```\n\n## Mappings Examples\n\n### 1. Mapping JSON Objects\n\nIn this example, we'll learn how to map simple objects:\n\n#### Original JSON:\n\n```json\n{\n    \"item\": \"Skirt\",\n    \"price\": \"40\"\n}\n```\n\n#### Output:\n\n```json\n{\n    \"ItemName\": \"Skirt\",\n    \"ItemPrice\": \"40\"\n}\n```\n\n#### Mappings:\n\n**NOTE: REMOVE THE COMMENTS BELOW AFTER YOU COPY/PASTE THE MAPPINGS!**\n\nComments below are used for demonstration purposes only. Please remove them before you use the sample!\n\n```json\n{\n    // not necessary at this level\n    \"name\": \"root\",\n    \"attributes\": [\n        {\n            // The name of the new attribute\n            \"name\": \"ItemName\",\n            \"path\": [\n                // The path to the attribute in the source JSON\n                \"item\"\n            ]\n        },\n        {\n            \"name\": \"ItemPrice\",\n            \"path\": [\n                \"price\"\n            ]\n        }\n    ]\n}\n```\n\nInteresting, isn't it? P.S. You don't have to include all attributes of the JSON object. Map the attributes that you\nonly need.\n\n### 2. Mapping JSON Arrays\n\nIn this example, we'll learn how to map a JSON Array `\"items\"` to `\"ItemsArray\"` and rename the `\"name\"` attribute.\n\n#### Original JSON:\n\n```json\n{\n    \"items_count\": \"2\",\n    \"items\": [\n        {\n            \"name\": \"Skirt\",\n            \"price\": 40\n        },\n        {\n            \"name\": \"T-Shirt\",\n            \"price\": 50\n        }\n    ]\n}\n```\n\n#### Output:\n\n```json\n{\n    \"ItemsArray\": [\n        {\n            \"ItemName\": \"Skirt\"\n        },\n        {\n            \"ItemName\": \"T-Shirt\"\n        }\n    ]\n}\n```\n\n#### Mappings:\n\n**NOTE: REMOVE THE COMMENTS BELOW AFTER YOU COPY/PASTE THE MAPPINGS!**\n\nComments below are used for demonstration purposes only. Please remove them before you use the sample!\n\n```json\n{\n    \"name\": \"root\",\n    \"attributes\": [\n        {\n            \"name\": \"ItemsArray\",\n            \"type\": \"array\",\n            // This is required to rewrite JSON Arrays\n            \"path\": [\n                \"items\"\n            ],\n            \"attributes\": [\n                // Defines the elements of the new JSON Array \n                {\n                    \"name\": \"ItemName\",\n                    \"path\": [\n                        \"name\"\n                    ]\n                }\n            ]\n        }\n    ]\n}\n```\n\n### 3. Applying Conditions\n\nWe'll learn how to apply conditions to an attribute. In this example, we'll replace the value of `\"completed\"` to\neither `Completed` or `Pending` based on the original value of the attribute.\n\nA list of supported condition types:\n\n* Contains: `contains`\n* Equals: `eq`\n* Greater Than: `gt`\n* Greater Than or Equals: `gte`\n* Inset: `in`\n* Not Inset: `not_in`\n* Less Than: `lt`\n* Less Than or Equals: `lte`\n* Not Equals: `neq`\n* Not Null: `notnull`\n* Null: `null`\n* Is Boolean: `is_boolean`\n* Is Double: `is_double`\n* Is Float: `is_float`\n* Is Numeric: `is_numeric`\n* Is String: `is_string`\n\n#### Original JSON:\n\n```json\n{\n    \"todos\": [\n        {\n            \"userId\": 1,\n            \"id\": 1,\n            \"title\": \"delectus aut autem\",\n            \"completed\": false\n        },\n        {\n            \"userId\": 1,\n            \"id\": 2,\n            \"title\": \"quis ut nam facilis et officia qui\",\n            \"completed\": true\n        }\n    ]\n}\n```\n\n#### Output:\n\n```json\n{\n    \"ToDo\": [\n        {\n            \"ID\": 1,\n            \"Status\": \"Pending\"\n        },\n        {\n            \"ID\": 2,\n            \"Status\": \"Completed\"\n        }\n    ]\n}\n```\n\n#### Mappings:\n\n**NOTE: REMOVE THE COMMENTS BELOW AFTER YOU COPY/PASTE THE MAPPINGS!**\n\nComments below are used for demonstration purposes only. Please remove them before you use the sample!\n\n```json\n{\n    \"name\": \"root\",\n    \"attributes\": [\n        {\n            \"name\": \"ToDo\",\n            \"type\": \"array\",\n            \"path\": [\n                \"todos\"\n            ],\n            \"attributes\": [\n                {\n                    \"name\": \"ID\",\n                    \"path\": [\n                        \"id\"\n                    ]\n                },\n                {\n                    \"name\": \"Status\",\n                    \"path\": [\n                        \"completed\"\n                    ],\n                    \"conditions\": [\n                        // Defines a list of conditions\n                        {\n                            \"condition_type\": \"eq\",\n                            // the value you're comapring against\n                            \"value\": \"true\",\n                            // the replacement text if condition is true\n                            \"then\": \"Completed\",\n                            // optional\n                            \"otherwise\": \"Pending\"\n                        }\n                    ]\n                }\n            ]\n        }\n    ]\n}\n```\n\n### 4. Cast Values To Another Type\n\nYou can cast values to another type. For example, you may need to change `\"1\"` to become `\"true\"`, or convert a date to\nanother date format.\n\nA list of supported types:\n\n* Boolean: `boolean`\n* Date: `date`\n* Integer: `integer`\n* String: `string`\n* Float: `float`\n\n#### Original JSON:\n\n```json\n{\n    \"notifications\": [\n        {\n            \"email_sent\": 1,\n            \"sent_at\": \"2021-03-26 10:24:51 AM\"\n        },\n        {\n            \"email_sent\": 0,\n            \"sent_at\": \"2021-03-26 10:24:51 AM\"\n        }\n    ]\n}\n```\n\n#### Output:\n\n```json\n{\n    \"notifications\": [\n        {\n            \"email_sent\": true,\n            \"sent_at\": \"March 26, 2021, 10:24 AM\"\n        },\n        {\n            \"email_sent\": false,\n            \"sent_at\": \"March 26, 2021, 10:24 AM\"\n        }\n    ]\n}\n```\n\n#### Mappings:\n\n**NOTE: REMOVE THE COMMENTS BELOW AFTER YOU COPY/PASTE THE MAPPINGS!**\n\nComments below are used for demonstration purposes only. Please remove them before you use the sample!\n\n```json\n{\n    \"name\": \"root\",\n    \"attributes\": [\n        {\n            \"name\": \"notifications\",\n            \"type\": \"array\",\n            \"path\": [\n                \"notifications\"\n            ],\n            \"attributes\": [\n                {\n                    \"name\": \"email_sent\",\n                    \"path\": [\n                        \"email_sent\"\n                    ],\n                    \"cast\": {\n                        \"type\": \"boolean\"\n                    }\n                },\n                {\n                    \"name\": \"sent_at\",\n                    \"path\": [\n                        \"sent_at\"\n                    ],\n                    \"cast\": {\n                        \"type\": \"date\",\n                        // required for cast type \"date\"\n                        \"format\": \"Y-m-d h:i A\"\n                    }\n                }\n            ]\n        }\n    ]\n}\n```\n\n### 5. Applying Mutators\n\nSometimes, you may need to change a value based on some business logic. Mutators allow you to apply custom PHP logic\naround the attribute value. It also gives the ability to use native PHP built-in functions.\n\nA list of supported mutators:\n\n* Arithmetic Multiplication: `multiply`\n* PHP Built-in Functions\n\n#### Original JSON:\n\nIn this example, we are going to convert the title to uppercase and multiply the views by 5.\n\n```json\n{\n    \"articles\": [\n        {\n            \"title\": \"Lorem ipsum dolor sit amet\",\n            \"views\": 10\n        },\n        {\n            \"text\": \"CONSECTETUR adipiscing elit\",\n            \"views\": 15\n        }\n    ]\n}\n```\n\n#### Output:\n\n```json\n{\n    \"articles\": [\n        {\n            \"title\": \"LOREM IPSUM DOLOR SIT AMET\",\n            \"views\": 50\n        },\n        {\n            \"title\": \"CONSECTETUR ADIPISCING ELIT\",\n            \"views\": 75\n        }\n    ]\n}\n```\n\n#### Mappings:\n\n**NOTE: REMOVE THE COMMENTS BELOW AFTER YOU COPY/PASTE THE MAPPINGS!**\n\nComments below are used for demonstration purposes only. Please remove them before you use the sample!\n\n```json\n{\n    \"name\": \"root\",\n    \"attributes\": [\n        {\n            \"name\": \"articles\",\n            \"type\": \"array\",\n            \"path\": [\n                \"articles\"\n            ],\n            \"attributes\": [\n                {\n                    \"name\": \"title\",\n                    \"path\": [\n                        \"title\"\n                    ],\n                    \"mutators\": [\n                        {\n                            \"name\": \"strtoupper\",\n                            \"arguments\": [\n                                // use this magic keyword to pass the original value to the built-in functions\n                                // in our case, the original value must be the first argument of \"strtoupper\"\n                                \"__value__\"\n                            ]\n                        }\n                    ]\n                },\n                {\n                    \"name\": \"views\",\n                    \"path\": [\n                        \"views\"\n                    ],\n                    \"mutators\": [\n                        {\n                            \"name\": \"multiply\",\n                            \"arguments\": [\n                                // the original value times 5\n                                5\n                            ]\n                        }\n                    ]\n                }\n            ]\n        }\n    ]\n}\n```\n\n### 6. Additional Features\n\n#### Default Values\n\nIt's possible to set a default value for an attribute. This can be useful if the path you set doesn't exist, or you want\nto set a default value anyway.\n\n```json\n{\n    \"name\": \"root\",\n    \"attributes\": [\n        {\n            \"name\": \"PersonName\",\n            \"path\": [\n                \"fullname\"\n            ],\n            \"default\": \"John Doe\"\n            // \u003c--- if \"fullname\" doesn't exist in the source data, \"PersonName\" will be set to \"John Doe\"\n        }\n    ]\n}\n```\n\n#### Limiting Array Items\n\nSometimes, you may want to get certain items from an array depending on your use-case. It's possible to define a list of\nindices. Please note that the first index starts with 0. To do so, append an array of indices as a second argument to\nthe `\"path\"` array on the target attribute. Possible ways to limit items:\n\n```json\n    ...\n    \"path\": [\n    \"categories\",\n        [0, 1]\n    ]\n    ...\n\n    ...\n    \"path\": [\n    \"categories\",\n        0 // you can select only on index and get the value as a string or whatever the data type of the source data.\n    ]\n    ...\n```\n\n##### Original JSON:\n\nIn this example, we are going to map all items but limit the categories to the first two items of the array and inject\nsome hard-coded values as the default value for an attribute that's going to be created during runtime.\n\n```json\n{\n    \"articles\": [\n        {\n            \"title\": \"Lorem ipsum dolor sit amet\",\n            \"categories\": [\n                10,\n                55,\n                3,\n                20\n            ]\n        }\n    ]\n}\n```\n\n##### Output:\n\n```json\n{\n    \"articles\": [\n        {\n            \"title\": \"Lorem ipsum dolor sit amet\",\n            \"categories\": [\n                10,\n                55\n            ]\n        }\n    ]\n}\n```\n\n##### Mappings:\n\n**NOTE: REMOVE THE COMMENTS BELOW AFTER YOU COPY/PASTE THE MAPPINGS!**\n\nComments below are used for demonstration purposes only. Please remove them before you use the sample!\n\n```json\n{\n    \"name\": \"root\",\n    \"attributes\": [\n        {\n            \"name\": \"articles\",\n            \"type\": \"array\",\n            \"path\": [\n                \"articles\"\n            ],\n            \"attributes\": [\n                {\n                    \"name\": \"title\",\n                    \"path\": [\n                        \"title\"\n                    ]\n                },\n                {\n                    \"name\": \"categories\",\n                    \"path\": [\n                        \"categories\",\n                        [\n                            0,\n                            1\n                        ]\n                    ]\n                }\n            ]\n        }\n    ]\n}\n\n```\n\n### Appending Values On Limiting Array Items\nIn the example, above we learnt how to get certain items from an array using indices, but you may have a case where you \nwant to append a value at the end of the list.\nThis is can be done this way:\n```json\n    ...\n    {\n        \"name\": \"categories\",\n        \"path\": [\n            \"categories\",\n            [\n                0,\n                1,\n                \"$foo\", // the output will be: \"foo\"\n                \"$bar\", // the output will be: \"bar\"\n                \"$100.5\", // the output will be: 100.5\n                \"$100\", // the output will be: 100\n                \"$true\", // the output will be: true\n                \"$false\", // the output will be: false\n                \"$null\" // the output will be: \"null\"\n            ]\n        ]\n    }\n    ...\n```\n\n## Notes On The Mappings\n\nYou should now be aware of how Mappings are built. Nevertheless, I feel that you may need to bear these things in mind\nwhile building yours.\n\n* You shouldn't add any modifiers (Cast type, conditions or mutators) to an attribute of type `array` because they won't\n  be effective. Instead, add modifiers to the attributes that sit under that JSON array - AKA Nested Attributes.\n\n```json\n{\n    \"name\": \"articles\",\n    \"type\": \"array\",\n    // \u003c--- JSON Array\n    \"path\": [\n        \"articles\"\n    ],\n    // don't add \"conditions\", \"cast_type\" or \"mutators\" here. they won't be effective.\n    \"attributes\": [\n        {\n            \"name\": \"title\",\n            \"path\": [\n                \"title\"\n            ]\n            // add them here instead, so they get applied to the \"title\" attribute.\n        }\n    ]\n}\n```\n\n## Extending The Package\n\nThe package is built to be extensible to allow you to add custom cast types, conditions and/or mutators. Moreover, you\ncan retire any of the core classes, just make sure you're implementing the right interface.\n\n### Custom Cast Type\n\n1. You'll need to implement `\\Zahran\\Mapper\\Contract\\CastType`. It has two public methods: `setModel` and `cast`. Create\n   the new Cast Type you want and follow the example below:\n\n```php\n\u003c?php\n\nnamespace Your\\Vendor\\Name;\n\nuse Zahran\\Mapper\\Contract\\CastType as CastTypeInterface;\nuse Zahran\\Mapper\\Model\\CastType;\n\nclass MyCustomCastType implements CastTypeInterface\n{\n    /**\n     * @var CastType\n     */\n    protected $model;\n\n    public function setModel(CastType $model): CastTypeInterface\n    {\n        $this-\u003emodel = $model;\n        return $this;\n    }\n\n    public function cast($originalValue): bool\n    {\n        // implement your logic here.\n    }\n}\n```\n\n2. Add your custom cast type to the Container. Replace `{type}` with the name you want to use in the mappings (i.e.\n   custom). You can replace a core class by overriding the id. For example, if you want to replace\n   class `\\Zahran\\Mapper\\CastType\\Boolean` with your own version, you'll need to register your custom implementation\n   under `cast_type.boolean`.\n\n```php\n\u003c?php\n\n\\Zahran\\Mapper\\Container::getInstance()-\u003eadd(\n    'cast_type.{type}', \n    new \\Your\\Vendor\\Name\\MyCustomCastType()\n);\n```\n\n### Add Custom Condition\n\n1. You'll need to implement `\\Zahran\\Mapper\\Contract\\Condition`. It has two public methods: `setModel` and `apply`.\n   Create the new Condition you want and follow the example below:\n\n```php\n\u003c?php\n\nnamespace Your\\Vendor\\Name;\n\nuse Zahran\\Mapper\\Contract\\Condition as ConditionInterface;\nuse Zahran\\Mapper\\Model\\Condition;\n\nclass MyCustomCondition implements ConditionInterface\n{\n    /**\n     * @var Condition\n     */\n    protected $model;\n\n    public function setModel(Condition $model): ConditionInterface\n    {\n        $this-\u003emodel = $model;\n        return $this;\n    }\n\n    public function apply($originalValue)\n    {\n        // use $originalValue to compare against it anything you want.\n        // use $this-\u003emodel-\u003egetThen() to get the return value if the condition is true.\n        // use $this-\u003emodel-\u003egetOtherwise() to get the return value if the condition is false.\n    }\n}\n\n```\n\n2. Add your custom condition to the Container. Replace `{condition_type}` with the name you want to use in the\n   mappings (i.e. custom). You can replace a core class by overriding the id. For example, if you want to replace\n   class `\\Zahran\\Mapper\\Condition\\Equals` with your own version, you'll need to register your custom implementation\n   under `condition.eq`.\n\n```php\n\u003c?php\n\n\\Zahran\\Mapper\\Container::getInstance()-\u003eadd(\n    'condition.{condition_type}', \n    new \\Your\\Vendor\\Name\\MyCustomCondition()\n);\n```\n\n### Add Custom Mutator\n\n1. You'll need to implement `\\Zahran\\Mapper\\Contract\\Condition`. It has two public methods: `setModel` and `apply`.\n   Create the new Condition you want and follow the example below:\n\n```php\n\u003c?php\n\nnamespace Your\\Vendor\\Name;\n\nuse Zahran\\Mapper\\Contract\\Mutator as MutatorInterface;\nuse Zahran\\Mapper\\Model\\Mutator;\n\nclass Multiply implements MutatorInterface\n{\n    /**\n     * @var Mutator\n     */\n    protected $model;\n\n    public function setModel(Mutator $model): MutatorInterface\n    {\n        $this-\u003emodel = $model;\n        return $this;\n    }\n\n    public function apply($originalValue, array $arguments = [])\n    {\n        // add your logic here\n    }\n}\n\n\n```\n\n2. Add your custom mutator to the Container. Replace `{name}` with the name you want to use in the mappings (i.e.\n   custom). You can replace a core class by overriding the id. For example, if you want to replace\n   class `\\Zahran\\Mapper\\Mutator\\Multiply` with your own version, you'll need to register your custom implementation\n   under `mutator.multiple`.\n\n```php\n\u003c?php\n\n\\Zahran\\Mapper\\Container::getInstance()-\u003eadd(\n    'mutator.{name}', \n    new \\Your\\Vendor\\Name\\MyCustomMutator()\n);\n```\n\n## Contributing\n\nAll changes that makes the Mapper more accurate is always highly appreciated and welcome.\n\n## License\n\nThe JSON Mapper is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozahran%2Fdata-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmozahran%2Fdata-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozahran%2Fdata-mapper/lists"}