Skip to content

Commit 6d00eaa

Browse files
Merge remote-tracking branch '36345/patch-6' into comm_jul
2 parents 61182f5 + a4ea151 commit 6d00eaa

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

app/code/Magento/Paypal/Model/Payflow/Request.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Request extends \Magento\Framework\DataObject
1414
{
1515
/**
1616
* Set/Get attribute wrapper
17+
*
1718
* Also add length path if key contains = or &
1819
*
1920
* @param string $method
@@ -24,7 +25,7 @@ class Request extends \Magento\Framework\DataObject
2425
*/
2526
public function __call($method, $args)
2627
{
27-
$key = $this->_underscore(substr($method, 3));
28+
$key = $this->_underscore($method);
2829
if (isset($args[0]) && (strstr($args[0], '=') || strstr($args[0], '&'))) {
2930
$key .= '[' . strlen($args[0]) . ']';
3031
}

lib/internal/Magento/Framework/DataObject.php

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -387,22 +387,37 @@ public function toString($format = '')
387387
*/
388388
public function __call($method, $args)
389389
{
390-
switch (substr((string)$method, 0, 3)) {
390+
// Compare 3 first letters of the method name
391+
switch ($method[0] . ($method[1] ?? '') . ($method[2] ?? '')) {
391392
case 'get':
392-
$key = $this->_underscore(substr($method, 3));
393-
$index = isset($args[0]) ? $args[0] : null;
394-
return $this->getData($key, $index);
393+
if (isset($args[0]) && $args[0] !== null) {
394+
return $this->getData(
395+
self::$_underscoreCache[$method] ?? $this->_underscore($method),
396+
$args[0]
397+
);
398+
}
399+
400+
return $this->getData(
401+
self::$_underscoreCache[$method] ?? $this->_underscore($method),
402+
$args[0] ?? null
403+
);
395404
case 'set':
396-
$key = $this->_underscore(substr($method, 3));
397-
$value = isset($args[0]) ? $args[0] : null;
398-
return $this->setData($key, $value);
405+
return $this->setData(
406+
self::$_underscoreCache[$method] ?? $this->_underscore($method),
407+
$args[0] ?? null
408+
);
399409
case 'uns':
400-
$key = $this->_underscore(substr($method, 3));
401-
return $this->unsetData($key);
410+
return $this->unsetData(
411+
self::$_underscoreCache[$method] ?? $this->_underscore($method)
412+
);
402413
case 'has':
403-
$key = $this->_underscore(substr($method, 3));
404-
return isset($this->_data[$key]);
414+
return isset(
415+
$this->_data[
416+
self::$_underscoreCache[$method] ?? $this->_underscore($method)
417+
]
418+
);
405419
}
420+
406421
throw new \Magento\Framework\Exception\LocalizedException(
407422
new \Magento\Framework\Phrase('Invalid method %1::%2', [get_class($this), $method])
408423
);
@@ -435,7 +450,23 @@ protected function _underscore($name)
435450
if (isset(self::$_underscoreCache[$name])) {
436451
return self::$_underscoreCache[$name];
437452
}
438-
$result = strtolower(trim(preg_replace('/([A-Z]|[0-9]+)/', "_$1", $name), '_'));
453+
454+
$result = strtolower(
455+
trim(
456+
preg_replace(
457+
'/([A-Z]|[0-9]+)/',
458+
"_$1",
459+
lcfirst(
460+
substr(
461+
$name,
462+
3
463+
)
464+
)
465+
),
466+
'_'
467+
)
468+
);
469+
439470
self::$_underscoreCache[$name] = $result;
440471
return $result;
441472
}

lib/internal/Magento/Framework/Test/Unit/DataObjectTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,13 @@ public function testUnderscore($input, $expectedOutput)
396396
public function underscoreDataProvider()
397397
{
398398
return [
399-
'Test 1' => ['Stone1Color', 'stone_1_color'],
400-
'Test 2' => ['StoneColor', 'stone_color'],
401-
'Test 3' => ['StoneToXml', 'stone_to_xml'],
402-
'Test 4' => ['1StoneColor', '1_stone_color'],
403-
'Test 5' => ['getCcLast4', 'get_cc_last_4'],
404-
'Test 6' => ['99Bottles', '99_bottles'],
405-
'Test 7' => ['XApiLogin', 'x_api_login']
399+
'Test 1' => ['GetStone1Color', 'stone_1_color'],
400+
'Test 2' => ['SetStoneColor', 'stone_color'],
401+
'Test 3' => ['GetStoneToXml', 'stone_to_xml'],
402+
'Test 4' => ['Set1StoneColor', '1_stone_color'],
403+
'Test 5' => ['GetgetCcLast4', 'get_cc_last_4'],
404+
'Test 6' => ['Set99Bottles', '99_bottles'],
405+
'Test 7' => ['GetXApiLogin', 'x_api_login']
406406
];
407407
}
408408
}

0 commit comments

Comments
 (0)