Skip to content

Commit

Permalink
Support PropertyBag in CRM_Utils_Array
Browse files Browse the repository at this point in the history
We now use the PropertyBag in payment processors - but as @mattwire discovered the CRM_Utils_Array::value
function is commonly used to access values now potentially 'in the bag' and the 'is_array'
filtering here means it is not being returned
  • Loading branch information
eileenmcnaughton committed Mar 6, 2020
1 parent 40cbd64 commit 945e87e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CRM/Utils/Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CRM_Utils_Array {
*
* @param string $key
* Key value to look up in the array.
* @param array $list
* @param array|ArrayAccess $list
* Array from which to look up a value.
* @param mixed $default
* (optional) Value to return $list[$key] does not exist.
Expand All @@ -38,6 +38,10 @@ public static function value($key, $list, $default = NULL) {
if (is_array($list)) {
return array_key_exists($key, $list) ? $list[$key] : $default;
}
if ($list instanceof ArrayAccess) {
return $list[$key];
}
CRM_Core_Error::deprecatedFunctionWarning('You have passed an invalid parameter for the "list"');
return $default;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/phpunit/Civi/Payment/PropertyBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ public function testRequire() {
}
}

/**
* Test retrieves using CRM_Utils_Array::value still work.
*/
public function testUtilsArray() {
$propertyBag = new PropertyBag();
$propertyBag->setContactID(123);
$this->assertEquals(123, \CRM_Utils_Array::value('contact_id', $propertyBag));
}

/**
*
* Data provider for testOtherParams
Expand Down

0 comments on commit 945e87e

Please sign in to comment.