Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alaugks/article-php-attribute-emarsys-example
Mapping FieldValueIDs for the payload of the Emarsys API Series
https://github.com/alaugks/article-php-attribute-emarsys-example
annotations attribute emarsys php8
Last synced: about 1 month ago
JSON representation
Mapping FieldValueIDs for the payload of the Emarsys API Series
- Host: GitHub
- URL: https://github.com/alaugks/article-php-attribute-emarsys-example
- Owner: alaugks
- Created: 2023-03-21T18:30:14.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-12T14:09:29.000Z (about 1 year ago)
- Last Synced: 2024-04-08T07:10:16.763Z (9 months ago)
- Topics: annotations, attribute, emarsys, php8
- Language: PHP
- Homepage: https://dev.to/elevado/series/22911
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Custom attribute example for PHP8.x.
Example 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).
## Docker image
### Start docker image
```bash
docker compose -f docker-compose.yml up --build -d
```### Run composer install
```bash
docker exec attribute_article composer install
```### Run tests
```bash
docker exec attribute_article vendor/bin/phpunit
```## Example
### Create a contact
```php
use Snowcap\Emarsys\Client;
use Snowcap\Emarsys\CurlClient;$httpClient = new CurlClient();
$client = new Client($httpClient, EMARSYS_API_USERNAME, EMARSYS_API_SECRET);class ContactDto
{
#[Emarsys(id: '1')]
private ?string $firstname = null;#[Emarsys(id: '2')]
private ?string $lastname = null;#[Emarsys(id: '3')]
private ?string $email = null;#[Emarsys(id: '46', type: Emarsys::TYPE_SINGLE_CHOICES, mapping: ['1' => 'MALE', '2' => 'FEMALE', '6' => 'DIVERS'])]
private ?string $salutation = null;#[Emarsys(id: '100674', type: Emarsys::TYPE_SINGLE_CHOICES, mapping: ['1' => true, '2' => false])]
private ?bool $marketingInformation = null;/* getter and setter */
}$contactDto->setSalutation('FEMALE');
$contactDto->setFirstname('Jane');
$contactDto->setEmail('[email protected]');
$contactDto->setMarketingInformation(true);// Request handling: Create request
$crmMappingService = new CrmMappingService();
$fields = $crmMappingService->normalize($contactDto);
/*
[
"1" => "Jane",
"2" => "Doe",
"3" => "[email protected]",
"46" => "2",
"100674" => "1"
]
*/
$client->createContact($fields);
```### Find a contact
```php
use Snowcap\Emarsys\Client;
use Snowcap\Emarsys\CurlClient;$httpClient = new CurlClient();
$client = new Client($httpClient, EMARSYS_API_USERNAME, EMARSYS_API_SECRET);$response = $client->getContactData([3 => '[email protected]']);
$fields = $response->getData();
/*
[
"1" => "Jane",
"2" => "Doe",
"3" => "[email protected]",
"46" => "2",
"100674" => "1"
]
*/$crmMappingService = new CrmMappingService();
$contactDto = $crmMappingService->denormalize($fields, new ContactDto());
/*
App\Dto\ContactDto Object
(
[firstname:App\Dto\ContactDto:private] => Jane
[lastname:App\Dto\ContactDto:private] => Doe
[email:App\Dto\ContactDto:private] => [email protected]
[salutation:App\Dto\ContactDto:private] => FEMALE
[marketingInformation:App\Dto\ContactDto:private] => 1
)
*/
```