@@ -100,24 +100,7 @@ protected function _setDataValues($dataObject, array $data, $interfaceName)
100
100
if (empty ($ data )) {
101
101
return $ this ;
102
102
}
103
- $ dataObjectMethods = get_class_methods (get_class ($ dataObject ));
104
-
105
- $ setMethods = array_filter ($ dataObjectMethods , static function ($ e ) {
106
- return 0 === strncmp ($ e , 'set ' , 3 );
107
- });
108
- $ setMethods = array_map (static function ($ e ) {
109
- return SimpleDataObjectConverter::camelCaseToSnakeCase (substr ($ e , 3 ));
110
- }, $ setMethods );
111
- $ setMethods = array_merge (
112
- $ setMethods ,
113
- array_map (
114
- function ($ e ) {
115
- return str_replace ('is_ ' , '' , $ e );
116
- },
117
- $ setMethods
118
- )
119
- );
120
- $ setMethods = array_flip ($ setMethods );
103
+ $ setMethods = $ this ->getSetters ($ dataObject );
121
104
if ($ dataObject instanceof ExtensibleDataInterface
122
105
&& !empty ($ data [CustomAttributesDataInterface::CUSTOM_ATTRIBUTES ])
123
106
) {
@@ -148,7 +131,7 @@ function ($e) {
148
131
$ methodName = SimpleDataObjectConverter::snakeCaseToUpperCamelCase ($ key );
149
132
150
133
if (!is_array ($ value )) {
151
- if ($ methodName !== 'setExtensionAttributes ' || $ value !== null ) {
134
+ if ($ methodName !== 'ExtensionAttributes ' || $ value !== null ) {
152
135
if (method_exists ($ dataObject , 'set ' . $ methodName )) {
153
136
$ dataObject ->{'set ' . $ methodName }($ value );
154
137
} else {
@@ -295,4 +278,38 @@ public function getCustomAttributeValueByType(array $attributeValues, $type)
295
278
}
296
279
return $ attributeValueArray ;
297
280
}
281
+
282
+ /** @var array */
283
+ private $ settersCache = [];
284
+
285
+ /**
286
+ * Get list of setters for object
287
+ *
288
+ * @param object $dataObject
289
+ * @return array
290
+ */
291
+ private function getSetters (object $ dataObject ): array
292
+ {
293
+ $ class = get_class ($ dataObject );
294
+ if (!isset ($ this ->settersCache [$ class ])) {
295
+ $ dataObjectMethods = get_class_methods ($ class );
296
+ // use regexp to manipulate with method list as it use jit starting with PHP 7.3
297
+ $ setters = explode (
298
+ ', ' ,
299
+ strtolower (
300
+ // (0) remove all not setter
301
+ // (1) add _ before upper letter
302
+ // (2) remove set_ in start of name
303
+ // (3) add name without is_ prefix
304
+ preg_replace (
305
+ ['/(^|,)(?!set)[^,]*/S ' ,'/(.)([A-Z])/S ' , '/(^|,)set_/iS ' , '/(^|,)is_([^,]+)/is ' ],
306
+ ['' , '$1_$2 ' , '$1 ' , '$1$2,is_$2 ' ],
307
+ implode (', ' , $ dataObjectMethods )
308
+ )
309
+ )
310
+ );
311
+ $ this ->settersCache [$ class ] = array_flip ($ setters );
312
+ }
313
+ return $ this ->settersCache [$ class ];
314
+ }
298
315
}
0 commit comments