{"id":19893072,"url":"https://github.com/alaugks/article-php-attribute-emarsys-example","last_synced_at":"2026-05-10T13:56:49.814Z","repository":{"id":175605410,"uuid":"617119080","full_name":"alaugks/article-php-attribute-emarsys-example","owner":"alaugks","description":"Mapping FieldValueIDs for the payload of the Emarsys API Series","archived":false,"fork":false,"pushed_at":"2023-11-12T14:09:29.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T19:44:57.605Z","etag":null,"topics":["annotations","attribute","denormalization","emarsys","emarsys-api","normalization","php8"],"latest_commit_sha":null,"homepage":"https://dev.to/alaugks/series/22911","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/alaugks.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,"governance":null}},"created_at":"2023-03-21T18:30:14.000Z","updated_at":"2024-09-09T11:00:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"2669a18c-1782-475e-a221-95f6698c8f46","html_url":"https://github.com/alaugks/article-php-attribute-emarsys-example","commit_stats":null,"previous_names":["alaugks/article-php-attribute-emarsys-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaugks%2Farticle-php-attribute-emarsys-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaugks%2Farticle-php-attribute-emarsys-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaugks%2Farticle-php-attribute-emarsys-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaugks%2Farticle-php-attribute-emarsys-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alaugks","download_url":"https://codeload.github.com/alaugks/article-php-attribute-emarsys-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241321810,"owners_count":19944021,"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":["annotations","attribute","denormalization","emarsys","emarsys-api","normalization","php8"],"created_at":"2024-11-12T18:27:18.093Z","updated_at":"2026-05-10T13:56:49.768Z","avatar_url":"https://github.com/alaugks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom attribute example for PHP8.x.\n\nExample of a custom attribute for the article [Create a custom Symfony Normalizer for mapping values](https://dev.to/elevado/create-a-custom-symfony-normalizer-for-mapping-values-4nc2).\n\n## Docker image\n\n### Start docker image\n```bash\ndocker compose -f docker-compose.yml up --build -d\n```\n\n### Run composer install\n```bash\ndocker exec attribute_article composer install\n```\n\n### Run tests\n```bash\ndocker exec attribute_article vendor/bin/phpunit\n```\n\n## Example\n\n### Create a contact\n```php\nuse Snowcap\\Emarsys\\Client;\nuse Snowcap\\Emarsys\\CurlClient;\n\n$httpClient = new CurlClient();\n$client = new Client($httpClient, EMARSYS_API_USERNAME, EMARSYS_API_SECRET);\n\nclass ContactDto\n{\n    #[Emarsys(id: '1')]\n    private ?string $firstname = null;\n\n    #[Emarsys(id: '2')]\n    private ?string $lastname = null;\n\n    #[Emarsys(id: '3')]\n    private ?string $email = null;\n\n    #[Emarsys(id: '46', type: Emarsys::TYPE_SINGLE_CHOICES, mapping: ['1' =\u003e 'MALE', '2' =\u003e 'FEMALE', '6' =\u003e 'DIVERS'])]\n    private ?string $salutation = null;\n\n    #[Emarsys(id: '100674', type: Emarsys::TYPE_SINGLE_CHOICES, mapping: ['1' =\u003e true, '2' =\u003e false])]\n    private ?bool $marketingInformation = null;\n\n    /* getter and setter */\n}\n\n$contactDto-\u003esetSalutation('FEMALE');\n$contactDto-\u003esetFirstname('Jane');\n$contactDto-\u003esetEmail('jane.doe@example.com');\n$contactDto-\u003esetMarketingInformation(true);\n\n// Request handling: Create request\n$crmMappingService = new CrmMappingService();\n$fields = $crmMappingService-\u003enormalize($contactDto);\n/*\n    [\n        \"1\" =\u003e \"Jane\",\n        \"2\" =\u003e \"Doe\",\n        \"3\" =\u003e \"jane.doe@example.com\",\n        \"46\" =\u003e \"2\",\n        \"100674\" =\u003e \"1\"\n    ]\n*/\n$client-\u003ecreateContact($fields);\n```\n\n### Find a contact\n```php\nuse Snowcap\\Emarsys\\Client;\nuse Snowcap\\Emarsys\\CurlClient;\n\n$httpClient = new CurlClient();\n$client = new Client($httpClient, EMARSYS_API_USERNAME, EMARSYS_API_SECRET);\n\n$response = $client-\u003egetContactData([3 =\u003e 'example@example.com']);\n$fields = $response-\u003egetData();\n/*\n    [\n        \"1\" =\u003e \"Jane\",\n        \"2\" =\u003e \"Doe\",\n        \"3\" =\u003e \"jane.doe@example.com\",\n        \"46\" =\u003e \"2\",\n        \"100674\" =\u003e \"1\"\n    ]\n*/\n\n$crmMappingService = new CrmMappingService();\n$contactDto = $crmMappingService-\u003edenormalize($fields, new ContactDto());\n/*\n    App\\Dto\\ContactDto Object\n    (\n        [firstname:App\\Dto\\ContactDto:private] =\u003e Jane\n        [lastname:App\\Dto\\ContactDto:private] =\u003e Doe\n        [email:App\\Dto\\ContactDto:private] =\u003e jane.doe@example.com\n        [salutation:App\\Dto\\ContactDto:private] =\u003e FEMALE\n        [marketingInformation:App\\Dto\\ContactDto:private] =\u003e 1\n    )\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falaugks%2Farticle-php-attribute-emarsys-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falaugks%2Farticle-php-attribute-emarsys-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falaugks%2Farticle-php-attribute-emarsys-example/lists"}