Skip to content
This repository was archived by the owner on Aug 18, 2023. It is now read-only.

Commit 3da6d90

Browse files
authored
Merge pull request #33 from kamil-klasicki/202010_fix_camelcasing
202010 fix camelcasing issue inside Profile Model
2 parents 2f53894 + 20f4883 commit 3da6d90

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
## CHANGELOG
22

3+
### 2.2.3
4+
- Fix - ProfileModel file to convert specialAttributes properties to camel case before executing property_exists method inside jsonSerialize
5+
36
### 2.2.2
47
- Fix - KlaviyoAPI file to handle json_decode correctly when empty string is returned
5-
- Fix - Fix EventModel unix timestamp issue
8+
- Fix - Fix EventModel unix timestamp issue
69
- Update - Add all Klaviyo special properties
710

811
### 2.2.1
@@ -26,4 +29,4 @@
2629
- There is no compatibility on migrating from 1.* to 2.* and will need to follow the new 2.0.0 pattern
2730

2831
### 1.0
29-
- As this changelog was created after 2.0.0, please refer to the README for version 1 https://github.com/klaviyo/php-klaviyo/tree/d388ca998dff55b2a7e420c2c7aa2cd221365d1c
32+
- As this changelog was created after 2.0.0, please refer to the README for version 1 https://github.com/klaviyo/php-klaviyo/tree/d388ca998dff55b2a7e420c2c7aa2cd221365d1c

src/Klaviyo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Klaviyo
2121
/**
2222
* @var string
2323
*/
24-
const VERSION = '2.2.2';
24+
const VERSION = '2.2.3';
2525

2626
/**
2727
* Constructor for Klaviyo.

src/Model/ProfileModel.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public function __construct( array $configuration ) {
9797
protected function setAttributes(array $configuration ) {
9898
foreach ( $configuration as $key => $value ) {
9999
if ( $this->isSpecialAttribute($key) ) {
100-
$this->{lcfirst(str_replace('_', '', ucwords(ltrim($key, '$'), '_')))} = $value;
100+
$this->{$this->convertToCamelCase($key)} = $value;
101101
}
102-
102+
103103
}
104104

105105
$this->setCustomAttributes( $configuration );
@@ -150,14 +150,25 @@ public function getCustomAttributes() {
150150
return $this->customAttributes;
151151
}
152152

153+
/**
154+
* The Special attributes array is using snake case, while class properties are camelCased.
155+
* This means that variables such as first_name or last_name won't exist on the class object and will
156+
* simply be missed inside jsonSerialize method. To accomodate for that, we convert all the keys to camelCase before running the comparison.
157+
*
158+
* @return string
159+
*/
160+
public function convertToCamelCase($key) {
161+
return lcfirst(str_replace('_', '', ucwords(ltrim($key, '$'), '_')));
162+
}
163+
153164
public function jsonSerialize() {
154165
$properties = array_fill_keys($this::$specialAttributes, null);
155166
foreach ($properties as $key => &$value) {
156-
if (!property_exists($this, substr($key, 1))) {
167+
if (!property_exists($this, $this->convertToCamelCase($key))) {
157168
continue;
158169
}
159170

160-
$value = $this->{substr($key, 1)};
171+
$value = $this->{$this->convertToCamelCase($key)};
161172
}
162173

163174
unset($properties['$email']);

0 commit comments

Comments
 (0)