From d1dce43e775ce51bbdd52b0d26a6cf160a118ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 26 Oct 2021 10:06:49 +0200 Subject: [PATCH 1/4] add some comment on customer --- src/Models/Customer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Models/Customer.php b/src/Models/Customer.php index a9f3dca..eaacf6f 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -14,6 +14,11 @@ use TypeError; * the account validation status. You can use it as * a standalone class but beware of catching exceptions * + * Be warned that on server side data is normalized + * - firstname and lastname are 'capitalized' + * - fields are trimmed + * - non numeric chars are removed from postcode + * * @property string $hashcode The crm hashcode this is a readonly field * @property string $email Must be a rfc valid email on a valid domain name * @property string $password Required only on create, must have upper and lowers chars, From d8786e0b436f203eac404a338e00514318d344a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 26 Oct 2021 10:26:20 +0200 Subject: [PATCH 2/4] Force bool cast when reponse is 0 or 1 --- src/Models/CrmClientModel.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Models/CrmClientModel.php b/src/Models/CrmClientModel.php index 7235a01..1db71e6 100644 --- a/src/Models/CrmClientModel.php +++ b/src/Models/CrmClientModel.php @@ -124,6 +124,10 @@ abstract class CrmClientModel implements JsonSerializable if (count($properties)) { foreach ($properties as $field => $value) { $type = $this->getPropType($field); + // Force boolean + if ($type === 'bool') { + $value = \is_int($value) and ($value === 1 or $value === 0) ? (bool)$value : $value; + } if (!$this->checkFieldType($type, $value)) { throw new TypeError("Wrong type for $field"); } From 2059e0ef0562b49ebba70b4dd9de19c268eb27fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 26 Oct 2021 12:36:10 +0200 Subject: [PATCH 3/4] Fill data props after save or update on Customer --- src/Models/CrmClientModel.php | 2 +- src/Models/Customer.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Models/CrmClientModel.php b/src/Models/CrmClientModel.php index 1db71e6..fe416ed 100644 --- a/src/Models/CrmClientModel.php +++ b/src/Models/CrmClientModel.php @@ -126,7 +126,7 @@ abstract class CrmClientModel implements JsonSerializable $type = $this->getPropType($field); // Force boolean if ($type === 'bool') { - $value = \is_int($value) and ($value === 1 or $value === 0) ? (bool)$value : $value; + $value = (\is_int($value) and ($value === 1 or $value === 0)) ? (bool)$value : $value; } if (!$this->checkFieldType($type, $value)) { throw new TypeError("Wrong type for $field"); diff --git a/src/Models/Customer.php b/src/Models/Customer.php index eaacf6f..1f6c07a 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -458,7 +458,7 @@ class Customer extends CrmClientModel $response = static::$apiInterface->call($request); if ($status = $response->status->equals(ApiStatus::OK())) { $this->updatedValues = []; - $this->hashcode = $response->data['hashcode']; + $this->fill($response->data); } return $status; } @@ -474,6 +474,7 @@ class Customer extends CrmClientModel $response = static::$apiInterface->call($request); if ($status = $response->status->equals(ApiStatus::OK())) { $this->updatedValues = []; + $this->fill($response->data); } return $status; } @@ -517,7 +518,7 @@ class Customer extends CrmClientModel ]); $response = static::$apiInterface->call($request); - $this->status = true; + $this->__set('status', true); return $response->status->equals(ApiStatus::OK()); } @@ -532,7 +533,7 @@ class Customer extends CrmClientModel */ public function toggleOptin(): bool { - $this->opt_in = !$this->opt_in; + $this->__set('opt_in', !$this->opt_in); return $this->update(); } From 390033d3da4b5f9447410656f3d23787557588b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 26 Oct 2021 12:50:09 +0200 Subject: [PATCH 4/4] generate version and update changelog bump to 2.2.3 --- apiConfig.readonly.json | 2 +- changelog.md | 4 ++++ composer.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apiConfig.readonly.json b/apiConfig.readonly.json index a844780..3a27873 100644 --- a/apiConfig.readonly.json +++ b/apiConfig.readonly.json @@ -1,5 +1,5 @@ { - "version": "2.2.1", + "version": "2.2.3", "tokenTimeout": 60, "apiRequestRatePerMinute": 256, "servicesDBCache": 10 diff --git a/changelog.md b/changelog.md index 6308f01..8595abe 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ #All notable changes to `CRM CLient V2` will be documented in this file. +# version 2.2.3 +- Changed for bool casting for response parse field 'status' when is int 1 or 0 +- Changed, properties are filled from CRM after a save or update action, this will allow for props to be set on model as it is on the crm, after all checks and casts (firstname capitalized, ... etc) + # version 2.2.2 - Fixed Arcadia mail where sending parameters as query instead of Data diff --git a/composer.json b/composer.json index 9369579..a45c696 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "LDC CRM Client V2", "license": "MIT", - "version": "2.2.2", + "version": "2.2.3", "authors": [ { "name": "Jérémy Munsch",