Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b6fbaeb
Improve performance of DataObject magic calls and addData()
igorwulff Oct 21, 2022
8d74dcd
Update DataObject.php
igorwulff Oct 21, 2022
f925945
Reverted back the way magic __call method types (set, get, etc...) ar…
igorwulff Oct 21, 2022
01c8d00
Fix issues with magic __call 'get' calls in certain conditions
igorwulff Oct 25, 2022
de09c40
Merge branch '2.4-develop' into patch-6
ihor-sviziev Oct 26, 2022
71cb333
Regression fixes to __call method dataobject
igorwulff Nov 1, 2022
fe19f5b
Merge branch '2.4-develop' into patch-6
igorwulff Nov 1, 2022
252ce2a
Update DataObjectTest.php
igorwulff Nov 1, 2022
1def672
Fix for missing + sign in preg_replace in _underscore call
igorwulff Nov 1, 2022
3deeaa1
phpstan issues for dataobject.php changes
igorwulff Nov 2, 2022
78fe7e7
Further changes to fix unit tests and keep things backwards compatible.
igorwulff Nov 4, 2022
cc12a55
Regression fix from unit tests for __call method
igorwulff Nov 8, 2022
3e494de
Merge branch '2.4-develop' into patch-6
igorwulff Nov 8, 2022
c02716c
Fix setData function calls due to dependencies
igorwulff Dec 6, 2022
780f6b6
Merge branch '2.4-develop' into patch-6
ihor-sviziev Apr 16, 2023
91e1cf1
Improve performance of DataObject magic calls and addData
ihor-sviziev Apr 18, 2023
e0bdc36
Improve performance of DataObject magic calls and addData
ihor-sviziev Apr 18, 2023
a927888
Merge branch '2.4-develop' into patch-6
ihor-sviziev Apr 18, 2023
3ebe7af
Merge branch '2.4-develop' into patch-6
engcom-Hotel Jun 13, 2023
934142a
Merge branch '2.4-develop' into patch-6
engcom-Hotel Jun 14, 2023
882d3de
Fix Integration test failure for testSuccessfulNotification test
glo24157 Jun 14, 2023
831616d
Add enter in docblock to fix phpcs error
igorwulff Jun 14, 2023
c838ed1
Resolve B2B integration tests failures
glo24157 Jun 17, 2023
17a7c00
Fix Static tests failures
glo24157 Jun 19, 2023
6ab506a
Merge branch '2.4-develop' into patch-6
igorwulff Jun 28, 2023
7462468
Merge branch '2.4-develop' into patch-6
engcom-Hotel Jul 12, 2023
a4ea151
Merge branch '2.4-develop' into patch-6
engcom-Hotel Aug 25, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/code/Magento/Paypal/Model/Payflow/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Request extends \Magento\Framework\DataObject
{
/**
* Set/Get attribute wrapper
*
* Also add length path if key contains = or &
*
* @param string $method
Expand All @@ -24,7 +25,7 @@ class Request extends \Magento\Framework\DataObject
*/
public function __call($method, $args)
{
$key = $this->_underscore(substr($method, 3));
$key = $this->_underscore($method);
if (isset($args[0]) && (strstr($args[0], '=') || strstr($args[0], '&'))) {
$key .= '[' . strlen($args[0]) . ']';
}
Expand Down
55 changes: 43 additions & 12 deletions lib/internal/Magento/Framework/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,37 @@ public function toString($format = '')
*/
public function __call($method, $args)
{
switch (substr((string)$method, 0, 3)) {
// Compare 3 first letters of the method name
switch ($method[0] . ($method[1] ?? '') . ($method[2] ?? '')) {
case 'get':
$key = $this->_underscore(substr($method, 3));
$index = isset($args[0]) ? $args[0] : null;
return $this->getData($key, $index);
if (isset($args[0]) && $args[0] !== null) {
return $this->getData(
self::$_underscoreCache[$method] ?? $this->_underscore($method),
$args[0]
);
}

return $this->getData(
self::$_underscoreCache[$method] ?? $this->_underscore($method),
$args[0] ?? null
);
case 'set':
$key = $this->_underscore(substr($method, 3));
$value = isset($args[0]) ? $args[0] : null;
return $this->setData($key, $value);
return $this->setData(
self::$_underscoreCache[$method] ?? $this->_underscore($method),
$args[0] ?? null
);
case 'uns':
$key = $this->_underscore(substr($method, 3));
return $this->unsetData($key);
return $this->unsetData(
self::$_underscoreCache[$method] ?? $this->_underscore($method)
);
case 'has':
$key = $this->_underscore(substr($method, 3));
return isset($this->_data[$key]);
return isset(
$this->_data[
self::$_underscoreCache[$method] ?? $this->_underscore($method)
]
);
}

throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('Invalid method %1::%2', [get_class($this), $method])
);
Expand Down Expand Up @@ -435,7 +450,23 @@ protected function _underscore($name)
if (isset(self::$_underscoreCache[$name])) {
return self::$_underscoreCache[$name];
}
$result = strtolower(trim(preg_replace('/([A-Z]|[0-9]+)/', "_$1", $name), '_'));

$result = strtolower(
trim(
preg_replace(
'/([A-Z]|[0-9]+)/',
"_$1",
lcfirst(
substr(
$name,
3
)
)
),
'_'
)
);

self::$_underscoreCache[$name] = $result;
return $result;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/internal/Magento/Framework/Test/Unit/DataObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ public function testUnderscore($input, $expectedOutput)
public function underscoreDataProvider()
{
return [
'Test 1' => ['Stone1Color', 'stone_1_color'],
'Test 2' => ['StoneColor', 'stone_color'],
'Test 3' => ['StoneToXml', 'stone_to_xml'],
'Test 4' => ['1StoneColor', '1_stone_color'],
'Test 5' => ['getCcLast4', 'get_cc_last_4'],
'Test 6' => ['99Bottles', '99_bottles'],
'Test 7' => ['XApiLogin', 'x_api_login']
'Test 1' => ['GetStone1Color', 'stone_1_color'],
'Test 2' => ['SetStoneColor', 'stone_color'],
'Test 3' => ['GetStoneToXml', 'stone_to_xml'],
'Test 4' => ['Set1StoneColor', '1_stone_color'],
'Test 5' => ['GetgetCcLast4', 'get_cc_last_4'],
'Test 6' => ['Set99Bottles', '99_bottles'],
'Test 7' => ['GetXApiLogin', 'x_api_login']
];
}
}